API
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CityRepository.cs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.Region;
  7. namespace UnivateProperties_API.Repository.Region
  8. {
  9. public class CityRepository : ICityRepository
  10. {
  11. private readonly DataContext dBContext;
  12. public CityRepository(DataContext _dBContext)
  13. {
  14. dBContext = _dBContext;
  15. }
  16. public List<City> Get(Func<City, bool> where)
  17. {
  18. return dBContext.Cities.Where(where).ToList();
  19. }
  20. public List<City> GetAll()
  21. {
  22. return dBContext.Cities.ToList();
  23. }
  24. public List<City> GetBy(string province)
  25. {
  26. var provObj = dBContext.Provinces.Where(p => p.Description == province).First();
  27. if (provObj != null)
  28. return dBContext.Cities.Where(c => c.ProvinceId == provObj.Id).OrderBy(c => c.Description).ToList();
  29. else
  30. return null;
  31. }
  32. public City GetDetailed(Func<City, bool> first)
  33. {
  34. throw new NotImplementedException();
  35. }
  36. public List<City> GetDetailedAll()
  37. {
  38. throw new NotImplementedException();
  39. }
  40. public void Insert(City item)
  41. {
  42. dBContext.Cities.Add(item);
  43. Save();
  44. }
  45. public void Insert(IEnumerable<City> items)
  46. {
  47. foreach (var item in items)
  48. {
  49. dBContext.Cities.Add(item);
  50. Save();
  51. }
  52. }
  53. public void Remove(City item)
  54. {
  55. dBContext.Cities.Remove(item);
  56. Save();
  57. }
  58. public void Remove(IEnumerable<City> items)
  59. {
  60. foreach (var item in items)
  61. {
  62. dBContext.Cities.Remove(item);
  63. }
  64. Save();
  65. }
  66. public void RemoveAtId(int item)
  67. {
  68. var city = Get(x => x.Id == item).FirstOrDefault();
  69. if (city != null)
  70. {
  71. dBContext.Cities.Remove(city);
  72. Save();
  73. }
  74. }
  75. public void Save()
  76. {
  77. dBContext.SaveChanges();
  78. }
  79. public void Update(City item)
  80. {
  81. dBContext.Entry(item).State = EntityState.Modified;
  82. Save();
  83. }
  84. }
  85. }