123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using UnivateProperties_API.Context;
- using UnivateProperties_API.Model.Properties;
-
- namespace UnivateProperties_API.Repository.Properties
- {
- public class PropertyImageRepository : IPropertyImageRepository
- {
- private readonly DataContext dBContext;
-
- public PropertyImageRepository(DataContext _dBContext)
- {
- dBContext = _dBContext;
- }
- public List<PropertyImage> Get(Func<PropertyImage, bool> where)
- {
- return dBContext.PropertyImages.Where(where).ToList();
- }
-
- public List<PropertyImage> GetAll()
- {
- return dBContext.PropertyImages.ToList();
- }
-
- public PropertyImage GetDetailed(Func<PropertyImage, bool> first)
- {
- return dBContext.PropertyImages.FirstOrDefault(first);
- }
-
- public List<PropertyImage> GetDetailedAll()
- {
- throw new NotImplementedException();
- }
-
- public List<string> GetImages(int PropertyId)
- {
- var images = (from p in dBContext.PropertyImages
- where p.PropertyId == PropertyId
- select p.Image).ToList();
-
- return images;
- }
-
- public void Insert(PropertyImage item)
- {
- dBContext.PropertyImages.Add(item);
- Save();
- }
-
- public void Insert(IEnumerable<PropertyImage> items)
- {
- foreach (var item in items)
- {
- dBContext.PropertyImages.Add(item);
- }
- Save();
- }
-
- public void Remove(PropertyImage item)
- {
- dBContext.PropertyImages.Remove(item);
- Save();
- }
-
- public void Remove(IEnumerable<PropertyImage> items)
- {
- foreach (var item in items)
- {
- dBContext.PropertyImages.Remove(item);
- }
- Save();
- }
-
- public void RemoveAtId(int item)
- {
- var image = Get(x => x.Id == item).FirstOrDefault();
- if (image != null)
- {
- dBContext.PropertyImages.Remove(image);
- Save();
- }
- }
-
- public void Save()
- {
- dBContext.SaveChanges();
- }
-
- public void Update(PropertyImage item)
- {
- dBContext.Entry(item).State = EntityState.Modified;
- Save();
- }
-
- public int NewId()
- {
- // Not sure if properties need it
- return 0;
- }
- }
- }
|