コード例 #1
0
        public ActionResult AddNewItemToExistingOrder(FormCollection collection)
        {
            int orderId             = Convert.ToInt32(collection["OrderId"]);
            List <OrderItem> orders = (List <OrderItem>)Session["TOrders"];

            try
            {
                var clientId  = Convert.ToInt32(collection["ClientId"]);
                var client    = _iClientManager.GetById(clientId);
                int productId = Convert.ToInt32(collection["ProductId"]);
                var aProduct  = _iProductManager.GetProductByProductAndClientTypeId(productId, client.ClientTypeId);
                aProduct.Quantity = Convert.ToInt32(collection["Quantity"]);
                var orderItem = orders.Find(n => n.ProductId == productId);
                if (orderItem != null)
                {
                    ViewBag.Result = "This product already is in the list!";
                }
                else
                {
                    bool rowAffected = _iOrderManager.AddNewItemToExistingOrder(aProduct, orderId);
                    if (rowAffected)
                    {
                        ViewBag.Result = "1 new Item added successfully!";
                    }
                }

                //return RedirectToAction("Edit", orderId);
                return(RedirectToAction("Edit", new { id = orderId }));
            }
            catch (Exception e)
            {
                Log.WriteErrorLog(e);
                if (e.InnerException != null)
                {
                    ViewBag.Error = e.Message + " <br /> System Error:" + e.InnerException.Message;
                }
                return(PartialView("_ErrorPartial", e));
            }
        }