101 lines
2.9 KiB
C#
101 lines
2.9 KiB
C#
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using _0_Framework.InfraStructure;
|
||
using AccountManagement.Application.Contracts.Account;
|
||
using AccountManagement.Application.Contracts.Position;
|
||
using AccountManagement.Domain.AccountAgg;
|
||
using AccountMangement.Infrastructure.EFCore;
|
||
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.EntityFrameworkCore;
|
||
using TaskManager.Domain.PositionAgg;
|
||
|
||
namespace TaskManager.Infrastructure.EFCore.Repository;
|
||
|
||
public class PositionRepository : RepositoryBase<long, Position>, IPositionRepository
|
||
{
|
||
private readonly AccountContext _accountContext;
|
||
private readonly IHttpContextAccessor _contextAccessor;
|
||
|
||
public PositionRepository(AccountContext accountContext, IHttpContextAccessor contextAccessor) : base(accountContext)
|
||
{
|
||
_accountContext = accountContext;
|
||
_contextAccessor = contextAccessor;
|
||
}
|
||
|
||
public List<PositionViewModel> GetPositions()
|
||
{
|
||
// این متد تمام سمت ها را بدست می آورد
|
||
return _accountContext.Positions.Select(x => new PositionViewModel()
|
||
{
|
||
Value = x.PositionValue,
|
||
Id = x.id,
|
||
Name = x.PositionName,
|
||
CountUsers = _accountContext.Accounts.Count(a => a.PositionId==x.id)
|
||
|
||
|
||
|
||
|
||
}).OrderBy(x=>x.Value).ToList();
|
||
|
||
}
|
||
|
||
public List<PositionViewModel> GetLowerPosition()
|
||
{
|
||
var posValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value);
|
||
return _accountContext.Positions.Where(x=>x.PositionValue>posValue).Select(x => new PositionViewModel()
|
||
{
|
||
Value = x.PositionValue,
|
||
Id = x.id,
|
||
Name = x.PositionName
|
||
|
||
|
||
|
||
|
||
}).OrderBy(x => x.Value).ToList();
|
||
}
|
||
|
||
public List<int> GetUnUsedPositionValues()
|
||
{
|
||
List<int> values= new List<int>() {1,2,3,4,5};
|
||
var usedPositions= _accountContext.Positions.Select(x => x.PositionValue).ToList();
|
||
return values.Where(x => !usedPositions.Contains(x)).ToList();
|
||
}
|
||
|
||
//لیست کسانی که سمتی برایشان ثبت نشده است
|
||
public List<AccountViewModel> GetNoPositionAccounts()
|
||
{
|
||
|
||
return _accountContext.Accounts.Where(x => x.PositionId == null).Select(x => new AccountViewModel()
|
||
{
|
||
Id = x.id,
|
||
Fullname = x.Fullname
|
||
}).ToList();
|
||
}
|
||
|
||
public List<Account> GetAccountsByIds(List<long> ids)
|
||
{
|
||
var res =_accountContext.Accounts.Include(x=>x.Position).Where(x => x.PositionId != null);
|
||
return res.Where(x => ids.Contains((long)x.PositionId)).ToList();
|
||
}
|
||
|
||
public void Remove(long id)
|
||
{
|
||
var position =Get(id);
|
||
Remove(position);
|
||
}
|
||
|
||
public int GetLastPositionValue()
|
||
{
|
||
if (!_accountContext.Positions.Any())
|
||
{
|
||
return 1;
|
||
}
|
||
else
|
||
{
|
||
return _accountContext.Positions.Max(x => x.PositionValue);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
} |