Exemple #1
0
        public ActionResult AddProduct()
        {
            var user = db.Users.Where(u => u.UserName.Equals(User.Identity.Name)).FirstOrDefault();

            ViewBag.ProductId = new SelectList(CombosHelper.GetProduct(user.CompanyId), "ProductId", "Description");

            return(PartialView());
        }
Exemple #2
0
        public ActionResult AddProduct(AddProductView view)
        {
            var user = db.Users.FirstOrDefault(u => u.UserName.Equals(User.Identity.Name));

            if (ModelState.IsValid)
            {
                var orderDetailTmp = db.OrderDetailTmps.FirstOrDefault(odt => odt.UserName == User.Identity.Name && odt.ProductId == view.productId);

                if (orderDetailTmp == null)
                {
                    var product = db.Products.Find(view.productId);

                    orderDetailTmp = new OrderDetailTmp
                    {
                        Description = product.Description,
                        Price       = product.Price,
                        ProductId   = product.ProductId,
                        Quantity    = view.Quantity,
                        TaxRate     = product.Tax.Rate,
                        UserName    = User.Identity.Name
                    };

                    db.OrderDetailTmps.Add(orderDetailTmp);
                }
                else
                {
                    orderDetailTmp.Quantity       += view.Quantity;
                    db.Entry(orderDetailTmp).State = EntityState.Modified;
                }



                try
                {
                    db.SaveChanges();
                    return(RedirectToAction("Create"));
                }
                catch (Exception)
                {
                    throw;
                }
            }


            ViewBag.ProductId = new SelectList(CombosHelper.GetProduct(user.CompanyId, true), "ProductId", "Description", view.productId);

            return(PartialView(view));
        }