Beispiel #1
0
        public ActionResult Create(SysUser model, string SysRolesID)
        {
            SysUser u = model;

            u.ID        = IdentityCreator.NextIdentity;
            u.AddBy     = cuser.UserID;
            u.AddByName = cuser.LoginName;
            u.AddDate   = DateTime.Now;
            if (!userService.Exist(user => user.LoginName == model.LoginName))
            {
                var dep = depService.Find(u.SysDepID);
                if (dep != null)
                {
                    u.SysDepName = dep.Name;
                    userService.Add(u);
                    if (userService.SaveChanges(out msg) > 0)
                    {
                        if (roleBll.SetUserRoles(model.ID, SysRolesID, out msg))
                        {
                            return(Json(new AjaxResult()
                            {
                                success = true, msg = insertSuccess, url = Url.Action("Index"), moremsg = msg
                            }));
                        }
                        else
                        {
                            return(Json(new AjaxResult()
                            {
                                success = false, msg = msg
                            }));
                        }
                    }
                    else
                    {
                        msg = errorOutPutToPage ? msg : insertFailure;
                        return(Json(new AjaxResult()
                        {
                            success = false, msg = msg
                        }));
                    }
                }
                else
                {
                    return(Json(new AjaxResult()
                    {
                        success = false, msg = "未找到对应的部门"
                    }));
                }
            }
            else
            {
                return(Json(new AjaxResult()
                {
                    success = false, msg = "登录名已存在"
                }));
            }
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "ParentID,IsAvailable,IsDel,Name,SortNo")] SysDep model)
        {
            model.ID        = IdentityCreator.NextIdentity;
            model.AddBy     = cuser.UserID;
            model.AddByName = cuser.LoginName;
            model.AddDate   = DateTime.Now;
            model.IsDel     = false;
            if (string.IsNullOrEmpty(Request["SortNo"]))
            {
                model.SortNo = 0;
            }
            var parentDep = depService.Find(model.ParentID);

            if (parentDep != null)
            {
                model.ParentName      = parentDep == null ? null : parentDep.Name;
                model.DepFullIDPath   = parentDep.DepFullIDPath + model.ID + "/";
                model.DepFullNamePath = parentDep.DepFullNamePath + model.Name + "/";
                depService.Add(model);
                if (depService.SaveChanges(out msg) > 0)
                {
                    return(Json(new AjaxResult()
                    {
                        success = true, msg = insertSuccess, url = Url.Action("treeindex", "sysdep", "admin"), moremsg = msg
                    }));
                }
                else
                {
                    return(Json(new AjaxResult()
                    {
                        success = false, msg = insertFailure, moremsg = msg
                    }));
                }
            }
            else
            {
                return(Json(new AjaxResult()
                {
                    success = false, msg = insertFailure, moremsg = "未找到上级组织"
                }));
            }
        }