using Marco.Pms.DataAccess.Data; using Marco.Pms.DataAccess.Repository; using Marco.Pms.DataAccess.Repository.IRepository; using Marco.Pms.Model.Entitlements; using Marco.Pms.Model.Projects; using Microsoft.EntityFrameworkCore; using System.Linq.Expressions; namespace BulkyBook.DataAccess.Repository { public class FeaturesRepository : Repository, IFeatureRepository { private readonly ApplicationDbContext _context; internal DbSet dbSet; public FeaturesRepository(ApplicationDbContext db): base(db) { _context = db; this.dbSet = _context.Set(); } public void Update(Feature project) { _context.Features.Update(project); } public Task> GetAllAsync(Expression>? filter = null, string? includeProperties = null) { IQueryable query = _context.Features; 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(); // return await _context.Projects.ToListAsync(); ; } public Task> GetAsync(Expression>? filter = null, string? includeProperties = null) { IQueryable query = _context.Features; if (filter != null) { query.Where(filter); //var projects1= query2.Where(filter).ToListAsync(); } if (!string.IsNullOrEmpty(includeProperties)) { foreach (var includeProp in includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProp); } } return query.ToListAsync(); // return await _context.Projects.ToListAsync(); ; } public async Task CreateAsync(Feature projectModel) { try { await _context.Features.AddAsync(projectModel); await _context.SaveChangesAsync(); return projectModel; } catch (Exception ex) { throw ex; } } //public async Task UpdateAsync(int id, UpdateFeatureDto projectDto) //{ // var projectModel = await _context.Features.FirstOrDefaultAsync(item => item.Id == id); // if (projectModel == null) // { // return null; // } // projectModel.ContactPerson = projectDto.ContactPerson; // projectModel.ProjectAddress = projectDto.ProjectAddress; // projectModel.Name = projectDto.Name; // projectModel.EndDate = projectDto.EndDate; // projectModel.StartDate = projectDto.StartDate; // //projectModel.TenantId = projectDto.TenantId; // try // { // await _context.SaveChangesAsync(); // }catch(Exception ex ) // { // throw ex; // } // return projectModel; //} } }