12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using UnivateProperties_API.Context;
- using UnivateProperties_API.Model.Users;
-
- namespace UnivateProperties_API.Repository.Users
- {
- public class AgencyRepository : IRepository<Agency>
- {
- private readonly DataContext _dbContext;
-
- public AgencyRepository(DataContext dbContext)
- {
- _dbContext = dbContext;
- }
-
- public List<Agency> Get(Func<Agency, bool> where)
- {
- return _dbContext.Agencies.Where(where).ToList();
- }
-
- public List<Agency> GetAll()
- {
- return _dbContext.Agencies.ToList();
- }
-
- public Agency GetDetailed(Func<Agency, bool> first)
- {
- var item = _dbContext.Agencies.FirstOrDefault(first);
- //AgencyRepository account = new AgencyRepository(_dbContext);
- //item = GetDetailedObject(item, account);
- return item;
- }
-
- private Agency GetDetailedObject(Agency item, AgencyRepository repo)
- {
- item = repo.GetDetailed(x => x.Id == item.Id);
- return item;
- }
-
- public void Insert(Agency item)
- {
- _dbContext.Add(item);
- Save();
- }
-
- public void Insert(IEnumerable<Agency> item)
- {
- _dbContext.Add(item);
- Save();
- }
-
- public void Remove(Agency item)
- {
- var i = _dbContext.Agencies.Find(item);
- _dbContext.Agencies.Remove(i);
- Save();
- }
-
- public void Remove(IEnumerable<Agency> items)
- {
- foreach (var item in items)
- {
- Agency i = _dbContext.Agencies.Find(item);
- _dbContext.Agencies.Remove(i);
- }
- Save();
- }
-
- public void RemoveAtId(int item)
- {
- var i = _dbContext.Agencies.Find(item);
- _dbContext.Agencies.Remove(i);
- Save();
- }
-
- public void Update(Agency item)
- {
- _dbContext.Entry(item).State = EntityState.Modified;
- Save();
- }
-
- public void Save()
- {
- _dbContext.SaveChanges();
- }
-
- public List<Agency> GetDetailedAll()
- {
- //TODO: GetDetailed Agency
- throw new NotImplementedException();
- }
- }
- }
|