public async Task <ActionResult> Post([FromBody] CreateFriendDTO friend) { try { await _friendService.Post(friend); return(Accepted()); } catch (Exception e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }
public Friend CreateFriend(CreateFriendDTO createFriendDTO) { Friend friend = _mapper.Map <Friend>(createFriendDTO); friend.SinceDate = DateTime.Now; Friend foundFriend = _friends.Where(f => f.UserAccepterId == friend.UserAccepterId && f.UserRequesterId == friend.UserRequesterId).FirstOrDefault(); if (foundFriend != null) { throw new APIException("This friendship already exists!", StatusCodes.Status409Conflict); } else { _friendRepository.Add(friend); return(friend); } }
public IActionResult CreateFriend([FromBody] CreateFriendDTO createFriendDTO) { if (!ModelState.IsValid) { return(StatusCode(400, "bad data!")); } try { Friend friend = _friendService.CreateFriend(createFriendDTO); return(Ok(friend)); } catch (APIException e) { ErrorMessage error = new ErrorMessage { message = e.Message }; return(StatusCode(e.StatusCode, error)); } }
public async Task Post(CreateFriendDTO friend) { var registerCommand = _Mapper.Map <RegisterNewFriendCommand>(friend); await _Bus.SendCommand(registerCommand); }