コード例 #1
0
        public ActionResult UpdatePrefabPizza(long ID)
        {
            ActionResult response = null;

            try
            {
                PizzaDO pizzaDO = _pizzaDAO.ViewPizzaByID(ID); // Get the pizza by the ID.

                if (pizzaDO != null)                           // If a pizza by that Id exists.
                {
                    PizzaPO pizzaPO = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO);
                    FillPizzaSelectItems(pizzaPO);

                    if (pizzaPO.OrderID == null) // If the pizza is a prefab pizza.
                    {
                        pizzaPO.Description = null;
                        response            = View(pizzaPO);
                    }
                    else // It's not a prefab pizza.
                    {
                        TempData["ErrorMessage"] = "That pizza was not a prefab please choose another pizza.";
                        response = RedirectToAction("PrefabPizzas", "Pizza");
                    }
                }
                else // That pizza doesn't exist.
                {
                    RedirectingPage("The product with ID " + ID + " doesn't exist.", "");
                }
            }
            catch (Exception exception)
            {
                Logger.LogExceptionNoRepeats(exception);
            }
            finally
            {
                if (response == null)
                {
                    response = RedirectToAction("Index", "Home");
                }
            }

            return(response);
        }
コード例 #2
0
ファイル: PizzaController.cs プロジェクト: bobbyanne/capstone
        public ActionResult UpdatePrefabPizza(long ID)
        {
            ActionResult response = null;

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

                if (pizzaDO != null) // If a pizza by that Id exists.
                {
                    PizzaPO pizzaPO = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO);
                    FillPizzaSelectItems(pizzaPO);

                    if (pizzaPO.OrderID == null)
                    {
                        pizzaPO.Description = null;
                        response            = View(pizzaPO);
                    }
                    else // It's not a prefab pizza.
                    {
                        // TODO: Show admin the messup. Also log this.
                    }
                }
                else
                {
                    RedirectingPage("The product with ID " + ID + " doesn't exist.", "");
                }
            }
            catch (Exception exception)
            {
                Logger.LogExceptionNoRepeats(exception);
            }
            finally
            {
                if (response == null)
                {
                    response = RedirectToAction("Index", "Home");
                }
            }

            return(response);
        }
コード例 #3
0
ファイル: CartController.cs プロジェクト: bobbyanne/capstone
        public ActionResult AddPizzaToCart(long ID)
        {
            ActionResult response = null;

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

                if (pizzaDO == null) //  If that prefab doesn't exist...
                {
                    // redirect to home.
                    response = RedirectToAction("Index", "Home");
                }
                else
                {
                    // First check if this pizza is actually a prefab pizza created
                    // by the Admin.  Prefabs won't have an OrderID.
                    if (pizzaDO.OrderID != null)
                    {
                        response = RedirectToAction("Index", "Pizza");
                    }
                    else
                    {
                        // Add the pizza to the cart.
                        List <PizzaPO> cart = (List <PizzaPO>)Session["Cart"];
                        cart.Add(Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDO));

                        TempData["SuccessMessage"] = "Item added to cart.";

                        response = RedirectToAction("Index", "Pizza");
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.LogExceptionNoRepeats(exception);
            }
            finally
            {
                if (response == null)
                {
                    response = RedirectToAction("Index", "Home");
                }
            }

            return(response);
        }
コード例 #4
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);
}
コード例 #5
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);
}