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.

PropertyImageRepository.cs 2.5KB

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