Пример #1
0
        public Booking UpdateExistingBooking(Booking existingBooking, Booking editBooking)
        {
            try
            {
                if (!HasBookingChanged(editBooking, existingBooking))
                {
                    throw new NoBookingChangesFoundException();
                }

                editBooking.ID    = existingBooking.ID;
                editBooking.Owner = existingBooking.Owner;
                editBooking.PID   = existingBooking.PID;
                editBooking.Room  = db.Rooms.SingleOrDefault(x => x.ID == editBooking.RoomID);

                db.Entry(existingBooking).CurrentValues.SetValues(editBooking);
                db.ExternalAttendees.RemoveRange(db.ExternalAttendees.Where(x => x.BookingID == editBooking.ID));

                if (editBooking.ExternalAttendees != null)
                {
                    editBooking.ExternalAttendees.ToList().ForEach(x => x.BookingID = editBooking.ID);
                    db.ExternalAttendees.AddRange(editBooking.ExternalAttendees);
                }

                db.SaveChanges(editBooking, false);
            }
            catch (Exception e)
            {
                _logger.Error($"Unable to edit existing booking: ID {existingBooking.ID}. An error occured: {e.Message}");
                return(null);
            }
            return(GetById(editBooking.ID));
        }
Пример #2
0
        public void EditRoom(Room room)
        {
            Room originalRoom = GetRoomById(room.ID);

            db.Entry(originalRoom).CurrentValues.SetValues(room);
            db.SaveChanges();
        }
Пример #3
0
        public void UpdateAdmin(Admin admin)
        {
            Admin existingAdmin = GetAdminById(admin.ID);

            db.Entry(existingAdmin).CurrentValues.SetValues(admin);

            db.SaveChanges();
        }
Пример #4
0
        public void UpdateLocation(Location location)
        {
            Location originalLocation = GetLocationById(location.ID);

            db.Entry(originalLocation).CurrentValues.SetValues(location);

            //TODO: Need to tidy this up, we shouldn't have to delete all locations and re-add them each time. Not sure if there is a virtual update method
            IEnumerable <LocationCredentials> credentials = db.LocationCredentials.Where(x => x.LocationID == location.ID).ToList();

            db.LocationCredentials.RemoveRange(credentials);
            location.LocationCredentials.ToList().ForEach(x => x.LocationID = location.ID);
            db.LocationCredentials.AddRange(location.LocationCredentials);

            db.SaveChanges();
        }
Пример #5
0
        public void EditRoom(Room room)
        {
            try
            {
                Room originalRoom = GetRoomById(room.ID);

                db.Entry(originalRoom).CurrentValues.SetValues(room);
                db.SaveChanges();

                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(LoggerHelper.VOID_TYPE, room));
            }
            catch (Exception exn)
            {
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(exn, room));
                throw exn;
            }
        }
Пример #6
0
        public void UpdateAdmin(Admin admin)
        {
            try
            {
                Admin existingAdmin = GetAdminById(admin.ID);
                db.Entry(existingAdmin).CurrentValues.SetValues(admin);

                db.SaveChanges();
            }
            catch (Exception exn)
            {
                _logger.ErrorException("Unable to update admin: " + admin.PID, exn);
                throw exn;
            }
            finally
            {
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(null, admin));
            }
        }