Beispiel #1
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > UpdateAsync(UpdateRoleGroupRequest request)
        {
            return(await ExecuteResultAsync(async query =>
            {
                var rsp = new ApiResult <string>();
                var entity = await query.FirstOrDefaultAsync(p => p.Id == request.Id);
                if (entity == null)
                {
                    rsp.Message = "找不到要修改的信息.";
                    return rsp;
                }

                entity.Name = request.Name;
                entity.Remarks = request.Remarks;
                entity.Status = request.Status;
                // 修改
                RegisterDirty(entity);
                // 提交
                var flag = await CommitAsync();

                rsp.Message = flag ? "更新成功" : "更新失败";
                rsp.Success = flag;
                rsp.Data = entity.Id;
                return rsp;
            }));
        }
Beispiel #2
0
        public UpdateRoleGroupResponse Update(UpdateRoleGroupRequest request)
        {
            var response = new UpdateRoleGroupResponse();

            try
            {
                var roleGroup = request.MapTo <RoleGroup>();
                roleGroup.Level = DataContext.Levels.FirstOrDefault(x => x.Id == request.LevelId);
                DataContext.RoleGroups.Attach(roleGroup);
                DataContext.Entry(roleGroup).State = EntityState.Modified;
                DataContext.SaveChanges();

                response.IsSuccess = true;
                response.Message   = "User RoleGroup item has been updated successfully";
            }
            catch (DbUpdateException dbUpdateException)
            {
                response.Message = dbUpdateException.Message;
            }

            return(response);
        }
Beispiel #3
0
 public async Task <ApiResult <string> > Update([FromBody] UpdateRoleGroupRequest request)
 {
     return(await _roleGroupService.UpdateAsync(request));
 }