예제 #1
0
        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));
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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));
            }
        }
예제 #4
0
 public async Task Post(CreateFriendDTO friend)
 {
     var registerCommand = _Mapper.Map <RegisterNewFriendCommand>(friend);
     await _Bus.SendCommand(registerCommand);
 }