public async Task AddFriend(Guid currentUserId,
                                    string currentUserEmail,
                                    string friendEmail)
        {
            if (currentUserEmail == friendEmail)
            {
                throw new AddYourSelfAsFriendException("Can't add your self ass friend");
            }

            var currentUserFriendsList = _friendRepository.ListFriendsOfUser(currentUserId);

            if (currentUserFriendsList.FirstOrDefault(f => f.Email == friendEmail) != null)
            {
                throw new AlreadyFriendWithThisUserException("You are already friend with this user");
            }

            var friendToAdd = await this._profileRepository.GetUser(currentUserId);

            if (friendToAdd == null)
            {
                throw new NoSuchUserException("No Such User");
            }

            //TODO: Something is not right here!!
            if (friendToAdd.Friends.FirstOrDefault(f => f.Email == currentUserEmail) != null)
            {
                throw new AlreadyFriendWithThisUserException("You are already friend with this user");
            }

            _friendRepository.Create(friendEmail, currentUserId);
        }
        public ActionResult <FriendReadDto> Create([FromBody] FriendCreateDto request)
        {
            FriendList friendList = _friendListRepository.Get(request.FriendListId);

            if (friendList == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Friend list doesn't exist."));
            }

            if (friendList.Friends.Any(e => e.Id == request.FriendUserId))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "You already addes this User as your Friend."));
            }

            if (friendList.OwnerUserId == request.FriendUserId)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "You cannot add yourself as a Friend."));
            }

            if (_userRepository.Get(request.FriendUserId) == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "User doesn't exist."));
            }

            Friend newEntity = _mapper.Map <Friend>(request);

            newEntity.DateTime = DateTime.UtcNow;

            newEntity = _friendRepository.Create(newEntity);

            return(StatusCode(StatusCodes.Status201Created, _mapper.Map <FriendReadDto>(newEntity)));
        }
        public void AddFriend(User user, User friend)
        {
            var entity = new FriendEntity
            {
                user_id   = user.Id,
                friend_id = friend.Id
            };

            if (friendRepo.Create(entity) == 0)
            {
                throw new Exception();
            }
        }
Esempio n. 4
0
        public ValidationResult Create(FriendViewModel game)
        {
            var friendEntity = _mapper.Map <Friend>(game);

            _friendValidation.BaseValidation();
            var validation = _friendValidation.Validate(friendEntity);

            if (validation.IsValid)
            {
                _friendRepository.BeginTransaction();
                _friendRepository.Create(friendEntity);
                _friendRepository.Commit();
            }

            return(validation);
        }
Esempio n. 5
0
        public void Add(FriendViewModel viewModel)
        {
            var friend = new FriendAdapter().ViewModelToFriend(viewModel);

            _friendRepository.Create(friend);
        }
Esempio n. 6
0
        public async Task <ActionResult <Friend> > Post([FromBody] Friend friend)
        {
            await _repo.Create(friend);

            return(new OkObjectResult(friend));
        }
Esempio n. 7
0
        public void AddFriend(Guid currentUserId, string currentUserEmail, string currentUserName, string friendEmail)
        {
            _friendRepository.Create(currentUserId, friendEmail);

            _notificationService.SendNotification(currentUserEmail, currentUserName, friendEmail);
        }