using System.Collections.Generic; using System.Linq; using _0_Framework.Application; using _0_Framework.InfraStructure; using Company.Domain.RollCallServiceAgg; using CompanyManagment.App.Contracts.RollCallService; using Microsoft.EntityFrameworkCore; namespace CompanyManagment.EFCore.Repository; public class RollCallServiceRepository : RepositoryBase, IRollCallServiceRepository { private readonly CompanyContext _context; public RollCallServiceRepository(CompanyContext context) : base(context) { _context = context; } public EditRollCallService GetDetails(long id) { return _context.RollCallServices.Select(x => new EditRollCallService() { Id = x.id, ServiceType = x.ServiceType, StartServiceStr = x.StartService.ToFarsi(), StartService = x.StartService, EndServiceStr = x.EndService.ToFarsi(), EndService = x.EndService, WorkshopId = x.WorkshopId, AccountId = x.AccountId, IsActiveString = x.IsActiveString, MaxPersonValid = x.MaxPersonValid, Amount = x.Amount, AmountFa = x.Amount.ToMoney(), Duration = x.Duration, }).FirstOrDefault(x => x.Id == id); } public RollCallServiceViewModel GetActiveServiceByWorkshopId(long workshopId) { return _context.RollCallServices.AsSplitQuery().Select(x => new RollCallServiceViewModel() { Id = x.id, ServiceType = x.ServiceType, StartServiceStr = x.StartService.ToFarsi(), StartService = x.StartService, EndServiceStr = x.EndService.ToFarsi(), EndService = x.EndService, WorkshopId = x.WorkshopId, AccountId = x.AccountId, IsActiveString = x.IsActiveString, MaxPersonValid = x.MaxPersonValid, Amount = x.Amount, AmountFa = x.Amount.ToMoney(), Duration = x.Duration, HasCustomizeCheckoutService = x.HasCustomizeCheckoutService, }).FirstOrDefault(x => x.WorkshopId == workshopId && x.IsActiveString == "true"); } public List GetAllServiceByWorkshopId(long workshopId) { return _context.RollCallServices.Select(x => new RollCallServiceViewModel() { Id = x.id, ServiceType = x.ServiceType, StartServiceStr = x.StartService.ToFarsi(), StartService = x.StartService, EndServiceStr = x.EndService.ToFarsi(), EndService = x.EndService, WorkshopId = x.WorkshopId, AccountId = x.AccountId, IsActiveString = x.IsActiveString, MaxPersonValid = x.MaxPersonValid, Amount = x.Amount, AmountFa = x.Amount.ToMoney(), Duration = x.Duration, HasCustomizeCheckoutService = x.HasCustomizeCheckoutService, }).Where(x => x.WorkshopId == workshopId).ToList(); } public List GetActiveServiceByAccountId(long accountId) { return _context.RollCallServices.Select(x => new RollCallServiceViewModel() { Id = x.id, ServiceType = x.ServiceType, StartServiceStr = x.StartService.ToFarsi(), StartService = x.StartService, EndServiceStr = x.EndService.ToFarsi(), EndService = x.EndService, WorkshopId = x.WorkshopId, AccountId = x.AccountId, IsActiveString = x.IsActiveString, MaxPersonValid = x.MaxPersonValid, Amount = x.Amount, AmountFa = x.Amount.ToMoney(), Duration = x.Duration, HasCustomizeCheckoutService = x.HasCustomizeCheckoutService, }).Where(x => x.AccountId == accountId && x.IsActiveString == "true").ToList(); } public List GetAllServiceByAccountId(long accountId) { return _context.RollCallServices.Select(x => new RollCallServiceViewModel() { Id = x.id, ServiceType = x.ServiceType, StartServiceStr = x.StartService.ToFarsi(), StartService = x.StartService, EndServiceStr = x.EndService.ToFarsi(), EndService = x.EndService, WorkshopId = x.WorkshopId, AccountId = x.AccountId, IsActiveString = x.IsActiveString, MaxPersonValid = x.MaxPersonValid, Amount = x.Amount, AmountFa = x.Amount.ToMoney(), Duration = x.Duration, HasCustomizeCheckoutService = x.HasCustomizeCheckoutService, }).Where(x => x.AccountId == accountId).ToList(); } public bool IsExistActiveServiceByWorkshopId(long workshopId) { return _context.RollCallServices.AsSplitQuery().Any(x => x.WorkshopId == workshopId && x.IsActiveString == "true"); } }