Beispiel #1
0
        public ActionResult TreeListPartialUpdate(ProjectAnalysis.Models.T_CustomerDepartment item)
        {
            List <T_CustomerDepartment> model = new List <T_CustomerDepartment>();
            var cid = Convert.ToInt32(Session["CustomerID"]);

            if (cid == 0)
            {
                model = db.T_CustomerDepartment.ToList();
            }
            else
            {
                model = db.T_CustomerDepartment.Where(m => m.CustomerID == cid).ToList();
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var modelItem = model.FirstOrDefault(it => it.CustomerDepID == item.CustomerDepID);
                    if (modelItem != null)
                    {
                        this.UpdateModel(modelItem);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            return(PartialView("_TreeListPartial", model.ToList()));
        }
Beispiel #2
0
        public ActionResult TreeListPartialAddNew(ProjectAnalysis.Models.T_CustomerDepartment item, string ParentDeps)
        {
            //var model = db.T_CustomerDepartment;
            List <T_CustomerDepartment> model = new List <T_CustomerDepartment>();
            var cid = Convert.ToInt32(Session["CustomerID"]);

            if (cid == 0)
            {
                model = db.T_CustomerDepartment.ToList();
            }
            else
            {
                model = db.T_CustomerDepartment.Where(m => m.CustomerID == cid).ToList();
            }
            if (ModelState.IsValid)
            {
                try
                {
                    ObjectParameter output = new ObjectParameter("CurrentSequenceStr", typeof(string));

                    string[] str = ParentDeps.Split(',');
                    foreach (var p in str)
                    {
                        db.p_sys_GenSequence("T_CustomerDepartment_CustomerDepID", output);
                        var result = output.Value;
                        item.CustomerDepID = long.Parse(result.ToString());//主键
                        item.ParentDep     = long.Parse(p);
                        if (cid != 0)
                        {
                            item.CustomerID = long.Parse(cid.ToString());
                        }

                        db.T_CustomerDepartment.Add(item);
                        db.SaveChanges();
                    }
                    //

                    //item.CustomerID = cid;

                    return(Content("<script>alert('保存成功');location.href='/Manage/CustomerDepartment';</script>"));
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                    return(Content("<script>alert('" + e.Message + "');history.go(-1);</script>"));
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            return(View());
        }