1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using UnivateProperties_API.Context;
- using UnivateProperties_API.Model.Property;
-
- 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();
- }
- }
- }
|