示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
 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
     });
 }
示例#4
0
 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;
 }
示例#5
0
        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);
        }