Exemplo n.º 1
0
        public ActionResult AddProduct()
        {
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            ViewBag.ProductId = new SelectList(CombosHelpers.GetProducts(user.CompanyID, false), "ProductId", "Description");
            return(PartialView());
        }
Exemplo n.º 2
0
        public ActionResult AddProduct(AddProductView view)
        {
            if (ModelState.IsValid)
            {
                var orderDetailTmp = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name && odt.ProductId == view.ProductId).FirstOrDefault();
                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;
                }

                db.SaveChanges();
                return(RedirectToAction("Create"));
            }

            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            ViewBag.ProductId = new SelectList(CombosHelpers.GetProducts(user.CompanyID), "ProductId", "Description");
            return(PartialView(view));
        }
Exemplo n.º 3
0
        public ActionResult AddProduct(AddProductView addProductView)
        {
            if (ModelState.IsValid)
            {
                var product = db.Products.Find(addProductView.ProductId);

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

                db.OrderDetailTmps.Add(orderDetailTmp);
                db.SaveChanges();

                return(RedirectToAction("Create"));
            }

            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            ViewBag.ProductId = new SelectList(CombosHelpers.GetProducts(user.CompanyId), "ProductId", "Description");

            return(View());
        }