예제 #1
0
 public void AddReservation(Reservation reservation)
 {
     reservation.ReservedApartment = Apartments.Where(a => a.IsDeleted == false && a.Id == reservation.ReservedApartment.Id).FirstOrDefault();
     reservation.Guest             = Users.Where(u => u.IsDeleted == false && u.Username == reservation.Guest.Username).FirstOrDefault() as Guest;
     Reservations.Add(reservation);
     SaveChanges();
 }
예제 #2
0
        public void RemoveUser(string username)
        {
            var us = Users.SingleOrDefault(i => i.Username == username);

            var apartments = Apartments.Where(i => i.Host.Username == us.Username && i.IsDeleted == false);

            foreach (var item in apartments)
            {
                RemoveApartment(item.Id);
            }

            var comments = Comments.Where(c => c.IsDeleted == false && c.GuestThaWroteComment.Username == username);

            foreach (var item in comments)
            {
                RemoveComment(item);
            }

            var reservations = Reservations.Where(r => r.IsDeleted == false && r.Guest.Username == username);

            foreach (var item in reservations)
            {
                RemoveReservation(item);
            }

            us.IsDeleted = true;
            SaveChanges();
        }
        private static void SetRelationalProperties()
        {
            foreach (var owner in Owners.Where(o => o.Id.HasValue))
            {
                owner.Apartments = Apartments.Where(a =>
                {
                    if (a.OwnerId != owner.Id.Value)
                    {
                        return(false);
                    }

                    a.Owner   = owner;
                    a.OwnerId = owner.Id.Value;
                    return(true);
                }).ToArray();
            }

            foreach (var building in Buildings.Where(b => b.Id.HasValue))
            {
                building.Apartments = Apartments.Where(a =>
                {
                    if (a.BuildingId != building.Id.Value)
                    {
                        return(false);
                    }

                    a.Building   = building;
                    a.BuildingId = building.Id.Value;
                    return(true);
                }).ToArray();
            }
        }
예제 #4
0
 public List <Apartment> GetMyApartments(long profileId)
 {
     return(Apartments.Where(m => m.ProfileId == profileId)
            .Include(m => m.Type)
            .Include(m => m.ApartmentOptions)
            .Include(m => m.ApartmentPhotos.Select(k => k.Links))
            .ToList());
 }
예제 #5
0
        public void AddComment(Comment comment, int apartmentId)
        {
            var apartment = Apartments.Where(a => a.IsDeleted == false && a.Id == apartmentId).FirstOrDefault();
            var guest     = Users.Where(u => u.IsDeleted == false && u.Username == comment.GuestThaWroteComment.Username).FirstOrDefault() as Guest;

            comment.GuestThaWroteComment = guest;
            comment.Apartment            = apartment;
            Comments.Add(comment);
            SaveChanges();
        }
예제 #6
0
        public void RemoveUser(User user)
        {
            var us = Users.SingleOrDefault(i => i.Username == user.Username);

            var apartments = Apartments.Where(i => i.Host.Username == us.Username && i.IsDeleted == false);

            foreach (var item in apartments)
            {
                item.IsDeleted = true;
            }

            us.IsDeleted = true;
            SaveChanges();
        }
예제 #7
0
        public Apartment AddApartment(Apartment apartment)
        {
            var user = Users.Where(u => u.IsDeleted == false && u.Username == apartment.Host.Username).FirstOrDefault();

            apartment.Host = user as Host;

            ICollection <Amenities> amenities = new List <Amenities>();

            foreach (var item in apartment.Amenities)
            {
                amenities.Add(Amenities.SingleOrDefault(a => item.Id == a.Id));
            }
            apartment.Amenities = amenities;

            Apartments.Add(apartment);
            SaveChanges();
            var apartment1 = Apartments.Where(a => a.Id == apartment.Id).FirstOrDefault();

            apartment1.PicturesLocation += $"{apartment.Id}";
            SaveChanges();
            return(apartment1);
        }