public async Task <YaeherUserRole> UpdateYaeherUserRole(YaeherUserRole YaeherUserRoleInfo) { return(await _repository.UpdateAsync(YaeherUserRoleInfo)); }
public async Task <ObjectResultModule> CreateYaeherUserRole([FromBody] YaeherUserRoleJSON YaeherUserRoleJSON) { if (!Commons.CheckSecret(YaeherUserRoleJSON.Secret)) { this.ObjectResultModule.StatusCode = 422; this.ObjectResultModule.Message = "Wrong Secret"; this.ObjectResultModule.Object = ""; return(this.ObjectResultModule); } try { var userid = _IabpSession.UserId > 0 ? (int)_IabpSession.UserId : 0; var resultId = 0; var UserID = YaeherUserRoleJSON.UserID; string[] Roles = null; if (!string.IsNullOrEmpty(YaeherUserRoleJSON.RoleID)) { Roles = YaeherUserRoleJSON.RoleID.Split(','); } #region 根据用户删除现有数据 YaeherUserRoleIn yaeherUserRoleIn = new YaeherUserRoleIn(); yaeherUserRoleIn.UserID = UserID; var query = await _yaeherUserRoleService.YaeherUserRoleList(yaeherUserRoleIn); if (query.Count() > 0) { foreach (var UserRoleInfo in query) { UserRoleInfo.DeleteBy = UserID; UserRoleInfo.DeleteTime = DateTime.Now; UserRoleInfo.IsDelete = true; var res = await _yaeherUserRoleService.DeleteYaeherUserRole(UserRoleInfo); } } #endregion #region 新增用户权限 if (Roles != null && Roles.Length > 0) { for (int a = 0; a < Roles.Length; a++) { var CreateYaeherUserRole = new YaeherUserRole() { RoleID = int.Parse(Roles[a]), UserID = UserID, CreatedBy = userid, CreatedOn = DateTime.Now }; var result = await _yaeherUserRoleService.CreateYaeherUserRole(CreateYaeherUserRole); resultId = +result.Id; } } #endregion #region 操作日志 var CreateYaeherOperList = new YaeherOperList() { OperExplain = "CreateYaeherUserRole", OperContent = JsonHelper.ToJson(YaeherUserRoleJSON), OperType = "CreateYaeherUserRole", CreatedBy = userid, CreatedOn = DateTime.Now }; var resultLog = await _yaeherOperListService.CreateYaeherOperList(CreateYaeherOperList); #endregion this.ObjectResultModule.Object = resultId; this.ObjectResultModule.StatusCode = 200; this.ObjectResultModule.Message = "success"; return(this.ObjectResultModule); } catch (Exception ex) { this.ObjectResultModule.StatusCode = 400; this.ObjectResultModule.Message = "error!"; this.ObjectResultModule.Object = ex.ToString(); return(this.ObjectResultModule); } }
public async Task <YaeherUserRole> CreateYaeherUserRole(YaeherUserRole YaeherUserRoleInfo) { YaeherUserRoleInfo.Id = await _repository.InsertAndGetIdAsync(YaeherUserRoleInfo); return(YaeherUserRoleInfo); }