示例#1
0
        public ActionResult DeletePrefabPizza(long ID)
        {
            ActionResult response = null;

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

                if (pizzaDO != null) // If that pizza exists
                {
                    PizzaPO existingPizza = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO);

                    if (existingPizza.OrderID == null)  // If the pizza is in fact a prefab
                    {
                        _pizzaDAO.DeletePizza(ID);
                        TempData["SuccessMessage"] = "Pizza was successfully deleted";
                        response = RedirectToAction("PrefabPizzas", "Pizza");
                    }
                    else // Otherwise, the pizza the Admin is trying to delete is not a prefab pizza.
                    {
                        response = RedirectingPage("That pizza is not a prefab.", "../PrefabPizzas");
                    }
                }
                else // Otherwise, the pizza didn't exist.
                {
                    response = RedirectToAction("That pizza doesn't exist.", "../PrefabPizzas");
                }
            }
            catch (Exception exception)
            {
                Logger.LogExceptionNoRepeats(exception);
            }
            finally
            {
                if (response == null)
                {
                    response = RedirectToAction("Index", "Home");
                }
            }

            return(response);
        }
示例#2
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);
}
示例#3
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);
}