private void ValidateFriendInput(FriendInput friendInput) { if (friendInput == null) { throw new InvalidInputException(InvalidFriendInputMessage); } if (String.IsNullOrEmpty(friendInput.Name)) { throw new InvalidInputException(EmptyFriendNameMessage); } }
public async Task <ActionResult <FriendOutput> > PostAsync([FromBody] FriendInput FriendInput) { try { var FriendOutput = await FriendUsecase.CreateAsync(FriendInput); return(StatusCode(StatusCodes.Status201Created, FriendOutput)); } catch (FriendUsecaseException exception) { return(BadRequest(exception.Message)); } }
public async Task <IActionResult> PostFriends([FromRoute] int id, [FromBody] FriendInput friendInput) { try { var friend = await _friendAppService .InsertAsync(id, friendInput) .ConfigureAwait(false); return(Created("", friend)); } catch (ArgumentException arg) { return(BadRequest(arg.Message)); } }
public async Task <Friends> InsertAsync(int friendId, FriendInput input) { var clientId = _logged.GetClientLoggedId(); var friend = new Friends(clientId, friendId); //Validar os dados obrigatorios var id = await _friendRepository .InsertAsync(friend) .ConfigureAwait(false); friend.SetId(id); return(friend); }
public async Task <ActionResult> PutAsync(int id, [FromBody] FriendInput FriendInput) { try { await FriendUsecase.UpdateAsync(id, FriendInput); return(NoContent()); } catch (NotFoundException exception) { return(NotFound(exception.Message)); } catch (FriendUsecaseException exception) { return(BadRequest(exception.Message)); } }
public async Task UpdateAsync(int id, FriendInput friendInput) { try { ValidateFriendInput(friendInput); var friend = await repository.FindAsync(id); if (friend == null) { throw new NotFoundException(String.Format(FriendNotFoundMessage, id)); } friend.Name = friendInput.Name; await repository.UpdateAsync(id, friend); } catch (Exception exception) { throw new FriendUsecaseException(FailureUpdatingFriendDataMessage, exception); } }
public async Task <FriendOutput> CreateAsync(FriendInput friendInput) { try { ValidateFriendInput(friendInput); var friend = new Friend { Name = friendInput.Name }; await repository.CreateAsync(friend); var friendOutput = presenter.ToOutput(friend); return(friendOutput); } catch (Exception exception) { throw new FriendUsecaseException(FailureCreatingFriendDataMessage, exception); } }