예제 #1
0
        public void AddRemoveFriend()
        {
            SignUpAccountService signUpAccountService = new SignUpAccountService();
            AccountService       accountService       = new AccountService();
            FriendshipService    frService            = new FriendshipService();

            AdressDTO address = new AdressDTO();

            address.latitude  = 50;
            address.longitude = 30;
            address.address   = "Beautiful city";

            SignUpAccountDTO account = new SignUpAccountDTO();

            account.FirstName = "Ion";
            account.LastName  = "Popescu";
            account.UserName  = "******";
            account.Email     = "*****@*****.**";
            account.Adress    = address;
            account.Password  = "******";

            SignUpAccountDTO account1 = new SignUpAccountDTO();

            account1.FirstName = "Dfsadsa";
            account1.LastName  = "Ddsadsad";
            account1.UserName  = "******";
            account1.Email     = "*****@*****.**";
            account1.Adress    = address;
            account1.Password  = "******";



            AccountSimpleDTO acc  = signUpAccountService.addAccount(account);
            AccountSimpleDTO acc1 = signUpAccountService.addAccount(account1);

            frService.AddFriend(acc.Id, acc1.Id);

            var friends = frService.GetAllFriendships(acc.Id);

            FriendshipDTO friendship = friends.Where(fr => (fr.UserOne.Id == acc1.Id | fr.UserTwo.Id == acc1.Id)).FirstOrDefault();

            frService.RemoveFriendship(friendship.Id);

            var friends1 = frService.GetAllFriendships(acc.Id);

            FriendshipDTO friendship1 = friends1.Where(fr => (fr.UserOne.Id == acc1.Id | fr.UserTwo.Id == acc1.Id)).FirstOrDefault();

            accountService.deleteAccount(acc.Id);
            accountService.deleteAccount(acc1.Id);

            Assert.IsNotNull(friendship);
            Assert.IsNull(friendship1);
        }
        public ActionResult AddFriend(Guid id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Guid profileId = Guid.Parse(Session["profileId"].ToString());

            _friendshipService.AddFriend(profileId, id);

            return(RedirectToAction("Details", new { id = profileId }));
        }
예제 #3
0
        public IHttpActionResult AddFriend(int userId, int friendId)
        {
            var friendshipService = new FriendshipService();
            var sports            = friendshipService.AddFriend(userId, friendId);

            if (sports == null)
            {
                return(NotFound());
            }

            return(Ok(sports));
        }