Beispiel #1
0
        // GET: Order
        public ActionResult Index()
        {
            List <OrderPO> mappedOrders = null;
            List <OrderDO> allOrders    = null;

            try
            {
                allOrders = _orderDataAccess.ReadAllOrders();

                mappedOrders = new List <OrderPO>();

                foreach (OrderDO dataObject in allOrders)
                {
                    mappedOrders.Add(OrderMappers.OrderDOtoPO(dataObject));
                }
            }

            catch (Exception exception)
            {
                ErrorLogger.LogExceptions(exception);
            }

            finally
            { }

            return(View(mappedOrders));
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }