120 lines
3.5 KiB
C#

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<Feature>, IFeatureRepository
{
private readonly ApplicationDbContext _context;
internal DbSet<Feature> dbSet;
public FeaturesRepository(ApplicationDbContext db): base(db)
{
_context = db;
this.dbSet = _context.Set<Feature>();
}
public void Update(Feature project)
{
_context.Features.Update(project);
}
public Task<List<Feature>> GetAllAsync(Expression<Func<Feature, bool>>? filter = null, string? includeProperties = null)
{
IQueryable<Feature> 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<List<Feature>> GetAsync(Expression<Func<Feature, bool>>? filter = null, string? includeProperties = null)
{
IQueryable<Feature> 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<Feature> CreateAsync(Feature projectModel)
{
try
{
await _context.Features.AddAsync(projectModel);
await _context.SaveChangesAsync();
return projectModel;
}
catch (Exception ex) { throw ex; }
}
//public async Task<Feature> 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;
//}
}
}