Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }