Пример #1
0
        public static CurrentReservation CreateNewCurrentReservation(Dictionary <Item, int> itemToItemQuantity, DateTime expectedPickUpDate, InventoryContext dbContext)
        {
            var currRes = new CurrentReservation()
            {
                IsPickedUp         = false,
                ExpectedPickUpDate = expectedPickUpDate
            };

            try
            {
                dbContext.Reservations.Add(currRes);
                dbContext.SaveChanges();
            }
            catch (Exception)
            {
                //If the above commit to db didn't work
                return(null);
            }

            if (!CreateItemReservations(itemToItemQuantity, dbContext, currRes))
            {
                return(null);
            }
            else
            {
                return(currRes);
            }
        }
        public async Task <IActionResult> ConfirmClient(int id)
        {
            if (id == 0)
            {
                return(RedirectToAction(nameof(ShowClients)));
            }
            else
            {
                if (int.Parse(TempData["clientsnum"].ToString()) < int.Parse(TempData["roomcap"].ToString()))
                {
                    var clients = (from c in _context.Clients where c.Id == id select c).ToList();
                    if (clients.Count > 0)
                    {
                        string clientIds;
                        try
                        {
                            clientIds = TempData["clientids"].ToString();
                        }
                        catch (Exception)
                        {
                            clientIds = "";
                        }
                        clientIds += (clients[0].Id.ToString() + " ");
                        TempData["clientsnum"] = int.Parse(TempData["clientsnum"].ToString()) + 1;
                        //HttpContext.Items["clientIds"] = clientIds;
                        TempData["clientids"] = clientIds;
                        // CurrentReservation.Clients.Add(clients[0]);
                        return(RedirectToAction(nameof(ShowClients)));
                    }

                    //return RedirectToAction(nameof(ShowClients));
                }
                // Reservation res = CurrentReservation.GetReservation();
                Reservation res = new Reservation();
                res.StartDate      = DateTime.Parse(TempData["startdate"].ToString());
                res.EndDate        = DateTime.Parse(TempData["enddate"].ToString());
                res.IsAllInclusive = bool.Parse(TempData["allink"].ToString());
                res.IsAllInclusive = bool.Parse(TempData["breakfast"].ToString());
                // string a = TempData["clientids"].ToString();
                res.Reserver = CurrentReservation.GetReserver(int.Parse(TempData["userId"].ToString()), _context);
                res.Room     = CurrentReservation.GetRoom(int.Parse(TempData["roomid"].ToString()), _context);
                res.Clients  = CurrentReservation.GetClients(TempData["clientids"].ToString().Substring(1), _context);
                res.Price    = CurrentReservation.CalkPrice(res);
                try { SecurityChecker.CheckReservation(res); }
                catch (Exception)
                {
                    return(RedirectToAction(nameof(Create)));
                }
                _context.Add(res);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
        }
        // Methods
        private void CreateReservation(object obj)
        {
            CurrentReservation.Guest         = SelectedGuest;
            CurrentReservation.Area          = SelectedArea;
            CurrentReservation.ArrivalStatus = SelectedArrivalStatus;
            CurrentReservation.WantedSeats   = SelectedWantedSeats;
            foreach (var table in SelectedReservedTables)
            {
                CurrentReservation.Tables.Add(table);
            }
            CurrentReservation.TimeIn = SelectedDate.ChangeTime(SelectedTimeIn.Hour, SelectedTimeIn.Minute);
            if (SelectedTimeOut.Hour != 0 && SelectedTimeOut.Minute != 0)
            {
                CurrentReservation.TimeOut = new DateTime();
                CurrentReservation.TimeOut = SelectedDate.ChangeTime(SelectedTimeOut.Hour, SelectedTimeOut.Minute);
            }
            if (!string.IsNullOrEmpty(SelectedGuest.FirstName) || !string.IsNullOrEmpty(SelectedGuest.LastName))
            {
                CurrentReservation.Guest = SelectedGuest;
            }

            string result = CurrentReservation.IsValid();

            if (result == "true")
            {
                SqlConnector conn = new SqlConnector();
                // If guest is not null then insert or update in people table.
                if (CurrentReservation.Guest != null)
                {
                    conn.CreateOrUpdateGuest(CurrentReservation.Guest);
                }
                // Whether guest is null or not does not affect the reservation itself.
                conn.CreateReservation(CurrentReservation);
                MessageBox.Show("Your reservation has been saved!");
                ClearAll();
            }
            else
            {
                MessageBox.Show(result);
            }
        }
Пример #4
0
        /*
         * public static PastReservation CreateNewPastReservation()
         * {
         *
         * }*/

        public static bool CreateItemReservations(Dictionary <Item, int> itemToItemQuantity, InventoryContext dbContext, CurrentReservation currRes)
        {
            //If this transaction worked
            bool isSuccessful;

            try
            {
                foreach (KeyValuePair <Item, int> itemQuantity in itemToItemQuantity)
                {
                    dbContext.ItemReservations.Add(new ItemReservation()
                    {
                        Item        = itemQuantity.Key,
                        Reservation = currRes,
                        Quantity    = itemQuantity.Value
                    });
                }
                dbContext.SaveChanges();

                isSuccessful = true;
            }
            catch (Exception)
            {
                //If adding ItemReservations fails, remove currRes
                dbContext.Reservations.Remove(currRes);
                dbContext.SaveChanges();
                isSuccessful = false;
            }

            return(isSuccessful);
        }