Beispiel #1
0
        /// <summary>
        /// Removes the <paramref name="apartment"/> from the database.
        /// </summary>
        /// <param name="apartment">Apartment to be removed.</param>
        /// <remarks>This method does nothing if <paramref name="apartment"/> is null.</remarks>
        public static void DeleteApartment(ApartmentInfo apartment)
        {
            if (apartment is null)
            {
                return;
            }

            GuestBook.Context.Apartments.Remove(apartment);
            GuestBook.Context.SaveChanges();
        }
Beispiel #2
0
        /// <summary>
        /// Saves the <paramref name="apartment"/> to the database.
        /// </summary>
        /// <param name="apartment">Apartment to be saved.</param>
        /// <remarks>This method does nothing if <paramref name="apartment"/> is null.</remarks>
        public static void SetApartment(ApartmentInfo apartment)
        {
            if (apartment is null)
            {
                return;
            }

            GuestBook.Context.Apartments.Add(apartment);
            GuestBook.Context.SaveChanges();
        }
Beispiel #3
0
        /// <summary>
        /// Updates the parameters of an existing apartment.
        /// </summary>
        /// <param name="apartment">Apartment to update.</param>
        public static void UpdateApartment(ApartmentInfo apartment)
        {
            if (apartment is null)
            {
                return;
            }

            var updatedApartment = GetApartmentById(apartment.ApartmentId);

            updatedApartment.Number     = apartment.Number;
            updatedApartment.Price      = apartment.Price;
            updatedApartment.Capacity   = apartment.Capacity;
            updatedApartment.DoubleBeds = apartment.DoubleBeds;

            GuestBook.Context.SaveChanges();
        }