Beispiel #1
0
        //新增修改
        public IActionResult Create(string KeyId, string PId, string PName)
        {
            sys_organization model = null;

            if (!string.IsNullOrEmpty(KeyId))
            {
                model = bll.GetModelById <sys_organization>(KeyId);
            }
            model         = model ?? new sys_organization();
            ViewBag.PId   = PId;
            ViewBag.PName = PName;
            return(View(model));
        }
Beispiel #2
0
        public JsonResult Create(sys_organization model)
        {
            ExecuteResult er   = new ExecuteResult();
            string        pids = "";

            GetPIds(ref pids, model.ParentId);
            if (string.IsNullOrEmpty(model.KeyID))
            {
                int count = bll.GetList <sys_organization>(item => item.ParentId == model.ParentId && item.FullName == model.FullName && item.IsDeleted == false).Count;
                if (count > 0)
                {
                    er.Result  = false;
                    er.Message = "同级别已存在相同项";
                }
                else
                {
                    #region 新增
                    model.KeyID      = Guid.NewGuid().ToString();
                    model.CreateDate = DateTime.Now;
                    model.IsDeleted  = false;
                    model.PIds       = pids;
                    er.Result        = bll.Insert <sys_organization>(model) > 0;
                    er.Message       = er.Result ? "新增成功" : "新增失败";
                    #endregion
                }
            }
            else
            {
                int count = bll.GetList <sys_organization>(item => item.ParentId == model.ParentId && item.FullName == model.FullName && item.KeyID != model.KeyID && item.IsDeleted == false).Count;
                if (count > 0)
                {
                    er.Result  = false;
                    er.Message = "同级别已存在相同项";
                }
                else
                {
                    #region 修改
                    var old = bll.GetModelById <sys_organization>(model.KeyID);
                    model.IsDeleted  = old.IsDeleted;
                    model.CreateDate = old.CreateDate;
                    model.PIds       = pids;
                    er.Result        = bll.Update <sys_organization>(model) > 0;
                    er.Message       = er.Result ? "编辑成功" : "编辑失败";
                    #endregion
                }
            }
            return(Json(er));
        }