public IActionResult RegionUpdate(int id, [FromBody] RegionUpdateDto updateRegion) { var regionEntity = _transActionRepo.GetRegion(id); if (regionEntity == null) { return(NotFound()); } if (updateRegion == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Mapper.Map(updateRegion, regionEntity); if (!_transActionRepo.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } return(NoContent()); }
public ActionResult UpdateRegion(Guid id, RegionUpdateDto regionUpdateDto) { var existingdata = _repo.GetRegionById(id); if (existingdata == null) { return(NotFound()); } _mapper.Map(regionUpdateDto, existingdata); _repo.UpdateRegion(existingdata); _repo.SaveChanges(); return(NoContent()); }
public IActionResult UpdateRegion(int id, [FromBody] RegionUpdateDto updateRegion) { if (!ModelState.IsValid) { return(BadRequest(new TransActionResponse(ModelState))); } var regionEntity = _unitOfWork.Region.GetRegionById(id); if (regionEntity == null) { return(StatusCode(404, new TransActionResponse("Region Not Found"))); } _unitOfWork.Region.Update(regionEntity); if (!_unitOfWork.Save()) { return(StatusCode(500, new TransActionResponse("A problem happened while handling your request."))); } return(StatusCode(StatusCodes.Status204NoContent, new TransActionResponse())); }
public async Task <BaseResponse> UpdateRegionAsync(string account, string GroupId, RegionUpdateDto req) { var data = await _rr.FindAsync(req.Id, GroupId); if (data == null) { return(new BaseResponse { Success = false, Message = "输入的区域标示不存在" }); } //检测是否重名 var d = await _rr.Find(a => a.ParentId == data.ParentId && a.GroupId == GroupId && a.Name == req.Name && a.Id != req.Id).FirstOrDefaultAsync(); if (d != null) { return(new BaseResponse { Success = false, Message = "修改区域信息失败,区域名称重复" }); } try { var dto = _mapper.Map(req, data); dto.Modify = account; dto.ModifyTime = DateTime.Now; await _rr.SaveAsync(dto); _log.LogInformation($"{account}修改标示为{new { Id = req.Id, GroupId = GroupId }}的区域成功"); return new BaseResponse { Success = true, Message = "修改区域信息成功" }; } catch (Exception ex) { _log.LogError($"{account}修改标示为{new { Id = req.Id, GroupId = GroupId }}的区域失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}"); return(new BaseResponse { Success = false, Message = "修改区域失败,请联系管理员" }); } }
public async Task <ActionResult <BaseResponse> > RegionUpdate(string GroupId, RegionUpdateDto req) { //管理员权限 //var GId = User.Claims.FirstOrDefault(a => a.Type == "GroupId").Value; //var isAdmin = User.Claims.FirstOrDefault(a => a.Type == "IsAdmin").Value.ToLower() == "true" ? true : false; string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value; //if (!isAdmin) //{ // return Unauthorized("用户没有权限编辑区域"); //} var rm = await _rs.UpdateRegionAsync(Account, GroupId, req); return(rm); }