123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- 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;
- }
-
- public void Insert(Agency item)
- {
- item.Id = NewId();
- _dbContext.Add(item);
- Save();
- }
-
- public void Insert(IEnumerable<Agency> item)
- {
- int id = NewId();
- foreach (var i in item)
- {
- i.Id = id;
- _dbContext.Add(i);
- id += 1;
- }
- 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();
- }
-
- public int NewId()
- {
- int id = 0;
- if (_dbContext.Agencies.Count() > 0)
- {
- id = _dbContext.Agencies.Max(x => x.Id);
- }
- id += 1;
- return id;
- }
- }
- }
|