예제 #1
0
        public HttpResponseMessage GetUserBadges(string id, string sortByKey, bool isAscending, int pageIndex, int pageSize)
        {
            if (ValidationService.AuthorizeToken(GetToken(), "get:/api/badge/userbadges?id=&sortByKey=&isAscending=&pageIndex=&pageSize=") == false)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            Guid userId      = new Guid(id);
            User user        = myService.FindUser(userId);
            User currentUser = ValidationService.FindUserWithToken(GetToken());

            //如果当前用户和user都是volunteer,必须是自己或者好友才能调用该web api看到badge
            if (user.UserRole.Contains(Role.Volunteer) && currentUser.UserRole.Contains(Role.Volunteer))
            {
                if (currentUser.Id != userId)
                {
                    if (FriendService.CheckIfWeAreFriends(currentUser.Id, userId) == false)
                    {
                        return(new HttpResponseMessage {
                            StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                        });
                    }
                }
            }
            List <BadgeEntity> source     = BadgeService.FindAllUserGrantedBadgeEntity(userId, sortByKey, isAscending, pageIndex, pageSize);
            var            result         = transformBadgeEntityToListShow(source);
            StringWriter   tw             = new StringWriter();
            JsonSerializer jsonSerializer = new JsonSerializer();

            jsonSerializer.Serialize(tw, result, result.GetType());
            return(new HttpResponseMessage {
                Content = new StringContent(tw.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }
예제 #2
0
        public void CallUserFriendRepository_AddOnce()
        {
            // Arrange
            var mockedUserFriendRepository = new Mock <IEFRepository <UserFriend> >();
            var mockedUserRepository       = new Mock <IEFRepository <CustomUser> >();
            var mockedUserFriendFactory    = new Mock <IUserFriendFactory>();
            var friendShip = new UserFriend();

            mockedUserFriendFactory
            .Setup(
                x => x.CreateUserFriend(
                    It.IsAny <int>(),
                    It.IsAny <string>(),
                    It.IsAny <int>()))
            .Returns(friendShip);
            var mockedUnitOfWork = new Mock <IUnitOfWork>();

            var friendService = new FriendService(
                mockedUserFriendRepository.Object,
                mockedUserRepository.Object,
                mockedUserFriendFactory.Object,
                mockedUnitOfWork.Object);
            int    userId           = 10;
            string friendIdentityId = "friend-xx-id";
            int    friendId         = 50;

            // Act
            friendService.AddFriendship(userId, friendIdentityId, friendId);

            // Assert
            mockedUserFriendRepository.Verify(x => x.Add(It.Is <UserFriend>(u => u == friendShip)), Times.Once);
        }
예제 #3
0
        static void Main()
        {
            userService    = new UserService();
            messageService = new MessageService();
            friendService  = new FriendService(userService);

            mainView                 = new MainView();
            registrationView         = new RegistrationView(userService);
            authenticationView       = new AuthenticationView(userService);
            userMenuView             = new UserMenuView();
            userInfoView             = new UserInfoView();
            userDataUpdateView       = new UserDataUpdateView(userService);
            messageSendingView       = new MessageSendingView(messageService, userService);
            userIncomingMessageView  = new UserIncomingMessageView();
            userOutcomingMessageView = new UserOutcomingMessageView();

            friendManageView = new FriendsManageView();
            addFriendView    = new AddFriendView(userService, friendService);
            showFriendView   = new ShowFriendsView(friendService);

            while (true)
            {
                mainView.Show();
            }
        }
예제 #4
0
        public async Task UpdateUserRelationshipStatus(string authenticationToken, string friendId, RelationshipStatus relationshipStatus)
        {
            try
            {
                FriendService friendService = new FriendService();

                var response = await friendService.UpdateUserRelationshipStatus(authenticationToken, friendId, relationshipStatus);

                if (!response.IsSuccessStatusCode)
                {
                    if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                    {
                        throw new Exception("Unauthorized");
                    }
                    else
                    {
                        throw new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #5
0
        private async Task ExecuteFetchFriendsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                if (await ConnectivityService.IsConnected())
                {
                    await FriendService.RefreshPendingFriendsList();
                }
                else
                {
                    DialogService.ShowError(Strings.NoInternetConnection);
                }
            }
            catch (Exception ex)
            {
                Logger.Report(ex);
            }

            IsBusy = false;
        }
        public async Task <TableLayoutPanel> GetLayoutPanelAsync(User i_LoggedInUser)
        {
            IFriendService friendsService = new FriendService();
            var            friendsList    = await friendsService.GetFriendsAsync(i_LoggedInUser);

            Label commentLabel = new Label {
                Text = Resources.SelectFriendWhosePOSTsYouLikeToSee, AutoSize = true
            };

            UsersListBox.Items.Add(i_LoggedInUser);
            foreach (User user in friendsList)
            {
                UsersListBox.Items.Add(user);
            }
            r_Panel.Controls.Add(commentLabel);
            r_Panel.Controls.Add(UsersListBox);
            r_Panel.Controls.Add(r_HTML_buttom);
            r_Panel.Controls.Add(r_Dot_button);
            UsersListBox.SelectedIndexChanged += personSelectedAsync;

            UsersListBox.SelectedIndex = 0;
            personSelectedAsync(null, null);
            r_Panel.Controls.Add(r_PostsPanel);

            return(r_Panel);
        }
예제 #7
0
 public BoxFriendPresenter()
 {
     _friendRepository = new SPKTCore.Core.DataAccess.Impl.FriendRepository();
     _userSession      = new SPKTCore.Core.Impl.UserSession();
     _friendService    = new FriendService();
     _friendInvite     = new SPKTCore.Core.DataAccess.Impl.FriendInvitationRepository();
 }
        public async Task ApproveShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var dbContext = new ApplicationDbContext(options);

            var friendRepository        = new EfDeletableEntityRepository <Friend>(dbContext);
            var friendRequestRepository = new EfDeletableEntityRepository <FriendRequest>(dbContext);

            var newFriendShipRequest = new FriendRequest
            {
                SenderId   = "1",
                ReceiverId = "2",
            };

            var newFriendShip = new Friend
            {
                SenderId   = "1",
                ReceiverId = "2",
            };

            var service = new FriendService(friendRequestRepository, friendRepository);

            var sendRequestResult = service.CreateFriendRequestAsync("1", "2");

            var sendSecondRequestResult = service.CreateFriendRequestAsync("1", "2");

            var result = service.ApproveFriendRequestAsync("1", "2");

            var countResult = friendRepository.All().Count();

            Assert.Equal(1, countResult);
        }
        public async Task AreTwoUsersFriendsAsyncShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var dbContext = new ApplicationDbContext(options);

            var friendRepository        = new EfDeletableEntityRepository <Friend>(dbContext);
            var friendRequestRepository = new EfDeletableEntityRepository <FriendRequest>(dbContext);

            var service = new FriendService(friendRequestRepository, friendRepository);

            var newFriendShip = new Friend
            {
                SenderId   = "1",
                ReceiverId = "2",
            };

            await friendRepository.AddAsync(newFriendShip);

            await friendRepository.SaveChangesAsync();

            var resultTrue = await service.AreTwoUsersFriendsAsync(newFriendShip.SenderId, newFriendShip.ReceiverId);

            var resultFalse = await service.AreTwoUsersFriendsAsync("4", "3");

            Assert.True(resultTrue);
            Assert.False(resultFalse);
        }
        public async Task GetAllFriendRequestAsyncShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var dbContext = new ApplicationDbContext(options);

            var friendRepository        = new EfDeletableEntityRepository <Friend>(dbContext);
            var friendRequestRepository = new EfDeletableEntityRepository <FriendRequest>(dbContext);

            var service = new FriendService(friendRequestRepository, friendRepository);

            var newFriendShip = new FriendRequest
            {
                SenderId   = "1",
                ReceiverId = "2",
                Status     = FriendRequestStatus.Pending,
            };

            await friendRequestRepository.AddAsync(newFriendShip);

            await friendRequestRepository.SaveChangesAsync();

            AutoMapperConfig.RegisterMappings(typeof(FriendRequestTestViewModel).GetTypeInfo().Assembly);

            var result = await service.GetAllFriendRequestAsync <FriendRequestTestViewModel>(newFriendShip.ReceiverId);

            Assert.Equal(1, result.Count());
        }
        public async Task DeclineFriendRequestAsyncShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var dbContext = new ApplicationDbContext(options);

            var friendRepository        = new EfDeletableEntityRepository <Friend>(dbContext);
            var friendRequestRepository = new EfDeletableEntityRepository <FriendRequest>(dbContext);


            var newFriendShipRequest = new FriendRequest
            {
                SenderId   = "5",
                ReceiverId = "6",
                Status     = FriendRequestStatus.Pending,
            };


            await friendRequestRepository.AddAsync(newFriendShipRequest);

            await friendRequestRepository.SaveChangesAsync();

            var service = new FriendService(friendRequestRepository, friendRepository);

            var result = service.DeclineFriendRequestAsync("5", "6");

            var testResult = friendRequestRepository.All().Where(x => x.SenderId == "5" && x.Status == FriendRequestStatus.Declined).Count();

            Assert.Equal(1, testResult);
        }
        public async Task GetPendingRequestForUserShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var dbContext = new ApplicationDbContext(options);

            var friendRepository        = new EfDeletableEntityRepository <Friend>(dbContext);
            var friendRequestRepository = new EfDeletableEntityRepository <FriendRequest>(dbContext);

            var service = new FriendService(friendRequestRepository, friendRepository);

            var newFriendShip = new FriendRequest
            {
                SenderId   = "1",
                ReceiverId = "2",
                Status     = FriendRequestStatus.Pending,
            };

            await friendRequestRepository.AddAsync(newFriendShip);

            await friendRequestRepository.SaveChangesAsync();

            var result = await service.RequestFriendCountAsync("2");

            Assert.Equal(1, result);
        }
        public async Task DeleteShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var dbContext = new ApplicationDbContext(options);

            var friendRepository        = new EfDeletableEntityRepository <Friend>(dbContext);
            var friendRequestRepository = new EfDeletableEntityRepository <FriendRequest>(dbContext);

            var service = new FriendService(friendRequestRepository, friendRepository);

            var newFriendShip = new Friend
            {
                SenderId   = "1",
                ReceiverId = "2",
            };

            await friendRepository.AddAsync(newFriendShip);

            await friendRepository.SaveChangesAsync();

            var result = service.DeleteFriendShipAsync(newFriendShip.SenderId, newFriendShip.ReceiverId);

            Assert.Equal(0, friendRepository.All().Count());
        }
        public ActionResult Index(string id = null)
        {
            var utilisateur = User as PrincessPrincipal;
            var ps          = new ProfileService(null);

            if (id.IsNullOrWhiteSpace())
            {
                if (utilisateur != null)
                {
                    ps = new ProfileService(utilisateur.Token);
                    return(View(ps.GetMyProfile()));
                }
                return(RedirectToAction("Index", "Home"));
            }

            var profile = ps.GetUserProfile(id, false);

            if (!profile.IsPrivate)
            {
                return(View(profile));
            }

            //profile prive
            if (utilisateur == null)
            {
                return(RedirectToAction("Index", "Home")); //utilisateur non connecte
            }
            var fs = new FriendService(utilisateur.Token);

            if (fs.GetAllFriends().Any(f => f.HashId == profile.UserHashId)) //Dans ses amis
            {
                return(View(profile));
            }
            return(RedirectToAction("Index", "Home"));
        }
예제 #15
0
        public virtual List <Group> GetGroupByFriends(int userId, int count)
        {
            FriendService fs   = new FriendService();
            String        fIds = fs.FindFriendsIds(userId);

            if (strUtil.IsNullOrEmpty(fIds))
            {
                return(new List <Group>());
            }

            List <GroupUser> guList = db.find <GroupUser>("Member.Id in ( " + fIds + " ) ").list();
            List <GroupUser> myList = db.find <GroupUser>(myGroupCondition(userId)).list();

            List <Group> results = new List <Group>();

            foreach (GroupUser gu in guList)
            {
                if (gu.Group == null)
                {
                    continue;
                }
                if (isInMyGroups(myList, gu.Group))
                {
                    continue;
                }
                if (isGroupAdded(results, gu.Group))
                {
                    continue;
                }
                results.Add(gu.Group);
            }
            return(results);
        }
예제 #16
0
 public FeedController()
 {
     feedService    = new FeedService();
     friendService  = new FriendService();
     visitorService = new VisitorService();
     followService  = new FollowerService();
 }
예제 #17
0
 public ViewerContext(MvcContext ctx)
 {
     friendService = new FriendService();
     msgService    = new MessageService();
     followService = new FollowerService();
     this.ctx      = ctx;
 }
        public HttpResponseMessage BreakOffFriendship([FromBody] IdModel model)
        {
            if (ValidationService.AuthorizeToken(GetToken(), "post:/api/volunteer/breakofffriendship") == false)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            Guid otherVolunteerId = new Guid(model.id);
            User myself           = ValidationService.FindUserWithToken(GetToken());
            User other            = myService.FindUser(otherVolunteerId);
            Guid myId             = myself.Id;

            if (FriendService.CheckIfWeAreFriends(myId, otherVolunteerId) == false)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("你们不是好友,无法断绝关系", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            if (myService.FriendServiceInVolunteerService.BreakOffFriendship(myself, other) == false)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("断绝好友关系不成功", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
        }
예제 #19
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.InputEncoding  = Encoding.Unicode;

            userService    = new UserService();
            messageService = new MessageService();
            friendService  = new FriendService();

            mainView                 = new MainView();
            registrationView         = new RegistrationView(userService);
            authenticationView       = new AuthenticationView(userService);
            userMenuView             = new UserMenuView(userService);
            userInfoView             = new UserInfoView();
            userDataUpdateView       = new UserDataUpdateView(userService);
            messageSendingView       = new MessageSendingView(messageService, userService);
            userIncomingMessageView  = new UserIncomingMessageView();
            userOutcomingMessageView = new UserOutcomingMessageView();
            friendCreateNewView      = new FriendCreateView(friendService);

            while (true)
            {
                mainView.Show();
            }
        }
        public HttpResponseMessage AcceptFriend([FromBody] IdAndCommentModel model)
        {
            if (ValidationService.AuthorizeToken(GetToken(), "post:/api/volunteer/acceptfriend") == false)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            Guid otherVolunteerId = new Guid(model.id);
            User myself           = ValidationService.FindUserWithToken(GetToken());
            User other            = myService.FindUser(otherVolunteerId);
            Guid myId             = myself.Id;

            //检查是否已经是好友
            if (FriendService.CheckIfWeAreFriends(myId, otherVolunteerId) == true)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("你们已经是好友了", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            //同意好友申请并添加好友
            if (myService.FriendServiceInVolunteerService.AcceptFriendApplication(other, myself, model.comment) == false)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("同意好友申请不成功", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
        }
        public void Add_WithTheSameLocation_ReturnUnsuccessful(
            FriendService sut,
            Friend newFriend)
        {
            var myFriendsCollection = Builder <Friend> .CreateListOfSize(10).All()
                                      .TheFirst(1)
                                      .With(x => x.Name     = "Sergio")
                                      .With(x => x.Location = new Location
            {
                Latitude = 10, Longitude = 10
            })
                                      .Build()
                                      .ToList();

            sut.InMemoryCacheService.Remove(CacheKey);
            sut.InMemoryCacheService.Insert(CacheKey, myFriendsCollection);

            newFriend.Location.Latitude  = 10;
            newFriend.Location.Longitude = 10;

            var result = sut.Add(newFriend);

            Assert.False(result.Succeeded);
            Assert.True(result.Reason == ServiceResultFailReason.BusinessValidation);
            Assert.Contains("Já existe um amigo nessa mesma localização.", result.Errors);
        }
예제 #22
0
 public PhotoPostService()
 {
     friendService   = new FriendService();
     pickedService   = new PickedService();
     incomeService   = new UserIncomeService();
     followerService = new FollowerService();
 }
예제 #23
0
 public FriendController()
 {
     followService    = new FollowerService();
     friendService    = new FriendService();
     userService      = new UserService();
     blacklistService = new BlacklistService();
 }
예제 #24
0
 public MicroblogService()
 {
     feedService     = new FeedService();
     nfService       = new NotificationService();
     friendService   = new FriendService();
     followerService = new FollowerService();
 }
 public OverviewPage()
 {
     InitializeComponent();
     SetNewsPictureSource(_currentNews.ImageSource);
     DataContext    = this;
     _friendService = FriendService.GetInstance();
     _friendService.FriendListUpdated += SetFriendListIcon;
 }
예제 #26
0
        public ShareController()
        {
            feedService   = new FeedService();
            friendService = new FriendService();
            followService = new FollowerService();

            shareService = new ShareService();
        }
예제 #27
0
 public FriendController()
 {
     followService        = new FollowerService();
     friendService        = new FriendService();
     userService          = new UserService();
     blacklistService     = new BlacklistService();
     LayoutControllerType = typeof(MicroblogController);
 }
예제 #28
0
 public CommentController(CommentService commentService, CurrentUser currentUser,
                          FriendService friendService, PostService postService)
 {
     this.postService    = postService;
     this.currentUser    = currentUser;
     this.commentService = commentService;
     this.friendService  = friendService;
 }
예제 #29
0
 public ActionResult Add(Friend entity)
 {
     entity.DelFlag = true;
     entity.RegTime = DateTime.Now;
     entity.Status  = 1;
     FriendService.Add(entity);
     return(Json(new { status = 1, msg = "成功" }));
 }
예제 #30
0
 public ShowFriendPresenter()
 {
     _friendRepository = new SPKTCore.Core.DataAccess.Impl.FriendRepository();
     _userSession      = new SPKTCore.Core.Impl.UserSession();
     _friendService    = new FriendService();
     _ac         = new SPKTCore.Core.DataAccess.Impl.AccountRepository();
     _webcontext = new WebContext();
 }