public void UpdateFriendById_WhenUpdatedWithExistingId_ReturnsOkResult() { var friend = new FriendUpdateInputModel() { FirstName = "Lárus", }; var okResult = _controller.UpdateFriendById(1, friend); var result = Assert.IsType <OkObjectResult>(okResult); Assert.Equal(200, result.StatusCode); }
public FriendDto UpdateFriendById(int friendId, FriendUpdateInputModel body) { var friend = _friends.FirstOrDefault(f => f.Id == friendId); friend.FirstName = string.IsNullOrEmpty(body.FirstName) ? friend.FirstName : body.FirstName; friend.LastName = string.IsNullOrEmpty(body.LastName) ? friend.LastName : body.LastName; friend.Email = string.IsNullOrEmpty(body.Email) ? friend.Email : body.Email; friend.Phone = string.IsNullOrEmpty(body.Phone) ? friend.Phone : body.Phone; friend.Address = string.IsNullOrEmpty(body.Address) ? friend.Address : body.Address; return(new FriendDto() { FirstName = friend.FirstName, LastName = friend.LastName, Email = friend.Email, Phone = friend.Phone, Address = friend.Address }); }
public Friend UpdateFriendById(int userId, FriendUpdateInputModel body) { // Validate that given user exists var friend = _armDbContext.Friends.FirstOrDefault(f => f.Id == userId); if (friend == null) { throw new ResourceNotFoundException($"User with id: {userId} was not found"); } friend.FirstName = string.IsNullOrEmpty(body.FirstName) ? friend.FirstName : body.FirstName; friend.LastName = string.IsNullOrEmpty(body.LastName) ? friend.LastName : body.LastName; friend.Email = string.IsNullOrEmpty(body.Email) ? friend.Email : body.Email; friend.Phone = string.IsNullOrEmpty(body.Phone) ? friend.Phone : body.Phone; friend.Address = string.IsNullOrEmpty(body.Address) ? friend.Address : body.Address; _armDbContext.SaveChanges(); return(friend); }
public IActionResult UpdateFriendById(int userId, [FromBody] FriendUpdateInputModel body) { var friend = _friendService.UpdateFriendById(userId, body); return(Ok(friend)); }
public FriendDto UpdateFriendById(int friendId, FriendUpdateInputModel body) => new FriendDto(_friendRepo.UpdateFriendById(friendId, body));