94 lines
2.6 KiB
C#
94 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework_b.Application;
|
|
using _0_Framework_b.InfraStructure;
|
|
using Company.Domain.ProceedingSession;
|
|
using CompanyManagment.App.Contracts.ProceedingSession;
|
|
using CompanyManagment.EFCore;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class ProceedingSessionRepository : RepositoryBase<long, ProceedingSession>, IProceedingSessionRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
public ProceedingSessionRepository(CompanyContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public void RemoveProceedingSessions(List<EditProceedingSession> proceedingSessions)
|
|
{
|
|
foreach (var obj in proceedingSessions)
|
|
{
|
|
var proceedingSession = Get(obj.Id);
|
|
|
|
Remove(proceedingSession);
|
|
SaveChanges();
|
|
}
|
|
}
|
|
|
|
public List<EditProceedingSession> Search(ProceedingSessionSearchModel searchModel)
|
|
{
|
|
var query = _context.ProceedingSessions.Select(x => new
|
|
{
|
|
Id = x.id,
|
|
Date = x.Date,
|
|
Time = x.Time,
|
|
Board_Id = x.Board_Id,
|
|
Status = x.Status
|
|
});
|
|
|
|
//TODO if
|
|
|
|
if (searchModel.Id != 0)
|
|
{
|
|
query = query.Where(x => x.Id == searchModel.Id);
|
|
}
|
|
|
|
if (searchModel.Board_Id != 0)
|
|
{
|
|
query = query.Where(x => x.Board_Id == searchModel.Board_Id);
|
|
}
|
|
|
|
if (searchModel.Status != 0)
|
|
{
|
|
query = query.Where(x => x.Status == searchModel.Status);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(searchModel.FromDate))
|
|
{
|
|
query = query.Where(x => x.Date >= searchModel.FromDate.ToGeorgianDateTime());
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(searchModel.ToDate))
|
|
{
|
|
query = query.Where(x => x.Date <= searchModel.ToDate.ToGeorgianDateTime());
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(searchModel.Time))
|
|
{
|
|
query = query.Where(x => x.Time == searchModel.Time);
|
|
}
|
|
|
|
if (searchModel.Year != 0 && searchModel.Month != 0)
|
|
{
|
|
var start = $"{searchModel.Year:0000}/{searchModel.Month:00}/01";
|
|
var end = start.FindeEndOfMonth();
|
|
|
|
|
|
var startGr = start.ToGeorgianDateTime();
|
|
var endGr = end.ToGeorgianDateTime();
|
|
|
|
query = query.Where(x => x.Date >= startGr && x.Date <= endGr);
|
|
}
|
|
|
|
return query.Select(x => new EditProceedingSession
|
|
{
|
|
Id = x.Id,
|
|
Date = x.Date.ToFarsi(),
|
|
Time = x.Time,
|
|
Board_Id = x.Board_Id,
|
|
Status = x.Status
|
|
}).ToList();
|
|
}
|
|
} |