public UserModule(IUserService _userService, ISiteService _siteService, IRoleService _roleService, IUserRoleMappingService _userRoleMappingService) : base("/user") { UserValidator uservalidator = new UserValidator(); Get["/list"] = x => { return View["User/List",_userService.GetAllUser()]; }; Get["/add"] = x => { ViewBag.Errored = false; return View["User/Add", new User()]; }; Post["/add"] = x => { User user = this.Bind<User>(); ValidationResult results = uservalidator.Validate(user); if (!results.IsValid) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error,"错误信息", results.Errors); ViewBag.Errored = true; return View["User/Add", user]; } if (_userService.CreateUser(user)) { ViewBag.ErrorMsg = "<strong>OK~</strong>"; ViewBag.Errored = true; return View["User/Add", user]; } ViewBag.ErrorMsg = "<strong>出错啦~</strong>"; ViewBag.Errored = true; return View["User/Add", user]; //return this.Context.GetRedirect("~/user/add?error=true"); //return View["User/Add"]; }; Get["/edit/{id}"] = x => { return View["User/Edit", _userService.GetByAutoId((int)x.id)]; }; Post["/edit/{id}"] = x => { ViewBag.Errored = true; var user = this.Bind<User>(); var model = _userService.GetById(user.ID); if (!String.IsNullOrEmpty(user.Password)) { model.PasswordSalt = PasswordUtil.GenerateSalt(); model.Password = PasswordUtil.EncodePassword(user.Password, model.PasswordFormat, model.PasswordSalt); model.passwordConfirm = PasswordUtil.EncodePassword(user.passwordConfirm, model.PasswordFormat, model.PasswordSalt); } else { model.passwordConfirm = model.Password; } model.PrivateEmail = user.PrivateEmail; model.Nickname = user.Nickname; model.Gender = user.Gender; model.Status = user.Status; ValidationResult results = uservalidator.Validate(model); if (!results.IsValid) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", results.Errors); return View["User/Edit", user]; } if (user.ID == Guid.Empty) { return Response.AsRedirect("/user/list"); } if (_userService.ModifyUser(model)) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.success, "成功信息", "修改用户信息成功"); } else { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", "未知错误,请联系管理员"); } return View["User/Edit", user]; }; Get["/delete/{id}"] = x => { var model = _userService.GetByAutoId((int)x.id); _userService.DeleteUser(model.ID); return Response.AsRedirect("/user/list"); }; Get["/editrole"] = x => { Guid userId = new Guid(Request.Query.userId); dynamic SiteId = null; SiteId = !String.IsNullOrEmpty(Request.Query.siteId.ToString()) && Request.Query.siteId != null ? new Guid(Request.Query.siteId) : Guid.Empty; var usermodel = _userService.GetById(userId); ViewBag.UserName = usermodel.UserName; ViewBag.UserId = usermodel.ID; ViewBag.SiteId = SiteId; ViewBag.SiteList = _siteService.GetAllSite(); List<Role> siteRoles = _roleService.GetAllBySiteId(SiteId); List<Role> rightRoles = _roleService.GetAllBySiteIdAndUserId(SiteId, userId); ViewBag.NoSystemRoles = (SiteId != Guid.Empty && siteRoles.Count == 0); var leftRoles = (from p in siteRoles where !rightRoles.Exists(r => r.ID == p.ID) select p).ToList(); ViewBag.LeftRoles = leftRoles; ViewBag.RightRoles = rightRoles; return View["User/EditRole"]; }; Post["/saverole"] = x => { var result = new NotyResult(); Guid userId = new Guid(Request.Form.userId); dynamic SiteId = null; SiteId = !String.IsNullOrEmpty(Request.Form.siteId.ToString()) && Request.Form.siteId != null ? new Guid(Request.Form.siteId) : Guid.Empty; Guid[] ids = RequestResultUtil.GetIdsByGuid(Request.Form.ids); var list = (ids ?? new Guid[0]); if (SiteId == Guid.Empty) { result.code = NotyType.warning.ToString(); result.msg = "你没有选择站点!"; } else { List<Role> rightRoles = _roleService.GetAllBySiteIdAndUserId(SiteId, userId); bool changed = false; bool success = false; List<object> added = new List<object>(); List<object> removed = new List<object>(); // 处理加角色的情况 foreach (Guid roleId in list) { if (!rightRoles.Exists(r=>r.ID == roleId)) { changed = true; success = _userRoleMappingService.CreateUserRoleMapping(userId, roleId); added.Add(new { userId = userId, siteId = SiteId, roleId = roleId }); } } // 处理减角色的情况 foreach (Role role in rightRoles) { if (!list.ToList().Exists(r=>r == role.ID)) { changed = true; success = _userRoleMappingService.DeleteByUserIdAndRoleId(userId, role.ID); removed.Add(new { userId = userId, siteId = SiteId, roleId = role.ID }); } } if (!changed || (changed && success)) { result.code = NotyType.success.ToString(); result.msg = "保存成功!"; } else { result.code = NotyType.error.ToString(); result.msg = "保存失败!请联系管理员!"; } } //if (list.Length == 0) //{ // result.code = NotyType.warning.ToString(); // result.msg = "你没有选择!"; //} //else //{ // result.code = NotyType.success.ToString(); // result.msg = "排序成功"; //} //else //{ // result.code = NotyType.error.ToString(); // result.msg = "排序失败!请联系管理员!"; //} return this.Response.AsJson<NotyResult>(result); }; }
public SiteModule(ISiteService _siteService) : base("/site") { SiteValidator sitevalidator = new SiteValidator(); Get["/list"] = x => { return View["Site/List",_siteService.GetAllSite()]; }; Get["/add"] = x => { return View["Site/Add",new Site()]; }; Post["/add"] = x => { var site = this.Bind<Site>(); ViewBag.Errored = true; ValidationResult results = sitevalidator.Validate(site); if (!results.IsValid) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", results.Errors); } else if (_siteService.CreateSite(site)) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.success, "成功信息","添加网站成功"); } else { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", "未知错误,请联系管理员"); } return View["Site/Add",site]; }; Get["/edit/{id}"] = x => { var model = _siteService.GetSite((int)x.id); return View["Site/Edit", model]; }; Post["/edit/{id}"] = x => { var site = this.Bind<Site>(); ViewBag.Errored = true; ValidationResult results = sitevalidator.Validate(site); if (!results.IsValid) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", results.Errors); } else if (_siteService.ModifySite(site)) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.success, "成功信息", "修改网站成功"); } else { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", "未知错误,请联系管理员"); } return View["Site/Edit", site]; }; Get["/delete/{id}"] = x => { _siteService.DeleteSite((int)x.id); return Response.AsRedirect("/site/list"); }; Get["/editdomain/{id}"] = x => { var model = _siteService.GetSite((int)x.id); return View["Site/EditDomain", model]; }; Post["/adddomain"] = x => { var domainName = Request.Form.domain.ToString(); var id = new Guid(Request.Form.id.ToString()); var result = new NotyResult(); if (String.IsNullOrEmpty(domainName)) { result.code = NotyType.warning.ToString(); result.msg = "域名不能为空!"; } else if (!_siteService.IsDomainOnly(id,domainName)) { result.code = NotyType.warning.ToString(); result.msg = "域名已存在!"; } else if (_siteService.AddDomain(id,domainName)) { result.code = NotyType.success.ToString(); result.msg = "添加成功"; } else { result.code = NotyType.error.ToString(); result.msg = "添加失败!请联系管理员!"; } return this.Response.AsJson<NotyResult>(result); }; }
public RoleModule(ISiteService _siteService, IRoleService _roleService) : base("/role") { RoleValidator roleValidator = new RoleValidator(); Get["/list"] = x => { ViewBag.SiteId = Request.Query.siteId; ViewBag.SiteList = _siteService.GetAllSite(); if (!String.IsNullOrEmpty(Request.Query.siteId)) { return View["Role/List", _roleService.GetAllBySiteId(new Guid(Request.Query.siteId))]; } else { return View["Role/List",new List<Role>()]; } }; Get["/add"] = x => { ViewBag.SiteId = Request.Query.siteId; ViewBag.SiteList = _siteService.GetAllSite(); return View["Role/Add", new Role()]; }; Post["/add"] = x => { ViewBag.SiteId = Request.Query.siteId; ViewBag.SiteList = _siteService.GetAllSite(); ViewBag.Errored = true; var role = this.Bind<Role>(); ValidationResult results = roleValidator.Validate(role); if (!results.IsValid) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", results.Errors); } else if (_roleService.CreateRole(role)) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.success, "成功信息", "添加成功"); } else { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", "未知错误,请联系管理员"); } return View["Role/Add", role]; }; Get["/edit/{id}"] = x => { ViewBag.SiteList = _siteService.GetAllSite(); var model = _roleService.GetByAutoId(x.id); return View["Role/Edit", model]; }; Post["/edit/{id}"] = x => { ViewBag.SiteList = _siteService.GetAllSite(); ViewBag.Errored = true; var role = this.Bind<Role>(); ValidationResult results = roleValidator.Validate(role); if (!results.IsValid) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", results.Errors); } else if (_roleService.ModifyRole(role)) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.success, "成功信息", "修改成功"); } else { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", "未知错误,请联系管理员"); } return View["Role/Edit", role]; }; Get["/delete/{id}"] = x => { var model = _roleService.GetByAutoId((int)x.id); _roleService.DeleteRole(model.ID); return Response.AsRedirect("/role/list?siteId=" + model.ID.ToString()); }; Post["/delete"] = x => { var result = new NotyResult(); Guid[] ids; try { ids = RequestResultUtil.GetIdsByGuid(Request.Form.id); } catch { Guid strongid = new Guid(Request.Form.id); ids = new Guid[1]; ids[0] = strongid; } var list = (ids ?? new Guid[0]); if (list.Length == 0) { result.code = NotyType.warning.ToString(); result.msg = "你没有选择!"; } else if (_roleService.DeleteByIds(ids)) { result.code = NotyType.success.ToString(); result.msg = "删除成功!"; } else { result.code = NotyType.error.ToString(); result.msg = "删除失败!请联系管理员!"; } return this.Response.AsJson<NotyResult>(result); }; Get["/vieworder"] = x => { var id = new Guid(Request.Query.siteId); return View["Role/ViewOrder", _roleService.GetAllBySiteId(id)]; }; Post["/saveorder"] = x => { var result = new NotyResult(); Guid[] ids = RequestResultUtil.GetIdsByGuid(Request.Form.ids); var list = (ids ?? new Guid[0]); if (list.Length == 0) { result.code = NotyType.warning.ToString(); result.msg = "你没有选择!"; } else if (_roleService.SetOrderByIds(ids)) { result.code = NotyType.success.ToString(); result.msg = "排序成功"; } else { result.code = NotyType.error.ToString(); result.msg = "排序失败!请联系管理员!"; } return this.Response.AsJson<NotyResult>(result); }; }
public PermissionModule(ISiteService _siteService, IPermissionGroupService _permissionGroupService, IMiscService _miscService, IPermissionItemService _permissionItemService) : base("/permission") { PermissionGroupValidator permissionGroupValidator = new PermissionGroupValidator(); PermissionItemValidator permissionItemValidator = new PermissionItemValidator(); Get["/list"] = x => { ViewBag.SiteId = Request.Query.siteId; ViewBag.SiteList = _siteService.GetAllSite(); Guid siteid; if (!String.IsNullOrEmpty(Request.Query.siteId)) { siteid = new Guid(Request.Query.siteId); } else { siteid = new Guid(); } return View["Permission/List", _miscService.GetPermissionGroupItemsBySiteId(siteid)]; }; Get["/addgroup"] = x => { ViewBag.SiteId = Request.Query.siteId; ViewBag.SiteList = _siteService.GetAllSite(); return View["Permission/AddGroup", new PermissionGroup()]; }; Post["/addgroup"] = x => { ViewBag.Errored = true; var permissiongroup = this.Bind<PermissionGroup>(); ViewBag.SiteId = Request.Query.siteId; ViewBag.SiteList = _siteService.GetAllSite(); ValidationResult results = permissionGroupValidator.Validate(permissiongroup); if (!results.IsValid) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", results.Errors); } else if (_permissionGroupService.CreatePermissionGroup(permissiongroup)) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.success, "成功信息", "添加成功"); } else { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", "未知错误,请联系管理员"); } return View["Permission/AddGroup", permissiongroup]; }; Get["/additem"] = x => { var permissiongroupid = Request.Query.permissiongroupid; var siteid = Request.Query.siteid; ViewBag.SiteId = siteid; ViewBag.PermissionGroupId = permissiongroupid; ViewBag.SiteName = _siteService.GetSite(new Guid(siteid)).SiteName; ViewBag.PermissionGroupList = _permissionGroupService.GetAllBySiteId(new Guid(siteid)); return View["Permission/AddItem", new PermissionItem()]; }; Post["/additem"] = x => { var permissiongroupid = Request.Query.permissiongroupid; var siteid = Request.Query.siteid; ViewBag.SiteId = siteid; ViewBag.Errored = true; ViewBag.PermissionGroupId = permissiongroupid; ViewBag.SiteName = _siteService.GetSite(new Guid(siteid)).SiteName; ViewBag.PermissionGroupList = _permissionGroupService.GetAllBySiteId(new Guid(siteid)); var permissionitem = this.Bind<PermissionItem>(); ValidationResult results = permissionItemValidator.Validate(permissionitem); if (!results.IsValid) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", results.Errors); } else if (_permissionItemService.CreatePermissionItem(permissionitem)) { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.success, "成功信息", "添加成功"); } else { ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", "未知错误,请联系管理员"); } return View["Permission/AddItem", permissionitem]; }; Post["/deleteitem"] = x => { var result = new NotyResult(); Guid[] ids; try { ids = RequestResultUtil.GetIdsByGuid(Request.Form.id); } catch { Guid strongid = new Guid(Request.Form.id); ids = new Guid[1]; ids[0] = strongid; } var list = (ids ?? new Guid[0]); if (list.Length == 0) { result.code = NotyType.warning.ToString(); result.msg = "你没有选择!"; } else { try { _permissionItemService.DeletePermissionItem(ids); result.code = NotyType.success.ToString(); result.msg = "删除成功!"; } catch { result.code = NotyType.error.ToString(); result.msg = "删除失败!请联系管理员!"; } } return this.Response.AsJson<NotyResult>(result); }; Post["/deletegroup"] = x => { var result = new NotyResult(); dynamic id = new Guid(Request.Form.id); id = id ?? new Guid(); if (id == new Guid()) { result.code = NotyType.warning.ToString(); result.msg = "你没有选择!"; } else { try { _permissionGroupService.DeletePermissionGroup(id); result.code = NotyType.success.ToString(); result.msg = "删除成功!"; } catch { result.code = NotyType.error.ToString(); result.msg = "删除失败!请联系管理员!"; } } return this.Response.AsJson<NotyResult>(result); }; Get["/viewgrouporder"] = x => { var id = new Guid(Request.Query.siteId); return View["Permission/ViewGroupOrder", _permissionGroupService.GetAllBySiteId(id)]; }; Get["/viewitemorder"] = x => { var id = new Guid(Request.Query.permissionGroupId); return View["Permission/ViewItemOrder", _permissionItemService.GetAllByPermissionGroupId(id)]; }; Post["/savegrouporder"] = x => { var result = new NotyResult(); Guid[] ids = RequestResultUtil.GetIdsByGuid(Request.Form.ids); var list = (ids ?? new Guid[0]); if (list.Length == 0) { result.code = NotyType.warning.ToString(); result.msg = "你没有选择!"; } else if (_permissionGroupService.SetOrderByIds(ids)) { result.code = NotyType.success.ToString(); result.msg = "排序成功"; } else { result.code = NotyType.error.ToString(); result.msg = "排序失败!请联系管理员!"; } return this.Response.AsJson<NotyResult>(result); }; Post["/saveitemorder"] = x => { var result = new NotyResult(); Guid[] ids = RequestResultUtil.GetIdsByGuid(Request.Form.ids); var list = (ids ?? new Guid[0]); if (list.Length == 0) { result.code = NotyType.warning.ToString(); result.msg = "你没有选择!"; } else if (_permissionItemService.SetOrderByIds(ids)) { result.code = NotyType.success.ToString(); result.msg = "排序成功"; } else { result.code = NotyType.error.ToString(); result.msg = "排序失败!请联系管理员!"; } return this.Response.AsJson<NotyResult>(result); }; Post["/editgroup"] = x => { var result = new NotyResult(); var id = new Guid(Request.Form.id); var name = Request.Form.name; if (_permissionGroupService.ModifyPermissionGroup(id,name)) { result.code = NotyType.success.ToString(); result.msg = "修改成功"; } else { result.code = NotyType.error.ToString(); result.msg = "修改失败!请联系管理员!"; } return this.Response.AsJson<NotyResult>(result); }; }