Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static OrderPO GetDataForSave(int id)
        {
            OrderPO item;

            if (id == 0)
            {
                item = new OrderPO()
                {
                    UserId            = 0,
                    Contact           = "",
                    Telphone          = "",
                    Mobliephone       = "",
                    Totalamount       = 0,
                    Reduction         = 0,
                    AmountpaId        = 0,
                    PromotionId       = "",
                    PromotionladderId = "",
                    SchoolId          = 0,
                    Deliveryaddress   = "",
                    Remark            = "",
                    Status            = 0,
                    Createtime        = DateTime.Now,
                    Updatetime        = DateTime.Now,
                };
            }
            else
            {
                item = GetItem(id);
            }
            return(item);
        }
Exemple #2
0
        public ActionResult CreateOrder()
        {
            OrderPO      order    = new OrderPO();
            ActionResult response = RedirectToAction("Index", "Home");

            if (Session["RoleID"] != null && ((int)Session["RoleID"] == 2 || (int)Session["RoleID"] == 3))
            {
                //Filling selectlist
                foreach (ProductDO dataObject in _productDataAccess.ReadAllProducts())
                {
                    //declaring a selectlistitem for the list in the OrderPO property ProductsDropDown
                    SelectListItem listItem = new SelectListItem();
                    //Assigning the product's name to the listitem's text
                    listItem.Text = dataObject.Name;
                    //Assigning the product's ID to the listitem's value
                    listItem.Value = dataObject.ProductID.ToString();
                    //Adding the listitem, with its text and value, to the ProductsDropDown property of the OrderPO object
                    order.ProductsDropDown.Add(listItem);
                }

                //Could instead make quantity not an int but make it required that it's an int? So as to not have a character
                //show up when the form loads.
                order.Quantity = 1;

                response = View(order);
            }

            else
            {
                response = RedirectToAction("Index", "Home");
            }

            return(response);
        }
Exemple #3
0
        /************* HELPER METHODS BEGIN ***************/

        private void FillSelectListItems(OrderPO orderPO)
        {
            List <string> textValues = new List <string> {
                "Prepping", "Cooking", "Completed"
            };

            orderPO.StatusSelectListItemsPickup   = new List <SelectListItem>();
            orderPO.StatusSelectListItemsDelivery = new List <SelectListItem>();

            foreach (string elm in textValues)
            {
                orderPO.StatusSelectListItemsDelivery.Add(new SelectListItem {
                    Text = elm, Value = elm
                });
                orderPO.StatusSelectListItemsPickup.Add(new SelectListItem {
                    Text = elm, Value = elm
                });
            }

            if (orderPO.IsDelivery)
            {
                orderPO.StatusSelectListItemsDelivery.Add(new SelectListItem {
                    Text = "Ready For Delivery", Value = "Ready For Delivery"
                });
                orderPO.StatusSelectListItemsDelivery.Find(item => item.Value == orderPO.Status).Selected = true;
            }
            else
            {
                orderPO.StatusSelectListItemsPickup.Add(new SelectListItem {
                    Text = "Ready For Pickup", Value = "Ready For Pickup"
                });
                orderPO.StatusSelectListItemsPickup.Find(item => item.Value == orderPO.Status).Selected = true;
            }
        }
 public static OrderModel ToModel(this OrderPO item)
 {
     if (item == null)
     {
         return(null);
     }
     return(new OrderModel
     {
         Id = item.Id,
         UserId = item.UserId,
         Contact = item.Contact,
         Telphone = item.Telphone,
         Mobliephone = item.Mobliephone,
         Totalamount = item.Totalamount,
         Reduction = item.Reduction,
         AmountpaId = item.AmountpaId,
         PromotionId = item.PromotionId,
         PromotionladderId = item.PromotionladderId,
         SchoolId = item.SchoolId,
         Deliveryaddress = item.Deliveryaddress,
         Remark = item.Remark,
         Status = item.Status,
         Createtime = item.Createtime,
         Updatetime = item.Updatetime,
     });
 }
        public ActionResult Create(OrderPO form)
        {
            ActionResult oResponse = RedirectToAction("Index", "Game");

            if (ModelState.IsValid)
            {
                try
                {
                    form.UserID = (Int64)Session["UserID"];
                    OrdersDO dataObject = OrderMapper.MapPoToDo(form);
                    dataAccess.CreateNewOrder(dataObject, Session["Cart"] as List <int>);

                    TempData["Message"] = $"{form.Name} order has been created";
                }
                catch (Exception ex)
                {
                    oResponse = View(form);
                }
            }
            else
            {
                oResponse = View(form);
            }
            Session["Cart"] = null;
            return(oResponse);
        }
Exemple #6
0
        public ActionResult CreateOrder([FromBody] OrderPO model)
        {
            var      timeCreate   = DateTime.Now;
            DateTime?timeDelivery = model.DeliveryTime;
            DateTime?takeTime     = model.TakeTime;
            var      deliver      = _slotService.GetSlots().Where(t1 => t1.TimeStart <= timeDelivery.Value.TimeOfDay).Where(t2 => t2.TimeEnd >= timeDelivery.Value.TimeOfDay).ToList();
            var      take         = _slotService.GetSlots().Where(t1 => t1.TimeStart <= takeTime.Value.TimeOfDay).Where(t2 => t2.TimeEnd >= takeTime.Value.TimeOfDay).ToList();
            var      checkCus     = _customerService.GetCustomer(model.CustomerId.Value);

            if (checkCus == null)
            {
                return(NotFound());
            }

            Order newOrder = model.Adapt <Order>();

            newOrder.IsDelete       = false;
            newOrder.SlotTakeId     = take[0].Id;
            newOrder.SlotDeliveryId = deliver[0].Id;
            newOrder.CreateTime     = timeCreate;
            _orderService.CreateOrder(newOrder);
            _orderService.Save();
            _hub.Clients.All.SendAsync("transferchartdata", "Có Đơn hàng được tạo");
            return(Ok(201));
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool Delete(int id)
        {
            var item = new OrderPO {
                Id = id
            };

            return(Delete(item));
        }
Exemple #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public static bool Delete(OrderPO item)
 {
     using (var context = new SchoolContext())
     {
         context.Orders.Attach(item);
         context.Orders.Remove(item);
         context.SaveChanges();
     }
     return(true);
 }
Exemple #9
0
        public ActionResult CreateOrder(OrderPO form)
        {
            ActionResult response = null;


            if (Session["RoleID"] != null && ((int)Session["RoleID"] == 2 || (int)Session["RoleID"] == 3))
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        OrderDO dataObject = OrderMappers.OrderPOtoDO(form);
                        _orderDataAccess.CreateOrder(dataObject);
                        response = RedirectToAction("Index", "Order");
                    }

                    catch (Exception exception)
                    {
                        ErrorLogger.LogExceptions(exception);
                        response = View(form);
                    }

                    finally
                    { }
                }

                else
                {
                    //Returning a list of products from the readall function in the DAL
                    foreach (ProductDO dataObject in _productDataAccess.ReadAllProducts())
                    {
                        //declaring a selectlistitem for the list in the OrderPO property ProductsDropDown
                        SelectListItem listItem = new SelectListItem();
                        //Assigning the product's name to the listitem's text
                        listItem.Text = dataObject.Name;
                        //Assigning the product's ID to the listitem's value
                        listItem.Value = dataObject.ProductID.ToString();

                        //Adding the listitem, with its text and value, to the ProductsDropDown property of the OrderPO object
                        form.ProductsDropDown.Add(listItem);
                    }

                    response = View(form);
                }
            }

            else
            {
                response = RedirectToAction("Index", "Home");
            }

            return(response);
        }
Exemple #10
0
        public static OrderBO OrderPOtoBO(OrderPO input)
        {
            OrderBO output = new OrderBO();

            output.OrderID             = input.OrderID;
            output.Quantity            = input.Quantity;
            output.DateOfOrder         = input.DateOfOrder;
            output.ExpectedArrivalDate = input.ExpectedArrivalDate;
            output.DistributionCenter  = input.DistributionCenter;
            output.ProductID           = input.ProductID;

            return(output);
        }
Exemple #11
0
        public static OrdersDO MapPoToDo(OrderPO from)
        {
            OrdersDO to = new OrdersDO();

            to.OrderID = from.OrderID;
            to.Name    = from.Name;
            to.Address = from.Address;
            to.Phone   = from.Phone;
            to.ZipCode = from.ZipCode;
            to.UserID  = from.UserID;

            return(to);
        }
Exemple #12
0
        public ActionResult UpdateOrder(int orderID)
        {
            OrderDO      item     = null;
            OrderPO      display  = null;
            ActionResult response = RedirectToAction("Index", "Home");

            //Available to all roles
            if (Session["RoleID"] != null)
            {
                try
                {
                    item    = _orderDataAccess.ReadIndividualOrder(orderID);
                    display = OrderMappers.OrderDOtoPO(item);

                    //Filling selectlist
                    foreach (ProductDO dataObject in _productDataAccess.ReadAllProducts())
                    {
                        //declaring a selectlistitem for the list in the OrderPO property ProductsDropDown
                        SelectListItem listItem = new SelectListItem();
                        //Assigning the product's name to the listitem's text
                        listItem.Text = dataObject.Name;
                        //Assigning the product's ID to the listitem's value
                        listItem.Value = dataObject.ProductID.ToString();

                        //Adding the listitem, with its text and value, to the ProductsDropDown property of the OrderPO object
                        display.ProductsDropDown.Add(listItem);
                    }

                    //Setting the dropdown list to the correct product:
                    display.ProductID = item.ProductID;
                }

                catch (Exception exception)
                {
                    ErrorLogger.LogExceptions(exception);
                    response = View(orderID);
                }

                finally
                { }

                response = View(display);
            }

            else
            {
                response = RedirectToAction("Index", "Home");
            }

            return(response);
        }
Exemple #13
0
public ActionResult CompleteDelivery(long ID)
{
    ActionResult response = null;

    try
    {
        // Get the order the user is wanting to delete.
        OrderDO orderDOtoComplete = _orderDAO.GetOrderByID(ID);

        if (orderDOtoComplete != null)         // If the order exists.
        {
            // Map the orderDO to an orderPO
            OrderPO orderPOtoComplete = Mapping.OrderMapper.OrderDOtoOrderPO(orderDOtoComplete);

            // If the order is in fact a delivery order.
            if (orderPOtoComplete.IsDelivery)
            {
                // Complete the order.
                _orderDAO.CompleteOrder(ID);

                TempData["SuccessMessage"] = "Order Complete";
            }
            else         // The order the user is trying to delete is not a delivery order.
            {
                TempData["ErrorMessage"] = "That order# " + ID + " is not a delivery order. The order may have been changed to carryout.";
            }
        }
        else          // The order doesn't exist.
        {
            TempData["ErrorMessage"] = "Order# " + ID + " doesn't exist.  The order may have been deleted.";
        }

        response = RedirectToAction("MyDeliveries", "Order");

        return(response);
    }
    catch (Exception exception)
    {
        Logger.LogExceptionNoRepeats(exception);
    }
    finally
    {
        if (response == null)
        {
            response = RedirectToAction("Index", "Home");
        }
        else /* The response was not null */ } {
}

return(response);
}
        public ActionResult UpdateOrder(Int64 orderID)
        {
            OrderPO displayObject = new OrderPO();

            try
            {
                OrdersDO item = dataAccess.ViewOrdersByID(orderID);
                displayObject = OrderMapper.MapDoToPo(item);
            }
            catch (Exception ex)
            {
            }
            return(View(displayObject));
        }
Exemple #15
0
        public static List <OrderPO> MapDoToPo(List <OrdersDO> from)
        {
            List <OrderPO> to = new List <OrderPO>();

            if (from != null)
            {
                foreach (OrdersDO item in from)
                {
                    OrderPO mappedItem = MapDoToPo(item);
                    to.Add(mappedItem);
                }
            }
            return(to);
        }
Exemple #16
0
public ActionResult RemoveDelivery(long ID)
{
    ActionResult response = null;

    try
    {
        // Get the order the using is trying to delete.
        OrderDO orderDOtoRemove = _orderDAO.GetOrderByID(ID);

        if (orderDOtoRemove != null)         // If that order exists.
        {
            // Map the order to a OrderPO.
            OrderPO orderPOtoRemove = Mapping.OrderMapper.OrderDOtoOrderPO(orderDOtoRemove);

            // If the current user is the driver on the order.
            if (orderDOtoRemove.DriverID == GetSessionUserID() || GetSessionRole() == 1)
            {
                _orderDAO.RemoveDeliveryFromDriver(ID);
            }
            else
            {
                TempData["ErrorMessage"] = "You MAY NOT remove an order that doesn't belong to you.";
                Logger.Log("WARNING", "OrderController", "RemoveDelivery",
                           "User ID: " + GetSessionUserID() + " tried to delete " + orderDOtoRemove.BuyerName + "'s order");
            }
        }
        else
        {
            TempData["ErrorMessage"] = "That order doesn't exist.";
        }

        response = RedirectToAction("MyDeliveries", "Order");
    }
    catch (Exception exception)
    {
        Logger.LogExceptionNoRepeats(exception);
    }
    finally
    {
        if (response == null)
        {
            response = RedirectToAction("Index", "Home");
        }
        else /* response was not null */ } {
}

return(response);
}
Exemple #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public static bool Save(OrderPO item)
 {
     using (var context = new SchoolContext())
     {
         if (item.Id == 0)
         {
             context.Orders.Add(item);
         }
         else
         {
             context.Entry(item).State = EntityState.Modified;
         }
         context.SaveChanges();
     }
     return(true);
 }
Exemple #18
0
public ActionResult TakeDelivery(long ID)
{
    ActionResult response = null;

    try
    {
        // Get the order the user wants to update.
        OrderPO orderPO =
            Mapping
            .OrderMapper
            .OrderDOtoOrderPO(_orderDAO.GetOrderByID(ID));

        // If this order is in fact a delivery order.
        if (orderPO.IsDelivery)
        {
            // Assign the current user to the order's DriverID.
            _orderDAO.AssignDriverToOrder(ID, GetSessionUserID());

            TempData["SuccessMessage"] = "Successfully added order# " + ID + " to your current deliveries.";

            response = RedirectToAction("ReadyDeliveries", "Order");
        }
        else          // Otherwise this order is not a delivery order.
        {
            TempData["ErrorMessage"] = "Could not add that order to you current deliveries.";

            Logger.Log("INFO", "OrderController", "TakeDelivery",
                       "User# " + GetSessionUserID() + " tried to checkout an order that was " +
                       "not a delivery order.");
        }
    }
    catch (Exception exception)
    {
        TempData["ErrorMessage"] = "An error occured while adding that order to your current deliveries.";
        response = RedirectToAction("ReadyDeliveries", "Order");
        Logger.LogExceptionNoRepeats(exception);
    }
    finally
    {
        if (response == null)
        {
            response = RedirectToAction("Index", "Home");
        }
    }

    return(response);
}
Exemple #19
0
public ActionResult DeleteOrder(long ID)
{
    ActionResult response = null;

    try
    {
        int rowsAffected = 0;

        // Get the order the user is trying to delete.
        OrderPO orderPO = Mapping.OrderMapper.OrderDOtoOrderPO(_orderDAO.GetOrderByID(ID));

        // If an Admin is trying to delete an order or if the order is in fact the user's,
        // then delete the order.
        if (GetSessionRole() == 1 || orderPO.UserID == GetSessionUserID())
        {
            // Delete the order and capture the number of rows affected.
            rowsAffected = _orderDAO.DeleteOrder(ID);

            response = RedirectingPage("Order deleted", "../../");
        }
        else
        {
            // The user doesn't have permissions to delete this order.
            response = RedirectingPage("You do not have permissions to delete this order.", "");
        }
    }
    catch (Exception exception)
    {
        Logger.LogExceptionNoRepeats(exception);
    }
    finally
    {
        if (response == null)
        {
            TempData["ErrorMessage"] = "There was a problem deleting your order, " +
                                       "please try again later.";
            response = RedirectToAction("MyOrders", "Order");
        }
        else /* The response was not null. */ } {
}

return(response);
}
Exemple #20
0
        public static OrderBO OrderPOtoOrderBO(OrderPO from)
        {
            OrderBO to = new OrderBO();

            to.OrderID            = from.OrderID;
            to.UserID             = from.UserID;
            to.DriverID           = from.UserID;
            to.IsDelivery         = from.IsDelivery;
            to.OrderDate          = from.OrderDate;
            to.OrderFulfilledTime = from.OrderFulfilledTime;
            to.Status             = from.Status;
            to.Paid            = from.Paid;
            to.Total           = from.Total;
            to.DriverFirstName = from.DriverFirstName;
            to.BuyerName       = from.BuyerName;
            to.BuyerAddress    = from.BuyerAddress;

            return(to);
        }
Exemple #21
0
        public ActionResult ViewPendingOrders()
        {
            ActionResult response = null;

            try
            {
                // Build a list of orderPOs to pass along to the View.
                List <OrderPO> orderPOList = new List <OrderPO>();

                foreach (OrderDO orderDO in _orderDAO.GetPendingOrders())
                {
                    OrderPO orderPO = Mapping.OrderMapper.OrderDOtoOrderPO(orderDO);

                    // If the status is not equal to "En Route" then fill the
                    // select list items so the admin can change them.
                    if (orderDO.Status != "En Route")
                    {
                        FillSelectListItems(orderPO);
                    }
                    else /* Don't fill the select list items */ } {
                    orderPOList.Add(orderPO);
            }

            // Pass in the list pending orders to the Views
            response = View(orderPOList);
        }
        catch (Exception exception)
        {
            Logger.LogExceptionNoRepeats(exception);
        }
        finally
        {
            if (response == null)
            {
                response = RedirectToAction("Index", "Home");
            }
            else /* response was assigned */ } {
    }

    return(response);
}
        public ActionResult UpdateOrder(OrderPO form)
        {
            ActionResult oReponse = RedirectToAction("Index", "Order");

            if (ModelState.IsValid)
            {
                try
                {
                    form.UserID = (Int64)Session["UserID"];
                    OrdersDO dataObject = OrderMapper.MapPoToDo(form);
                    dataAccess.UpdateOrder(dataObject);
                }
                catch (Exception ex)
                {
                    oReponse = View(form);
                }
            }
            else
            {
                oReponse = View(form);
            }
            return(oReponse);
        }
Exemple #23
0
public ActionResult OrderDetails(long ID)
{
    ActionResult response = null;

    try
    {
        OrderDO orderDO = _orderDAO.GetOrderByID(ID);

        if (orderDO != null)          // If that order exists
        {
            // Map the orderDO we got earlier to a orderPO
            OrderPO orderPO = Mapping.OrderMapper.OrderDOtoOrderPO(orderDO);

            // -- Allow the Driver's and Admins to view other person's order details but
            // -- don't allow the other users to view other user's order details.
            if (orderPO.UserID != GetSessionUserID() && GetSessionRole() == 3)
            {
                response = RedirectingPage("You don't have permissions to view this page.", "../../Account/Login");
            }
            else
            {
                // Get all the pizzas associtated with this order
                List <PizzaPO> pizzaPOList =
                    Mapping
                    .PizzaMapper
                    .PizzaDOListToPizzaPOList(_pizzaDAO.GetPizzasByOrderID(ID));

                // Create the view model for 1 order and a list of pizzas
                PizzaOrderVM pizzaOrderVM = new PizzaOrderVM();
                pizzaOrderVM.Order = orderPO;

                pizzaOrderVM.Pizzas = pizzaPOList;

                // Pass in the view model to the View.
                response = View(pizzaOrderVM);
            }
        }
        else
        {           // The order couldn't be found.
                    // If the current user is an Admin then show that the order doesn't exist
            if (GetSessionRole() == 1)
            {
                response = RedirectingPage("Order does not exist", "../");
            }
            else         // Don't show anyone else that the order doesn't exist.
            {
                response = RedirectToAction("Home", "Index");
            }
        }
    }
    catch (Exception exception)
    {
        Logger.LogExceptionNoRepeats(exception);
    }
    finally
    {
        if (response == null)
        {
            response = RedirectToAction("Index", "Home");
        }
    }

    return(response);
}
Exemple #24
0
public ActionResult DeleteFromOrder(long ID)
{
    ActionResult response     = null;
    int          rowsAffected = 0;

    try
    {
        // Get the pizza the user is currently trying to delete from the DB.
        PizzaDO pizzaDO = _pizzaDAO.ViewPizzaByID(ID);

        if (pizzaDO != null)         // If the pizza exists in the DB
        {
            PizzaPO pizzaPO = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO);

            if (pizzaPO.OrderID == null)         // If this pizza is a prefab pizza.
            {
                // Thats a prefab pizza and that shouldn't be deleted from this action.
                if (GetSessionRole() == 1)
                {
                    TempData["ErrorMessage"] = "You must delete that pizza from this page.";
                    response = RedirectToAction("PrefabPizzas", "Pizza");
                }
                else
                {
                }
            }
            else         // Otherwise, the pizza isn't a prefab.
            {
                // Get the order that this pizza is associated with the pizza.
                // Use this later to update the new total for the order.
                OrderPO orderPO =
                    Mapping
                    .OrderMapper
                    .OrderDOtoOrderPO(_orderDAO.GetOrderByID((long)pizzaPO.OrderID));

                if (GetSessionRole() == 1)          // If current user is an Admin.
                {
                    // Delete the pizza from the order.
                    rowsAffected = _pizzaDAO.DeletePizza(ID);
                }
                else
                {
                    // Check to make sure that the current user is associated with the pizza's order.

                    if (GetSessionUserID() != orderPO.UserID)          // If the order is not tied to the current user...
                    {
                        Logger.Log("WARNING", "PizzaController", "DeletePizza",
                                   "User #" + GetSessionUserID() + " tried to delete someone elses pizza");

                        response = RedirectingPage("You do not have enough permissions to change a customers order.", "../../");
                    }
                    else                  // The user is trying to delete their own pizza.
                    {
                        if (orderPO.Paid) // If the order has already been paid for.
                        {
                            // Send the user back to the Order Details page.
                            TempData["ErrorMessage"] = "The order cannot be changed since it has already been paid for.";
                            response = RedirectToAction("OrderDetails", "Order", new { ID = orderPO.OrderID });
                        }
                        else
                        {
                            // The order hasn't been paid for yet, so it's oaky to delete the pizza.
                            rowsAffected = _pizzaDAO.DeletePizza(ID);
                            response     = RedirectToAction("OrderDetails", "Order", new { ID = orderPO.OrderID });
                        }
                    }
                }

                if (rowsAffected > 0)         // If a database call was made and it was successfull.
                {
                    // Recalculate the total for the order.

                    // Get all of the pizzas associated with this order
                    List <PizzaBO> pizzaBOList =
                        Mapping
                        .PizzaMapper
                        .PizzaDOListToPizzaBOList(_pizzaDAO.GetPizzasByOrderID(orderPO.OrderID));

                    if (pizzaBOList.Count == 0)         // If there are no pizzas tied to this order...
                    {
                        // Delete the order.
                        response = RedirectToAction("DeleteOrder", "Order", new { ID = orderPO.OrderID });
                    }
                    else
                    {
                        // Calculate the new total
                        decimal newTotal = _pizzaBLO.GetCostOfPizzas(pizzaBOList);

                        // Update the order's total.
                        _orderDAO.UpdateOrderTotal(orderPO.OrderID, newTotal);

                        // Redirect the user to the order details page.
                        TempData["SuccessMessage"] = "Successfully delete the pizza from the order.";
                        response = RedirectToAction("OrderDetails", "Order", new { ID = orderPO.OrderID });
                    }
                }
            }
        }
        else
        {
            TempData["ErrorMessage"] = "That pizza doesn't exists.";
        }
    }
    catch (Exception exception)
    {
        Logger.LogExceptionNoRepeats(exception);
    }
    finally
    {
        if (response == null)
        {
            response = RedirectToAction("Index", "Home");
        }
    }

    return(response);
}
Exemple #25
0
public ActionResult DeleteFromOrder(long ID)
{
    ActionResult response     = null;
    int          rowsAffected = 0;

    try
    {
        PizzaDO pizzaDO = _pizzaDAO.ViewPizzaByID(ID);

        if (pizzaDO != null)
        {
            PizzaPO pizzaPO = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO);

            if (pizzaPO.OrderID == null)
            {
                // Thats a prefab pizza and that shouldn't be deleted from this action.
                if (GetSessionRole() == 1)
                {
                    TempData["ErrorMessage"] = "You must delete that pizza from this page.";
                    response = RedirectToAction("PrefabPizzas", "Pizza");
                }
            }
            else
            {
                // Get the order that this pizza is associated with the pizza.
                // Use this later to update the new total for the order.
                OrderPO orderPO =
                    Mapping
                    .OrderMapper
                    .OrderDOtoOrderPO(_orderDAO.GetOrderByID((long)pizzaPO.OrderID));

                if (GetSessionRole() == 1)
                {
                    rowsAffected = _pizzaDAO.DeletePizza(ID);
                }
                else
                {
                    // Check to make sure that the current user is associated with the pizza's order.
                    if (GetSessionUserID() == orderPO.UserID)
                    {
                        // The user is deleting their own pizza, so that's okay.
                        rowsAffected = _pizzaDAO.DeletePizza(ID);
                        response     = RedirectToAction("OrderDetails", "Order", new { ID = orderPO.OrderID });
                    }
                    else
                    {
                        Logger.Log("WARNING", "PizzaController", "DeletePizza",
                                   "User #" + GetSessionUserID() + " tried to delete someone elses pizza");
                        response = RedirectingPage("You do not have enough permissions to change a customers order.", "../../");
                    }
                }

                if (rowsAffected > 0)
                {
                    // Recalculate the total for the order.

                    // Get all of the pizza associated with this order
                    List <PizzaBO> pizzaBOList =
                        Mapping
                        .PizzaMapper
                        .PizzaDOListToPizzaBOList(_pizzaDAO.GetPizzasByOrderID(orderPO.OrderID));

                    // Calculate the new total
                    decimal newTotal = _pizzaBLO.GetCostOfPizzas(pizzaBOList);

                    // Update the order's total.
                    _orderDAO.UpdateOrderTotal(orderPO.OrderID, newTotal);
                }
            }
        }
        else
        {
            TempData["ErrorMessage"] = "That pizza doesn't exists.";
        }
    }
    catch (Exception exception)
    {
        Logger.LogExceptionNoRepeats(exception);
    }
    finally
    {
        if (response == null)
        {
            response = RedirectToAction("Index", "Home");
        }
    }

    return(response);
}
Exemple #26
0
        public ActionResult UpdateOrder(OrderPO form)
        {
            ActionResult response = null;

            //Available to all roles
            if (Session["RoleID"] != null)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        OrderDO dataObject = OrderMappers.OrderPOtoDO(form);
                        _orderDataAccess.UpdateOrder(dataObject);
                        response = RedirectToAction("Index", "Order");
                    }

                    catch (Exception exception)
                    {
                        ErrorLogger.LogExceptions(exception);
                        response = View(form);
                    }

                    finally
                    { }
                }

                else
                {
                    try
                    {
                        OrderDO item = _orderDataAccess.ReadIndividualOrder(form.OrderID);
                        //OrderPO display = OrderMappers.OrderDOtoPO(item);

                        //GETTING LIST OF PRODUCTS
                        foreach (ProductDO dataObject in _productDataAccess.ReadAllProducts())
                        {
                            //declaring a selectlistitem for the list in the OrderPO property ProductsDropDown
                            SelectListItem listItem = new SelectListItem();
                            //Assigning the product's name to the listitem's text
                            listItem.Text = dataObject.Name;
                            //Assigning the product's ID to the listitem's value
                            listItem.Value = dataObject.ProductID.ToString();

                            //Adding the listitem, with its text and value, to the ProductsDropDown property of the OrderPO object

                            //Previous was:
                            //display.ProductsDropDown.Add(listItem);
                            //Now trying:
                            form.ProductsDropDown.Add(listItem);
                        }
                    }

                    catch (Exception exception)
                    {
                        ErrorLogger.LogExceptions(exception);
                        response = View(form);
                    }

                    finally
                    { }

                    response = View(form);
                }
            }

            else
            {
                response = RedirectToAction("Index", "Home");
            }

            return(response);
        }
Exemple #27
0
        public ActionResult UpdatePizzaInOrder(long ID)
        {
            ActionResult response = null;

            try
            {
                PizzaDO pizzaDOtoUpdate = _pizzaDAO.ViewPizzaByID(ID);

                if (pizzaDOtoUpdate != null)
                {
                    // This pizza exists in the database.

                    // Get the order that the pizza is associated with.
                    OrderPO pizzaOrderPO =
                        Mapping
                        .OrderMapper
                        .OrderDOtoOrderPO(
                            _orderDAO.GetOrderByID((long)pizzaDOtoUpdate.OrderID)
                            );

                    // If the current user is tied to the Pizza's order OR if the current user is an Admin.
                    if (pizzaOrderPO.UserID == GetSessionUserID() || GetSessionRole() == 1)
                    {
                        // Map the pizza the user is trying to update to a PizzaPO
                        PizzaPO pizzaPOtoUpdate = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDOtoUpdate);

                        if (pizzaOrderPO.Paid) // If the order has already been paid for.
                        {
                            // Redirect the user to the order's details.

                            TempData["ErrorMessage"] = "You cannot update a pizza on an order that has already been paid for.";
                            response = RedirectToAction("OrderDetails", "Order", new { ID = pizzaOrderPO.OrderID });
                        }
                        else // Otherwise, the pizza can be updated.
                        {
                            FillPizzaSelectItems(pizzaPOtoUpdate);

                            // Pass the PizzaPO to the view.
                            response = View(pizzaPOtoUpdate);
                        }
                    }
                    else
                    {
                        // A regular user tried to update someone elses pizza.
                        Logger.Log("WARNING", "PizzaController", "UpdatePizzaInOrder",
                                   "UserID: " + GetSessionUserID() + " tried to update someone else's pizza.");

                        response = RedirectToAction("MyOrders", "Order");
                    }
                }
                else // The pizza doesn't exist.
                {
                    if (GetSessionRole() == 1) // If the current user is an Admin
                    {
                        TempData["ErrorMessage"] = "That doesn't exist.";
                        RedirectToAction("ViewPendingOrders", "Order");
                    }
                    else
                    {
                        response = RedirectToAction("MyOrders", "Order");
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.LogExceptionNoRepeats(exception);
            }
            finally
            {
                if (response == null)
                {
                    response = RedirectToAction("Index", "Home");
                }
            }

            return(response);
        }