Пример #1
0
        public void AddApartmentPhoto(Apartment apartment, ApartmentPhoto photo)
        {
            Apartment Apartment = context
                .Apartments
                .Include(m => m.ApartmentPhotos)
                .Include(m => m.DefaultPhoto)
                .Where(m => m.ApartmentId == apartment.ApartmentId)
                .FirstOrDefault();
            Apartment.ApartmentPhotos.Add(photo);

            context.SaveChanges();
            if (Apartment.DefaultPhoto == null)
            {
                SetApartmentDefaultPhoto(Apartment, photo);
            }
        }
Пример #2
0
        public void AddOption(Apartment aparment, ApartmentOption option)
        {
            ApartmentOption Option = context.ApartmentOptions.Find(option.ApartmentOptionId);
            Apartment Apartment = context.Apartments.Include(m => m.ApartmentOptions).Where(m => m.ApartmentId == aparment.ApartmentId).FirstOrDefault();
            if ((Apartment != null) && (Option != null) && (!Apartment.ApartmentOptions.Contains(Option)))
            {

                Apartment.ApartmentOptions.Add(Option);
                context.SaveChanges();
            }
        }
Пример #3
0
 public void AddApartment(Apartment apartment)
 {
     context.Apartments.Add(apartment);
     context.SaveChanges();
 }
Пример #4
0
 public void UpdateCoords(Apartment apartment, ApartmentCoords coords)
 {
     Apartment Apartment = context
         .Apartments
         .Where(m => m.ApartmentId == apartment.ApartmentId).FirstOrDefault();
     if (Apartment != null)
     {
         Apartment.Latitude = coords.Latitude;
         Apartment.Longitude = coords.Longitude;
         context.SaveChanges();
     }
 }
Пример #5
0
 public void UpdateApartment(Apartment apartment)
 {
     context.Apartments.AddOrUpdate(e => e.ApartmentId, apartment);
     context.SaveChanges();
 }
Пример #6
0
 public void SetApartmentDefaultPhoto(Apartment apartment, ApartmentPhoto photo)
 {
     Apartment Apartment = context
         .Apartments
         .Include(m => m.ApartmentPhotos)
         .Where(m => m.ApartmentId == apartment.ApartmentId)
         .FirstOrDefault();
     Apartment.DefaultPhoto = photo;
     context.SaveChanges();
 }
Пример #7
0
 public List<ApartmentPhoto> GetApartmentPhotos(Apartment apartment)
 {
     List<ApartmentPhoto> result = context
         .Apartments
         .Where(m => m.ApartmentId == apartment.ApartmentId)
         .SelectMany(m => m.ApartmentPhotos).ToList();
     return result;
 }
Пример #8
0
 public void ClearApartmentOptions(Apartment apartment)
 {
     Apartment clearApartment = context.Apartments.Include(m => m.ApartmentOptions).Where(m => m.ApartmentId == apartment.ApartmentId).FirstOrDefault();
     List<ApartmentOption> AllOptions = clearApartment.ApartmentOptions.ToList();
     foreach (ApartmentOption option in AllOptions)
     {
         RemoveOption(clearApartment, option);
     }
     context.SaveChanges();
 }