using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using _0_Framework.InfraStructure; using AccountManagement.Application.Contracts.Account; using AccountManagement.Application.Contracts.CameraAccount; using AccountManagement.Domain.CameraAccountAgg; using Microsoft.EntityFrameworkCore; namespace AccountMangement.Infrastructure.EFCore.Repository; public class CameraAccountRepository : RepositoryBase, ICameraAccountRepository { private readonly AccountContext _context; public CameraAccountRepository(AccountContext context) : base(context) { _context = context; } public CameraAccount GetBy(string username) { return _context.CameraAccounts.FirstOrDefault(x => x.Username == username); } public CameraAccount GetById(long id) { return _context.CameraAccounts.FirstOrDefault(x => x.id == id); } public EditCameraAccount GetDetails(long id) { return _context.CameraAccounts.Select(x => new EditCameraAccount() { Id = x.id, Username = x.Username, Mobile = x.Mobile, WorkshopId = x.WorkshopId, WorkshopName = x.WorkshopName, AccountId = x.AccountId, IsActiveString = x.IsActiveSting, Password = x.Password }).FirstOrDefault(x => x.Id == id); } #region Pooya public List GetAllByAccountId(long accountId) { return _context.CameraAccounts.Where(x => x.AccountId == accountId) .Select(x => new CameraAccountViewModel() { AccountId = x.AccountId, Id = x.id, IsActiveString = x.IsActiveSting, Username = x.Username, Mobile = x.Mobile, WorkshopId = x.WorkshopId }).ToList(); } public List GetAllByWorkshopId(long workshopId) { return _context.CameraAccounts.Where(x => x.WorkshopId == workshopId) .Select(x => new CameraAccountViewModel() { AccountId = x.AccountId, Id = x.id, IsActiveString = x.IsActiveSting, Username = x.Username, Mobile = x.Mobile, WorkshopId = x.WorkshopId, WorkshopName = x.WorkshopName }).ToList(); } #endregion #region Safa public EditCameraAccount GetDetailsByWorkshop(long workshopId) { var entity = _context.CameraAccounts.FirstOrDefault(x => x.WorkshopId == workshopId); if (entity == null) return new(); return new EditCameraAccount() { Id = entity.id, Username = entity.Username, Mobile = entity.Mobile, WorkshopId = entity.WorkshopId, WorkshopName = entity.WorkshopName, AccountId = entity.AccountId, IsActiveString = entity.IsActiveSting, Password = entity.Password }; } #endregion }