Exemplo n.º 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));
        }
Exemplo n.º 2
0
        public void UpdateAdmin(Admin admin)
        {
            Admin existingAdmin = GetAdminById(admin.ID);

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

            db.SaveChanges();
        }
Exemplo n.º 3
0
 public void SaveNewRoom(Room room)
 {
     try
     {
         db.Rooms.Add(room);
         db.SaveChanges();
         _logger.Trace(LoggerHelper.ExecutedFunctionMessage(LoggerHelper.VOID_TYPE, room));
     }
     catch (Exception exn)
     {
         _logger.Trace(LoggerHelper.ExecutedFunctionMessage(exn, room));
         throw exn;
     }
 }
Exemplo n.º 4
0
 public void SaveNewLocation(Location location)
 {
     try
     {
         db.Locations.Add(location);
         db.SaveChanges();
         _logger.Trace(LoggerHelper.ExecutedFunctionMessage(LoggerHelper.VOID_TYPE, location));
     }
     catch (Exception exn)
     {
         _logger.Trace(LoggerHelper.ExecutedFunctionMessage(exn, location));
         throw exn;
     }
 }
Exemplo n.º 5
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));
            }
        }
Exemplo n.º 6
0
 public void SaveNewLocation(Location location)
 {
     db.Locations.Add(location);
     db.SaveChanges();
 }
Exemplo n.º 7
0
 public void SaveNewRoom(Room room)
 {
     db.Rooms.Add(room);
     db.SaveChanges();
 }