using Marco.Pms.DataAccess.Data; using Marco.Pms.DataAccess.Repository.IRepository; using Marco.Pms.Model.Dtos.Project; using Marco.Pms.Model.Projects; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace Marco.Pms.DataAccess.Repository { public class ProjectAllocationRepository : Repository, IProjectAllocationRepository { private readonly ApplicationDbContext _context; internal DbSet dbSet; public ProjectAllocationRepository(ApplicationDbContext db) : base(db) { _context = db; this.dbSet = _context.Set(); } public void Update(ProjectAllocation project) { _context.ProjectAllocations.Update(project); } public async Task CreateAsync(ProjectAllocation project) { await _context.ProjectAllocations.AddAsync(project); await _context.SaveChangesAsync(); return project; } public Task> GetAllAsync(Expression>? filter = null, string? includeProperties = null) { throw new NotImplementedException(); } public Task> GetAsync(Expression>? filter = null, string? includeProperties = null) { IQueryable query = _context.ProjectAllocations; if (filter != null) { query.Where(filter); } if (!string.IsNullOrEmpty(includeProperties)) { foreach (var includeProp in includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProp); } } return query.ToListAsync(); } public async Task UpdateAsync(int id, ProjectAllocation project) { var allocation = await _context.ProjectAllocations.FirstOrDefaultAsync(item => item.Id == id); if (allocation == null) { return null; } allocation.ProjectId = project.ProjectId; allocation.EmployeeId = project.EmployeeId; allocation.AllocationDate = project.AllocationDate; allocation.ReAllocationDate = project.ReAllocationDate; allocation.TenantId = project.TenantId; _context.ProjectAllocations.Update(allocation); await _context.SaveChangesAsync(); return allocation; } } }