public async Task <ActionResult <BaseResponse> > Update(int Id, [FromBody] TypeUpdateViewModel req) { //var GroupId = User.Claims.FirstOrDefault(a => a.Type == "GroupId").Value; var Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value; var ret = await _ts.UpdateType(req, Account); return(ret); }
public async Task <BaseResponse> UpdateType(TypeUpdateViewModel req, string account) { var dm = await _tr.FindAsync(req.Id); if (dm == null) { return(new BaseResponse { Success = false, Message = "该类型不存在" }); } //同一部门下的子部门不能重名 var d = await _tr.Find(a => a.ParentId == dm.ParentId && a.TypeName == req.TypeName && a.GroupId == dm.GroupId).FirstOrDefaultAsync(); if (d != null && d.Id != req.Id) { return(new BaseResponse { Success = false, Message = "该组织下存在相同的类型名称" }); } try { dm.Modify = account; dm.ModifyTime = DateTime.Now; _mapper.Map(req, dm); await _tr.SaveAsync(dm); _log.LogInformation($"{account}修改Id为{req.Id}的类型名称为{req.TypeName}成功"); return(new BaseResponse { Success = true, Message = "修改类型数据成功" }); } catch (Exception ex) { _log.LogError($"{account}修改id为{req.Id}的类型名称失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}"); return(new BaseResponse { Success = false, Message = "修改类型数据失败" }); } }