public void UpdateWall(WallUpdateModel wall, string userId) { var theWall = _wallRepository.Get(wall.WallId); if (theWall != null) { if (theWall.SiteId != wall.SiteId) { throw new LynexException(string.Format("Wall {0} does not belong to Site {1}", wall.WallId, wall.SiteId)); } if (theWall.Site.UserId != userId) { throw new LynexException(string.Format("User {0} does not have permission on Wall {1}", userId, wall.WallId)); } theWall.X = wall.X; theWall.Y = wall.Y; theWall.Length = wall.Length; theWall.Angle = wall.Angle; theWall.Type = wall.Type; _wallRepository.UpdateWall(theWall); _wallRepository.Save(); } else { throw new LynexException(string.Format("Wall {0} does not exist", wall.WallId)); } }
public async Task <IActionResult> UpdateWall([FromBody] WallForUpdateDto updatedWall) { try { if (updatedWall == null) { return(BadRequest("Wall object is null")); } if (!ModelState.IsValid) // check to see if request was bound correctly { //_logger.LogError("Invalid retaining wall object sent from client request."); return(BadRequest("Invalid retaining wall object.")); } // retrieve wall from the db var wall = await _repo.GetWallByIdAsync(updatedWall.Id); // map changes to wall _mapper.Map(updatedWall, wall); // if a change was made to db if (await _repo.UpdateWall(wall)) { return(NoContent()); } return(BadRequest("Failed to update wall")); } catch (Exception ex) { return(StatusCode(500, "Internal server error" + ": " + ex.Message)); } }