public AddFriendCommandResult Handler(AddFriendCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new AddFriendCommandResult(false, false, command.Notifications.ToList()));
            }

            if (friendRepository.LocationAlreadyExists(Latitude: command.Latitude, Longitude: command.Longitude))
            {
                AddNotification("Location", "Já existe um amigo cadastrado nesta localização.");
            }

            if (Invalid)
            {
                return(new AddFriendCommandResult(false, false, Notifications.ToList()));
            }

            var friend = new Friend(command.Name, new Point(command.Latitude, command.Longitude));

            AddNotifications(friend);

            if (Invalid)
            {
                return(new AddFriendCommandResult(false, false, Notifications.ToList()));
            }

            friendRepository.Add(friend);

            return(new AddFriendCommandResult(true, true, new Message()
            {
                MessageType = MessageType.Information, Description = "Amigo cadastrado com sucesso!"
            }));
        }
Esempio n. 2
0
        public void Populate()
        {
            try
            {
                var friends = new List <Friend>();
                for (int i = 0; i < new Random().Next(10, 20); i++)
                {
                    friends.Add(new Friend()
                    {
                        Name    = string.Format("Amigo_{0}", i),
                        Address = new Address()
                        {
                            Street   = string.Format("Rua {0}", i),
                            Number   = i.ToString(),
                            Location = new Location()
                            {
                                Latitude  = ((float)new Random().NextDouble() * 10.0),
                                Longitude = ((float)new Random().NextDouble() * 10.0)
                            }
                        }
                    });
                }

                foreach (var f in friends)
                {
                    _friendRepository.Add(f);
                }

                Assert.IsTrue(true);
            }
            catch (Exception ex)
            {
                Assert.Fail();
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> LikeUser(int id, int recipientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var like = await _repository.GetLike(id, recipientId);

            if (like != null)
            {
                return(BadRequest("You already like this user"));
            }

            if (await _repository.GetUser(recipientId, false) == null)
            {
                return(NotFound());
            }

            like = new Like
            {
                LikerId = id,
                LikeeId = recipientId
            };

            _repository.Add <Like>(like);

            if (await _repository.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to like user"));
        }
        private Friend CreateNewFriend()
        {
            var friend = new Friend();

            _dataService.Add(friend);
            return(friend);
        }
Esempio n. 5
0
        public async Task <IActionResult> CreateMessage(int userId, MessageForCreationDto messageForCreationDto)
        {
            var sender = await _repo.GetUser(userId);

            if (sender.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            messageForCreationDto.MessageSenderId = userId;

            var recipient = await _repo.GetUser(messageForCreationDto.MessageRecipientId);

            if (recipient == null)
            {
                return(BadRequest("Could not find user"));
            }

            var message = _mapper.Map <Message>(messageForCreationDto);

            _repo.Add(message);

            if (await _repo.SaveAll())
            {
                var messageToReturn = _mapper.Map <MessageToReturnDto>(message);
                return(CreatedAtRoute("GetMessage", new { id = message.Id }, messageToReturn));
            }

            throw new Exception("Creating the message failed on save.");
        }
 public IActionResult AddFriend(AddFriendViewodel friendmodel)
 {
     if (ModelState.IsValid)
     {
         ApplicationUser existfriend = context.AspNetUsers.SingleOrDefault <ApplicationUser>(u => u.PhoneNumber == friendmodel.mobileno);
         //Console.WriteLine(existfriend);
         string msg = "";
         if (existfriend == null)
         {
             ApplicationUser appuser = context.AspNetUsers.SingleOrDefault <ApplicationUser>(u => u.Id == friendmodel.UserId);
             friendmodel.user = appuser;
             msg             = "Friend does not register on this website, so invite him using";
             ViewData["err"] = msg;
             return(View(friendmodel));
         }
         else
         {
             friend f = new friend
             {
                 fname    = friendmodel.fname,
                 mobileno = friendmodel.mobileno,
                 userID   = friendmodel.UserId
             };
             friendRepository.Add(f);
             return(Redirect("/home/home/" + friendmodel.UserId));
         }
     }
     return(View());
 }
Esempio n. 7
0
        public async Task <IActionResult> RequestUser(int id, int recipientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var request = await _repo.GetRequest(id, recipientId);

            if (request != null)
            {
                return(BadRequest("You already send request to this user"));
            }

            if (await _repo.GetUser(recipientId) == null)
            {
                return(NotFound());
            }

            request = new Request
            {
                SenderId   = id,
                ReceiverId = recipientId
            };

            _repo.Add <Request>(request);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to Send friend request"));
        }
        private Friend CreateNewFriend()
        {
            var friend = new Friend();

            _friendRepository.Add(friend);
            return(friend);
        }
Esempio n. 9
0
        public async Task <bool> Handle(CreateFriendCommand request, CancellationToken cancellationToken)
        {
            var entity = Friend.Create(request.Id, request.Name, request.Nickname, request.Email);

            _repository.Add(entity);

            await _repository.UnitOfWork.SaveAsync(cancellationToken);

            return(true);
        }
Esempio n. 10
0
 public override async Task Initialize()
 {
     await Task.Run(() =>
     {
         for (var i = 0; i < 10; i++)
         {
             _friendRepository.Add(GenerateRandomFriend(i));
         }
     });
 }
        public async Task <IActionResult> Create(Friend friend)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            await _context.Add(friend);

            var friendList = await _context.GetAllFriends();

            return(View("Index", friendList));
        }
Esempio n. 12
0
        public async Task <ValidationResult> Handle(RegisterNewFriendCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                return(request.ValidationResult);
            }

            var friend = new Friend(Guid.NewGuid(), request.Name);

            _friendRepository.Add(friend);

            return(await Commit(_friendRepository.UnitOfWork));
        }
Esempio n. 13
0
        public FriendRequestAddedDTO AddFriend(FriendRelationship friendRelationship)
        {
            if (friendRepository.FriendshipExists(friendRelationship.UserId, friendRelationship.FriendUserId))
            {
                friendRepository.Add(friendRelationship);
                unitOfWork.Commit();

                return(mapper.Map <FriendRequestAddedDTO>(friendRelationship));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 14
0
        public Friend Add(Friend friend, Location location)
        {
            if (location.FriendId == null)
            {
                friend.Location   = location;
                friend            = _friendRepository.Add(friend);
                location.FriendId = friend.Id;
                _locationRepository.Update(location);
            }
            else
            {
                throw new ArgumentException("Location invalid!");
            }

            return(friend);
        }
Esempio n. 15
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);
            }
        }
        public Task <bool> Handle(RegisterNewFriendCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(Task.FromResult(false));
            }
            else
            {
                var newFriend = _Mapper.Map <Friend>(request);
                _friendRepository.Add(newFriend);

                if (Commit())
                {
                    return(Task.FromResult(true));
                }

                return(Task.FromResult(false));
            }
        }
        public ICommandResult Handle(RegisterFriendCommand command)
        {
            if (_friendRepository.GetByFriendName(command.Name) != null)
            {
                AddNotification("Name", "Este amigo já está cadastrado!");
                return(null);
            }

            var friend = new Friend(command.Name, command.CellPhone, command.UserId);

            AddNotifications(friend.Notifications);

            if (Invalid)
            {
                return(new CommandResult(false, "Por favor, corrija os campos abaixo", Notifications));
            }

            _friendRepository.Add(friend);

            return(new CommandResult(true, "Cadastro realizado com sucesso", friend));
        }
Esempio n. 18
0
        public void AcceptRequest(FriendRequest request)
        {
            var friendshipIsMagic = new Friend()
            {
                ProposerCitizenID = request.ProposerCitizenID,
                SecondCitizenID   = request.SecondCitizenID,
                DayCreated        = GameHelper.CurrentDay
            };

            friendRepository.Add(friendshipIsMagic);

            using (NoSaveChanges)
            {
                string link = EntityLinkCreator.Create(request.SecondCitizen.Entity).ToHtmlString();

                popupService.AddSuccess("You accepted friendship request.");
                warningService.AddWarning(request.ProposerCitizenID, $"{link} accepted your friendship request.");
            }


            friendRepository.RemoveFriendshipRequest(request);
            ConditionalSaveChanges(friendRepository);
        }
Esempio n. 19
0
 public async Task <DataAccessResponse <string> > Add(Friend friend)
 {
     return((await _repo.Add(friend.ToEntity())).ToModel());
 }
        protected override int Create(IWriteDocument writeDocument, HttpResponseMessage response)
        {
            var friend = Reader.Read(writeDocument);

            return(repo.Add(friend));
        }
Esempio n. 21
0
 public FriendEntity CreateFriend(FriendEntity friend)
 {
     return(_friendRepository.Add(friend));
 }