public void RoleTypeSaveChanges(BasicInfoModel model) { var typeService = new RoleTypeService(); var roleauthorityService = new RoleAuthorityService(); List<role_type> types = typeService.FindAll(); foreach (role_type type in types) { int idFlag = 0; int nameFlag = 0; string newname = ""; foreach (NameModel name in model.Names) { if (type.Id == name.Id) { idFlag = 1; if (type.Name.Equals(name.Name)) { nameFlag = 1; } else { newname = name.Name; } } } //若存在此Id,但是name变化了的,则需要修改数据库 if (idFlag == 1) { if (nameFlag == 0) { if (string.IsNullOrEmpty(newname)) { throw new Exception(); } role_type modifyCure = typeService.Find(type.Id); modifyCure.Name = newname; typeService.Update(modifyCure); } } } //如果model里的Id为0,说明是新建的类型 foreach (NameModel name in model.Names) { if (name.Id == 0 && typeService.FindByName(name.Name) == null) { var newType = new role_type {Name = name.Name}; typeService.Insert(newType); for (int j = 1; j <= 19; j++) { var roleAuthority = new role_authority { RoleTypeId = typeService.FindByName(name.Name).Id, FunctionId = j, Check = true }; roleauthorityService.Insert(roleAuthority); } } } }
/// <summary> /// 获得角色类型下拉列表 /// </summary> /// <returns>返回集合</returns> public IEnumerable<SelectListItem> GetRoleTypeList() { var roleType = new RoleTypeService(); IEnumerable<SelectListItem> roleTypeSelectList = roleType.FindAll().Select(roleTypeItem => new SelectListItem { Text = roleTypeItem.Name, Value = roleTypeItem.Id + string.Empty }).OrderBy(m => m.Text); return roleTypeSelectList; }
//临时 public void update() { var f = new FunctionService(); var role = new RoleTypeService(); if (f.FindAll().Count > 21) return; var ro = new RoleAuthorityService(); f.Insert(new function() { Meno = "淘汰任务", Name = "EliminateTask" }); f.Insert(new function() { Name = "DeadTask", Meno = "死亡任务" }); f.Insert(new function() { Name = "EliminateInfo", Meno = "淘汰信息管理" }); f.Insert(new function() { Name = "DeadInfo", Meno = "死亡信息管理" }); var roletype = new RoleTypeService(); roletype.Insert(new role_type() { Name="淘汰生猪负责员" }); roletype.Insert(new role_type() { Name = "死亡生猪处理员" }); foreach (var a in role.FindAll()) { for (int i = 20; i < 24; i++) ro.Insert(new role_authority() { FunctionId = i, RoleTypeId = a.Id, Check = true }); } }