Exemplo n.º 1
0
        public ActionResult GridView2PartialUpdate(ProjectAnalysis.Models.T_Product item)
        {
            var cid = Convert.ToInt32(Session["CustomerID"]);

            ViewData["ProductCategory"] = db.T_ProductCategory.ToList();
            List <T_Product> model = new List <Models.T_Product>();

            if (cid == 0)
            {
                ViewData["Customer"] = db.T_Customer.ToList();
                var smodel = db.T_Product.ToList();
            }
            else
            {
                ViewData["Customer"] = db.T_Customer.Where(m => m.CustomerID == cid).ToList();
                model = db.T_Product.Where(m => m.CustomerID == cid).ToList();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var modelItem = model.FirstOrDefault(it => it.ProductID == item.ProductID);
                    if (modelItem != null)
                    {
                        this.UpdateModel(modelItem);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            return(PartialView("_GridView2Partial", model.ToList()));
        }
Exemplo n.º 2
0
        public ActionResult GridView2PartialAddNew(ProjectAnalysis.Models.T_Product item)
        {
            var cid = Convert.ToInt32(Session["CustomerID"]);

            ViewData["ProductCategory"] = db.T_ProductCategory.ToList();
            List <T_Product> model = new List <Models.T_Product>();

            if (cid == 0)
            {
                ViewData["Customer"] = db.T_Customer.ToList();
                var smodel = db.T_Product.ToList();
            }
            else
            {
                ViewData["Customer"] = db.T_Customer.Where(m => m.CustomerID == cid).ToList();
                model = db.T_Product.Where(m => m.CustomerID == cid).ToList();
            }
            if (ModelState.IsValid)
            {
                try
                {
                    ObjectParameter output = new ObjectParameter("CurrentSequenceStr", typeof(string));
                    db.p_sys_GenSequence("T_Product_ProductID", output);
                    var result = output.Value;
                    item.ProductID        = long.Parse(result.ToString());
                    item.ProductAliasName = item.ProductName;
                    model.Add(item);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            return(PartialView("_GridView2Partial", model.ToList()));
        }