private IActionResult _ChangeReservation(bool?isactive, Reservation reservation, DateTime start, DateTime end, Room room, string Description, ReservationChange reservationchange) { if (isactive.HasValue) { reservation.Active = isactive.Value; } reservation.StartDate = start; reservation.EndDate = end; if (room != null) { reservation.Room = room; } if (Description != null) { reservation.Description = Description; } _context.Add(reservation); _context.ReservationChanges.Add(reservationchange); _context.SaveChanges(); return(Content("Succesfully changed reservation")); }
private IActionResult _ForceChangeReservation(bool?isactive, Reservation reservation, DateTime start, DateTime end, Room room, string Description, ReservationChange reservationchange, User actor, IEnumerable <Reservation> Intersections) { if (!Intersections.All(x => x.IsMutable)) { throw new Exception("Cannot forcibly override immutable reservation"); } foreach (var intersection in Intersections) { ShortenOtherReservation(start, end, intersection, actor); } return(_ChangeReservation(isactive, reservation, start, end, room, Description, reservationchange)); }
/// <summary> /// Change a reservation only if no conflict occurs. /// </summary> /// <param name="emailservice"></param> /// <param name="Actor"></param> /// <param name="isactive"></param> /// <param name="reservation"></param> /// <param name="start"></param> /// <param name="end"></param> /// <param name="room"></param> /// <param name="Description"></param> /// <param name="reservationchange"></param> /// <returns></returns> private IActionResult _ChangeReservation(IEmailService emailservice, User Actor, bool?isactive, Reservation reservation, DateTime start, DateTime end, Room room, string Description, ReservationChange reservationchange) { if (isactive.HasValue) { reservation.Active = isactive.Value; } reservation.StartDate = start; reservation.EndDate = end; if (room != null) { reservation.Room = room; } if (Description != null) { reservation.Description = Description; } _context.ReservationChanges.Add(reservationchange); _context.SaveChanges(); foreach (var user in _context.Reservations.Where(x => x.Id == reservation.Id).Include(x => x.Participants).First().Participants.Where(x => x.User.EmailNotification)) { emailservice.SendReservationChangedMessage(user.User, Actor, reservation, reservationchange, _context); } return(Ok("Succesfully changed reservation")); }
/// <summary> /// Send a notification that reservation had changed. /// </summary> /// <param name="receiver"></param> /// <param name="sender"></param> /// <param name="reservation"></param> /// <param name="change"></param> /// <param name="_context"></param> public void SendReservationChangedMessage(User receiver, User sender, Reservation reservation, ReservationChange change, ReserveerDBContext _context) { FormatNotificationMessage(receiver, sender, String.Format( @"The reservation from room '{0}' with description {1} was changed. From {2} untill {3} To: {4} untill {5}", reservation.Room.Name, reservation.Description, reservation.StartDate.ToString(), reservation.EndDate.ToString(), change.OldStatDate.ToString(), change.OldEndDate.ToString()), "Your reservation was changed.", _context); }
public static void SendReservationChangedMessage(User receiver, User sender, Reservation reservation, ReservationChange change) { SendNotification(receiver, sender, String.Format( @"The reservation '{0}' was changed. New time: {1} - {2} Old time: {3} - {4}", reservation.Description, reservation.StartDate.ToString(), reservation.EndDate.ToString(), change.OldStatDate.ToString(), change.OldEndDate.ToString())); }