Ejemplo n.º 1
0
        //Cancel an order and decrement a counter so the delivery employee may be available again
        //The user must enter his firstname and lastaname correctly to make all this happening.
        public ActionResult CancelOrder(Customer customerModel)
        {
            var customerDbManager = new CustomerManager(Configuration);
            int idCustomer        = (int)HttpContext.Session.GetInt32("idCustomer");

            Customer customer = customerDbManager.GetFirstnameLastname(idCustomer);
            //We make our strings lower case so we don't care whether the customer use capital case or not.
            string firstnameC = customerModel.FirstName.ToLower();
            string lastnameC  = customerModel.LastName.ToLower();

            if (firstnameC.Equals(customer.FirstName.ToLower()) && lastnameC.Equals(customer.LastName.ToLower()))
            {
                int      idOrder              = (int)HttpContext.Session.GetInt32("idOrder");
                int      idStaffToDecrement   = (int)HttpContext.Session.GetInt32("idStaffToDecrement");
                TimeSpan deliveryTimeToCancel = SessionHelper.GetObjectFromJson <TimeSpan>(HttpContext.Session, "deliveryTimeToCancel");

                Dishes_orderManager dManager = new Dishes_orderManager(Configuration);
                dManager.UpdateOrderStatusToCancel(idOrder);

                AvailibilityManager aManager = new AvailibilityManager(Configuration);
                aManager.DecrementCounter(idStaffToDecrement);

                Availability availabilityStatus = aManager.IsAvailable(idStaffToDecrement, deliveryTimeToCancel);
                if (!availabilityStatus.isAvailable)
                {
                    aManager.UpdateAvailability(availabilityStatus.idAvailability, 1);
                }
                return(RedirectToAction("customerOrders", "DishesOrder"));
            }
            else
            {
                //If the user fails in entering a correct firstname and lastname the cancellation do not happen
                return(RedirectToAction("OrderCancelError", "Error", new { message = "Unfortunately your firstname or lastname did not match our records. Please try again." }));
            }
        }