API
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AgencyRepository.cs 2.4KB

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