/// <summary> /// 修改部门信息 /// </summary> /// <param name="info"></param> /// <returns></returns> public async Task Modify(OrganizationModifyRequest info) { using (_db) { await _db.ExecSqlNoQuery("delete Role_Organization where OrganizationId=@OrganizationId", new SqlParameter("OrganizationId", info.Id)); await _db.ExecSqlNoQuery("delete Privilege where MasterValue=@MasterValue", new SqlParameter("MasterValue", info.Id)); var organization = await _db.Organization.FindByIdAsync(info.Id); _mapper.Map(info.Organization, organization); _db.ModifyEntity(organization); await SetOtherInfo(_db, info.Id, info.ModuleIds, info.OperateIds, info.RoleIds); await _db.SaveChangesAsync(); } }
/// <summary> /// 角色信息修改 /// </summary> /// <param name="info"></param> /// <returns></returns> public async Task Save(RoleModifyRequest info) { using (_db) { if (info.Id != 0) { await _db.ExecSqlNoQuery("delete Role_User where RoleId=@RoleId", new SqlParameter("RoleId", info.Id)); await _db.ExecSqlNoQuery("delete Privilege where MasterValue=@MasterValue", new SqlParameter("MasterValue", info.Id)); Role role = await _db.Role.FindByIdAsync(info.Id); _mapper.Map(info.Role, role); //BeforeModify(role); } else { Role role = _mapper.Map <Role>(info.Role); await _db.AddAsync(role); await _db.SaveChangesAsync(); info.Id = role.Id; } foreach (int id in info.ModuleIds) { Privilege privilege = new Privilege(MasterEnum.Role, info.Id, AccessEnum.Module, id); await _db.AddAsync(privilege); } foreach (int id in info.OperateIds) { Privilege privilege = new Privilege(MasterEnum.Role, info.Id, AccessEnum.Operate, id); await _db.AddAsync(privilege); } foreach (int id in info.UserIds) { Role_User model = new Role_User(); model.UserId = id; model.RoleId = info.Id; await _db.AddAsync(model); } await _db.SaveChangesAsync(); } }
/// <summary> /// 修改用户信息 /// </summary> /// <param name="info"></param> /// <returns></returns> public async Task Modify(UserModifyRequest info) { using (_db) { await _db.ExecSqlNoQuery("delete Organization_User where UserId=@UserId", new SqlParameter("UserId", info.Id)); await _db.ExecSqlNoQuery("delete Role_User where UserId=@UserId", new SqlParameter("UserId", info.Id)); await _db.ExecSqlNoQuery("delete Privilege where MasterValue=@MasterValue", new SqlParameter("MasterValue", info.Id)); var user = await _db.User.FindByIdAsync(info.Id); _mapper.Map(info.User, user); //BeforeModify(user); await SetOtherInfo(_db, info.Id, info.User.OrganizationIds, info.ModuleIds, info.OperateIds, info.RoleIds); await _db.SaveChangesAsync(); } }