API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AgentRepository.cs 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Microsoft.EntityFrameworkCore;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnivateProperties_API.Context;
  6. using UnivateProperties_API.Model.Users;
  7. namespace UnivateProperties_API.Repository.Users
  8. {
  9. public class AgentRepository : IRepository<Agent>
  10. {
  11. private readonly DataContext _dbContext;
  12. public AgentRepository(DataContext dbContext)
  13. {
  14. _dbContext = dbContext;
  15. }
  16. public List<Agent> Get(Func<Agent, bool> where)
  17. {
  18. return _dbContext.Agents.Where(where).ToList();
  19. }
  20. public List<Agent> GetAll()
  21. {
  22. return _dbContext.Agents.ToList();
  23. }
  24. public Agent GetDetailed(Func<Agent, bool> first)
  25. {
  26. var item = _dbContext.Agents.FirstOrDefault(first);
  27. AgentRepository account = new AgentRepository(_dbContext);
  28. item = GetDetailedObject(item, account);
  29. return item;
  30. }
  31. private Agent GetDetailedObject(Agent item, AgentRepository repo)
  32. {
  33. item = repo.GetDetailed(x => x.Id == item.Id);
  34. return item;
  35. }
  36. public void Insert(Agent item)
  37. {
  38. _dbContext.Add(item);
  39. Save();
  40. }
  41. public void Insert(IEnumerable<Agent> item)
  42. {
  43. _dbContext.Add(item);
  44. Save();
  45. }
  46. public void Remove(Agent item)
  47. {
  48. var i = _dbContext.Agents.Find(item);
  49. _dbContext.Agents.Remove(i);
  50. Save();
  51. }
  52. public void Remove(IEnumerable<Agent> items)
  53. {
  54. foreach (var item in items)
  55. {
  56. Agent i = _dbContext.Agents.Find(item);
  57. _dbContext.Agents.Remove(i);
  58. }
  59. Save();
  60. }
  61. public void RemoveAtId(int item)
  62. {
  63. var i = _dbContext.Agents.Find(item);
  64. _dbContext.Agents.Remove(i);
  65. Save();
  66. }
  67. public void Update(Agent item)
  68. {
  69. _dbContext.Entry(item).State = EntityState.Modified;
  70. Save();
  71. }
  72. public void Save()
  73. {
  74. _dbContext.SaveChanges();
  75. }
  76. public List<Agent> GetDetailedAll()
  77. {
  78. // TODO: GetDetailed
  79. throw new NotImplementedException();
  80. }
  81. }
  82. }