public void SaveReservation(ReservationInfo resInfo) { Guest guest = GetGuest(resInfo); Reservation reservation = GetReservation(resInfo.Id); if (reservation == null) { Reservations.Add(new Models.Reservation(resInfo)); Logging.Instance.WriteLine("Add reservation:"); reservation = resInfo.ToReservation(this); Context.Reservations.Add(reservation); } else { Reservations[resInfo.Id - 1] = new Models.Reservation(resInfo); Logging.Instance.WriteLine("Edit reservation:"); Logging.Instance.WriteLine($"Old: {reservation}", true); UpdateReservation(reservation, guest, resInfo); } Logging.Instance.WriteLine($"New: {reservation}", true); Context.SaveChanges(); UpdateResInfos(); OnReservationsChanged?.Invoke(this, EventArgs.Empty); }
public Reservation GetReservation(int id) { Reservation reservation = Context.Reservations .Include(r => r.Guest) .Include(r => r.Transactions) .Include(r => r.Room) .FirstOrDefault(r => r.Id == id); return(reservation); }
public void AddNewTransaction(Guest guest, Reservation reservation, decimal paidSum, DateTime transDate, string tarnsMethod) { reservation.Transactions.Add(new Transaction { Guest = guest, Reservation = reservation, PaidSum = paidSum - reservation.Transactions.Sum(t => t.PaidSum), PaymentDate = transDate, PaymentMethod = tarnsMethod }); }
public void UpdateReservation(Reservation reservation, Guest guest, ReservationInfo resInfo) { reservation.LastVersionJson = JsonHandler.SerializeToJson(reservation); reservation.State = (State)resInfo.StateInt; reservation.Source = (Source)resInfo.SourceInt; reservation.Room = Context.Rooms.FirstOrDefault(r => r.FullRoomNumber == resInfo.Room); reservation.Guest = guest; reservation.StartDate = resInfo.StartDate; reservation.EndDate = resInfo.EndDate; reservation.TotalSum = resInfo.TotalSum; reservation.NumberOfGuests = resInfo.NumberOfGuests; reservation.Notes = resInfo.Notes; reservation.DateModified = DateTime.Now; }
public void CheckInReservation(int room, DateTime startDate) { Reservation reservation = Context.Reservations .Include(r => r.Guest).Include(r => r.Transactions) .Where(r => r.Room.FullRoomNumber == room) .Where(r => r.StartDate <= startDate) .Where(r => startDate < r.EndDate) .FirstOrDefault(r => r.State != State.Canceled); if (reservation == null) { return; } Logging.Instance.WriteLine("Edit reservation:"); Logging.Instance.WriteLine($"Old: {reservation}", true); Reservations[reservation.Id - 1].State = State.CheckedIn; reservation.LastVersionJson = JsonHandler.SerializeToJson(reservation); reservation.State = State.CheckedIn; reservation.DateModified = DateTime.Now; Logging.Instance.WriteLine($"New: {reservation}", true); Context.SaveChanges(); UpdateResInfos(); OnReservationsChanged?.Invoke(this, EventArgs.Empty); }