Ejemplo n.º 1
0
        public ActionResult CustomerGridViewPartialUpdate(ProjectAnalysis.Models.T_Customer item)
        {
            List <T_Customer> model = new List <T_Customer>();
            var cid = Convert.ToInt32(Session["CustomerID"]);

            if (cid == 0)
            {
                model = db.T_Customer.ToList();
            }
            else
            {
                model = db.T_Customer.Where(m => m.CustomerID == cid).ToList();
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var modelItem = model.FirstOrDefault(it => it.CustomerID == item.CustomerID);


                    if (modelItem != null)
                    {
                        this.UpdateModel(modelItem);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            return(PartialView("_CustomerGridViewPartial", model.ToList()));
        }
Ejemplo n.º 2
0
        public ActionResult CustomerGridViewPartialAddNew(ProjectAnalysis.Models.T_Customer item)
        {
            List <T_Customer> model = new List <T_Customer>();
            var cid = Convert.ToInt32(Session["CustomerID"]);

            if (cid == 0)
            {
                model = db.T_Customer.ToList();
            }
            else
            {
                model = db.T_Customer.Where(m => m.CustomerID == cid).ToList();
            }
            if (ModelState.IsValid)
            {
                try
                {
                    ObjectParameter output = new ObjectParameter("CurrentSequenceStr", typeof(string));
                    db.p_sys_GenSequence("T_Customer_CustomerID", output);
                    var result = output.Value;
                    item.CustomerID    = long.Parse(result.ToString());//主键
                    item.CustomerSysID = "sysDyl" + DateTime.Today.ToString("yyyyMMdd");
                    model.Add(item);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "请检查录入数据是否正确.";
            }
            return(PartialView("_CustomerGridViewPartial", model.ToList()));
        }