Exemple #1
0
        public ActionResult Save(Domain.SYS_ROLE entity)
        {
            bool isEdit = false;
            var  json   = new JsonHelper()
            {
                Msg = "保存成功", Status = "n"
            };

            try
            {
                if (entity != null)
                {
                    //判断角色名是否汉字
                    if (System.Text.RegularExpressions.Regex.IsMatch(entity.ROLENAME.Trim(), "^[\u4e00-\u9fa5]+$"))
                    {
                        if (entity.ROLENAME.Length > 36)
                        {
                            json.Msg = "角色名称最多只能能包含36个汉字";
                            return(Json(json));
                        }

                        //添加
                        if (entity.ID <= 0)
                        {
                            entity.CREATEDATE  = DateTime.Now;
                            entity.CREATEPERID = this.CurrentUser.Name;
                            entity.UPDATEDATE  = DateTime.Now;
                            entity.UPDATEUSER  = this.CurrentUser.Name;
                        }
                        else //修改
                        {
                            entity.UPDATEDATE = DateTime.Now;
                            entity.UPDATEUSER = this.CurrentUser.Name;
                            isEdit            = true;
                        }
                        //判断角色是否重名
                        if (!this.RoleManage.IsExist(p => p.ROLENAME == entity.ROLENAME && p.ID != entity.ID))
                        {
                            if (isEdit)
                            {
                                //系统更换 删除所有权限
                                var _entity = RoleManage.Get(p => p.ID == entity.ID);
                                if (_entity.FK_BELONGSYSTEM != entity.FK_BELONGSYSTEM)
                                {
                                    RolePermissionManage.Delete(p => p.ROLEID == _entity.ID);
                                }
                            }
                            if (RoleManage.SaveOrUpdate(entity, isEdit))
                            {
                                json.Status = "y";
                            }
                            else
                            {
                                json.Msg = "保存失败";
                            }
                        }
                        else
                        {
                            json.Msg = "角色名" + entity.ROLENAME + "已被使用,请修改角色名称再提交";
                        }
                    }
                    else
                    {
                        json.Msg = "角色名称只能包含汉字";
                    }
                }
                else
                {
                    json.Msg = "未找到需要保存的角色信息";
                }
                if (isEdit)
                {
                    WriteLog(Common.Enums.enumOperator.Edit, "修改用户角色,结果:" + json.Msg, Common.Enums.enumLog4net.INFO);
                }
                else
                {
                    WriteLog(Common.Enums.enumOperator.Add, "添加用户角色,结果:" + json.Msg, Common.Enums.enumLog4net.INFO);
                }
            }
            catch (Exception e)
            {
                json.Msg = "保存用户角色发生内部错误!";
                WriteLog(Common.Enums.enumOperator.None, "保存用户角色:", e);
            }
            return(Json(json));
        }
Exemple #2
0
 public static List <RoleInfo> List()
 {
     return(RoleManage.List());
 }
 public PersonalCenterController(MenuManage menuManage, RoleManage roleManage)
 {
     _menuManage = menuManage;
     _roleManage = roleManage;
 }
Exemple #4
0
 public RoleAppService(RoleManage roleManage)
 {
     _roleManage = roleManage;
 }
 /// <summary>
 ///     构造函数
 /// </summary>
 public ManagerAppService(ManagerMange managerManage, RoleManage roleManage, UserBaseManage userBaseManage)
 {
     _managerManage  = managerManage;
     _roleManage     = roleManage;
     _userBaseManage = userBaseManage;
 }
Exemple #6
0
 public MenuAppService(MenuManage menuManage, RoleManage roleManage)
 {
     _menuManage = menuManage;
     _roleManage = roleManage;
 }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                //check the code
                var  db   = new JustFoodDBEntities();
                Code code = db.Codes.FirstOrDefault(m => m.Code1 == model.Code);
                if (code == null)
                {
                    ModelState.AddModelError(model.Code, "Your given code is not valid.");
                    return(View(model));
                }


                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);

                    //create new user.
                    if (code.Percentage == null)
                    {
                        code.Percentage = 0;
                    }
                    if (code.Salary == null)
                    {
                        code.Salary = 0;
                    }

                    var user = new User {
                        LogName         = model.UserName,
                        Name            = model.PersonName,
                        IsEmployee      = code.IsEmployee,
                        IsOwner         = code.IsOwner,
                        IsAccessToAdmin = code.IsAccessToAdmin,
                        Percentage      = (double)code.Percentage,
                        Salary          = (double)code.Salary,
                        Email           = model.Email,
                        IsValidEmail    = true
                    };
                    //there is no need to keep the used code.
                    db.Entry(code).State = EntityState.Deleted;
                    db.Users.Add(user);
                    db.SaveChanges();
                    //Roles.CreateRole("");
                    var    roleManager = new RoleManage();
                    string role        = "";
                    if (user.IsAccessToAdmin)
                    {
                        role = RoleNames.Admin;
                    }
                    else if (user.IsEmployee)
                    {
                        role = RoleNames.SalesMan;
                    }
                    roleManager.AddRole(user.LogName, role);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }