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.

CarouselRepository.cs 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using Microsoft.EntityFrameworkCore;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnivateProperties_API.Containers.Property;
  6. using UnivateProperties_API.Context;
  7. using UnivateProperties_API.Model.Misc;
  8. namespace UnivateProperties_API.Repository.Misc
  9. {
  10. public class CarouselRepository : IRepository<Carousel>
  11. {
  12. private readonly DataContext dBContext;
  13. public CarouselRepository(DataContext _dBContext)
  14. {
  15. dBContext = _dBContext;
  16. }
  17. public List<Carousel> Get(Func<Carousel, bool> where)
  18. {
  19. var CarouselList = dBContext.Carousel.Where(where).ToList();
  20. foreach (var item in CarouselList)
  21. {
  22. if (!string.IsNullOrEmpty(item.Image) && !item.Image.StartsWith("data:image"))
  23. item.Image = ImageFormatter.ImageToBase64(item.Image);
  24. }
  25. return CarouselList;
  26. }
  27. public List<Carousel> GetAll()
  28. {
  29. var CarouselList = dBContext.Carousel.ToList();
  30. foreach (var item in CarouselList)
  31. {
  32. if (!string.IsNullOrEmpty(item.Image) && !item.Image.StartsWith("data:image"))
  33. item.Image = ImageFormatter.ImageToBase64(item.Image);
  34. }
  35. return CarouselList;
  36. }
  37. public Carousel GetDetailed(Func<Carousel, bool> first)
  38. {
  39. return dBContext.Carousel.FirstOrDefault(first);
  40. }
  41. public List<Carousel> GetDetailedAll()
  42. {
  43. return dBContext.Carousel.ToList();
  44. }
  45. public void Insert(Carousel item)
  46. {
  47. dBContext.Carousel.Add(item);
  48. Save();
  49. }
  50. public void Insert(IEnumerable<Carousel> items)
  51. {
  52. foreach (var item in items)
  53. {
  54. dBContext.Carousel.Add(item);
  55. Save();
  56. }
  57. }
  58. public void Remove(Carousel item)
  59. {
  60. dBContext.Carousel.Remove(item);
  61. Save();
  62. }
  63. public void Remove(IEnumerable<Carousel> items)
  64. {
  65. foreach (var item in items)
  66. {
  67. dBContext.Carousel.Remove(item);
  68. Save();
  69. }
  70. }
  71. public void RemoveAtId(int item)
  72. {
  73. var Carousel = Get(x => x.Id == item).FirstOrDefault();
  74. if (Carousel != null)
  75. {
  76. dBContext.Carousel.Remove(Carousel);
  77. Save();
  78. }
  79. }
  80. public void Save()
  81. {
  82. dBContext.SaveChanges();
  83. }
  84. public void Update(Carousel item)
  85. {
  86. dBContext.Entry(item).State = EntityState.Modified;
  87. Save();
  88. }
  89. public int NewId()
  90. {
  91. // Not sure if properties need it
  92. return 0;
  93. }
  94. }
  95. }