コード例 #1
0
ファイル: FollowRepository.cs プロジェクト: jrocket/MOG
 public int Create(FollowUser follow)
 {
     follow.CreatedOn = DateTime.Now;
     this.dbContext.FollowUsers.Add(follow);
     this.dbContext.SaveChanges();
     return follow.Id;
 }
コード例 #2
0
        public async Task <IActionResult> createFallowUser(int id)
        {
            var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (await _repo.GetUser(userId) == null)
            {
                return(Unauthorized());
            }

            var fallowUser = new FallowUserForCreateDto();

            fallowUser.DateCreated = DateTime.Now;
            fallowUser.UserId      = userId;
            fallowUser.FollowerId  = id;

            FollowUser newFallowUser = _mapper.Map <FollowUser>(fallowUser);

            _repo.Add(newFallowUser);


            if (await _repo.SaveAll())
            {
                return(StatusCode(201));
            }

            throw new Exception($"the creation for fallowUser fail");
        }
コード例 #3
0
        public List <FollowUser> GetFollows()
        {
            _followsButton.Click();

            if (!WebElementHelper.HasElementIn(_driver, _followContainer, By.ClassName(FOLLOW_CARD),
                                               TimeSpan.FromSeconds(1)))
            {
                throw new MessageException("Follow is empty");
            }

            ReadOnlyCollection <IWebElement> elements = _followContainer.FindElements(By.ClassName(FOLLOW_CARD));
            List <FollowUser> users = new List <FollowUser>();

            foreach (var element in elements)
            {
                string     name = element.FindElement(By.ClassName(FOLLOW_NICKNAME_CLASS)).Text;
                FollowUser user = new FollowUser()
                {
                    Name = name
                };

                users.Add(user);
            }

            return(users);
        }
コード例 #4
0
        public async Task <string> CreateUserFollow(int userid)
        {
            using (db = new testEntities())
            {
                ApplicationUser userLogin = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                var checkUser = await db.FollowUsers.FirstOrDefaultAsync(f => f.UserId == userLogin.UserExtentLogin.Id && f.UserIdFollowed == userid);

                if (checkUser == null)
                {
                    var followUser = new FollowUser {
                        UserId = userLogin.UserExtentLogin.Id, UserIdFollowed = userid, CreatedDate = DateTime.Now
                    };
                    db.FollowUsers.Add(followUser);
                    await db.SaveChangesAsync();

                    return("A");
                }
                else
                {
                    db.FollowUsers.Remove(checkUser);
                    await db.SaveChangesAsync();

                    return("R");
                }
            }
        }
コード例 #5
0
        public bool SaveChanges(FollowUser follow)
        {
            this.dbContext.Entry(follow).State = System.Data.Entity.EntityState.Modified;
            int result = this.dbContext.SaveChanges();

            return(result > 0);
        }
コード例 #6
0
 public int Create(FollowUser follow)
 {
     follow.CreatedOn = DateTime.Now;
     this.dbContext.FollowUsers.Add(follow);
     this.dbContext.SaveChanges();
     return(follow.Id);
 }
コード例 #7
0
        public IAggregate Handle(FollowUser command)
        {
            var aggregate = _domainRepository.GetById <UserAggregate>(command.Id);

            aggregate.Follow(command.OtherUserId);

            return(aggregate);
        }
コード例 #8
0
        public void UnFollow()
        {
            var             userManager     = new UserManager <ApplicationUser>(new TestUserStore());
            MemoryUser      user            = new MemoryUser("adarsh");
            ApplicationUser applicationUser = getApplicationUser();
            var             userContext     = new UserInfo
            {
                UserId         = user.Id,
                DisplayName    = user.UserName,
                UserIdentifier = applicationUser.Email,
                RoleName       = Enum.GetName(typeof(UserRoles), applicationUser.RoleId)
            };
            var testTicket = new FormsAuthenticationTicket(
                1,
                user.Id,
                DateTime.Now,
                DateTime.Now.Add(FormsAuthentication.Timeout),
                false,
                userContext.ToString());

            AccountController controller = new AccountController(userService, userProfileService, goalService, updateService, commentService, followRequestService, followUserService, securityTokenService, userManager);

            principal.SetupGet(x => x.Identity.Name).Returns("adarsh");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
            controllerContext.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);
            controller.ControllerContext = controllerContext.Object;

            contextBase.SetupGet(x => x.Request).Returns(httpRequest.Object);
            contextBase.SetupGet(x => x.Response).Returns(httpResponse.Object);
            genericPrincipal.Setup(x => x.Identity).Returns(identity.Object);

            contextBase.SetupGet(a => a.Response.Cookies).Returns(new HttpCookieCollection());

            var formsAuthentication = new DefaultFormsAuthentication();

            formsAuthentication.SetAuthCookie(contextBase.Object, testTicket);

            HttpCookie authCookie = contextBase.Object.Response.Cookies[FormsAuthentication.FormsCookieName];

            var ticket         = formsAuthentication.Decrypt(authCookie.Value);
            var goalsetterUser = new SocialGoalUser(ticket);

            string[] userRoles = { goalsetterUser.RoleName };

            principal.Setup(x => x.Identity).Returns(goalsetterUser);
            FollowUser flwuser = new FollowUser()
            {
                FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",
                ToUserId   = "402bd590-fdc7-49ad-9728-40efbfe512ed",
            };

            followUserRepository.Setup(x => x.Get(It.IsAny <Expression <Func <FollowUser, bool> > >())).Returns(flwuser);

            var result = controller.Unfollow("402bd590-fdc7-49ad-9728-40efbfe512ed") as RedirectToRouteResult;

            Assert.AreEqual("UserProfile", result.RouteValues["action"]);
        }
コード例 #9
0
        /**
         * Lets a user unfollow another user
         **/
        public bool UnfollowUser(string username, string usernameToFollow)
        {
            //TODO add error handling
            FollowUser followUser = _usersDbContext.Users.FirstOrDefault(
                user => user.User == username && user.UserToFollow == usernameToFollow);

            _usersDbContext.Users.Remove(followUser);
            _usersDbContext.SaveChanges();
            return(true);
        }
コード例 #10
0
        public void CreateFollowUserFromRequest(FollowUser followUser, IFollowRequestService groupRequestService)
        {
            var oldUser = followUserRepository.GetMany(g => g.FromUserId == followUser.FromUserId && g.ToUserId == followUser.ToUserId);

            if (oldUser.Count() == 0)
            {
                followUserRepository.Add(followUser);
                SaveFollowUser();
            }
            groupRequestService.ApproveRequest(followUser.ToUserId, followUser.FromUserId);
        }
コード例 #11
0
        public async Task <IActionResult> UnFollowUserAsync([FromBody] FollowUser following)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var currentUGuid = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            await _repository.UnFollowUserAsync(currentUGuid, following.FollowingUserId);

            return(Ok());
        }
コード例 #12
0
        /**
         * Lets a user follow another user
         **/
        public bool FollowUser(string username, string usernameToFollow)
        {
            //TODO add error handling
            FollowUser followUser = new FollowUser
            {
                User         = username,
                UserToFollow = usernameToFollow
            };

            _usersDbContext.Users.Add(followUser);
            _usersDbContext.SaveChanges();
            return(true);
        }
コード例 #13
0
        public ActionResult AcceptRequest(string touserid, string fromuserid)
        {
            var newFollowUser = new FollowUser()
            {
                Accepted   = true,
                FromUserId = fromuserid,
                ToUserId   = touserid,
                FromUser   = userService.GetUser(fromuserid),
                ToUser     = userService.GetUser(touserid)
            };

            followUserService.CreateFollowUserFromRequest(newFollowUser, followRequestService);
            return(RedirectToAction("Index", "Notification"));
        }
コード例 #14
0
ファイル: FollowService.cs プロジェクト: jrocket/MOG
        public int FollowUser(int followedId, int followerId)
        {
            FollowUser test = this.repo.GetFollowedUser(followedId, followerId);

            if (test != null)
            {
                return(test.Id);
            }

            FollowUser f = new FollowUser()
            {
                FollowedId = followedId, FollowerId = followerId
            };

            return(this.repo.Create(f));
        }
コード例 #15
0
ファイル: FollowController.cs プロジェクト: NIZAOMA/nizaoma
        //取消对人的关注
        public ActionResult _followUser(int id)
        {
            if (getCookie("id") == -1)
            {
                return(RedirectToAction("index", "index"));
            }
            User u = db.Users.Find(getCookie("id"));

            u.UFollowingNum--;
            User a = db.Users.Find(id);

            a.UFollowerNum--;
            FollowUser fu = db.FollowUsers.First(d => d.FollowingUID == id);

            db.FollowUsers.Remove(fu);
            db.SaveChanges();
            return(JavaScript("$('.unfollow-button').css('display','none');$('.follow-button').css('display','block');"));
        }
コード例 #16
0
ファイル: HomeController.cs プロジェクト: doha77/webShouts
        public IActionResult FollowStranger(int followingUserId)
        {
            // get current login user id from session
            var id = LoggedInUserId();

            // creates follow entity
            var follow = new FollowUser()
            {
                FollowerApplicationUserId  = (int)id,
                FollowingApplicationUserId = followingUserId
            };

            // save the entity in db
            dbContent.FollowUsers.Add(follow);
            dbContent.SaveChanges();

            // redirects to home page
            return(RedirectToAction("AllShouts", "Home"));
        }
コード例 #17
0
ファイル: FollowController.cs プロジェクト: NIZAOMA/nizaoma
        //关注人
        public ActionResult followUser(int id)
        {
            FollowUser fu = new FollowUser();

            if (getCookie("id") == -1)
            {
                return(RedirectToAction("index", "index"));
            }
            fu.FUUserID     = getCookie("id"); //当前登录用户
            fu.FollowingUID = id;              //界面所显示的用户
            db.FollowUsers.Add(fu);
            User u = db.Users.Find(fu.FUUserID);

            u.UFollowingNum++;
            User a = db.Users.Find(fu.FollowingUID);

            a.UFollowerNum++;
            db.SaveChanges();
            return(JavaScript("$('.unfollow-button').css('display','block');$('.follow-button').css('display','none');"));
        }
コード例 #18
0
        public FollowUser GetFollowByName(string name)
        {
            _followsButton.Click();

            name = name.ToLower();
            if (!WebElementHelper.HasElementIn(_driver, _followContainer, By.Id(name),
                                               TimeSpan.FromSeconds(1)))
            {
                throw new MessageException("Profile not found");
            }

            IWebElement element  = _followContainer.FindElement(By.Id(name));
            string      nickname = element.FindElement(By.ClassName(FOLLOW_NICKNAME_CLASS)).Text;

            FollowUser user = new FollowUser()
            {
                Name = nickname
            };

            return(user);
        }
コード例 #19
0
        private async void ExecuteFollowUserCommand(string userid)
        {
            FollowUser follower  = FollowerUsers.FirstOrDefault(x => x.Id == userid);
            FollowUser following = FollowingUsers.FirstOrDefault(x => x.Id == userid);

            if (follower?.IsFollowing == true || following?.IsFollowing == true)
            {
                UserContentProvider user   = new UserContentProvider();
                FollowResult        result = await user.UnFollowUser(userid, GlobalValue.CurrentUserContext.UserId, GlobalValue.CurrentUserContext.MobileToken);

                if (result.Error == null || result.Error.Count == 0)
                {
                    if (follower != null)
                    {
                        follower.IsFollowing = false;
                    }
                    if (following != null)
                    {
                        following.IsFollowing = false;
                    }
                }
            }
            else
            {
                UserContentProvider user   = new UserContentProvider();
                FollowResult        result = await user.FollowUser(userid, GlobalValue.CurrentUserContext.UserId, GlobalValue.CurrentUserContext.MobileToken);

                if (result.Error == null || result.Error.Count == 0)
                {
                    if (follower != null)
                    {
                        follower.IsFollowing = true;
                    }
                    if (following != null)
                    {
                        following.IsFollowing = true;
                    }
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// 我的关注中心
        /// </summary>
        /// <param name="notice_type">前台发送的关注关系的类型三种可能</param>
        /// <returns></returns>
        public JsonResult Notice_Center(string notice_type)
        {
            List <Users_Details> UDlist = new List <Users_Details>();


            //用户登录编号
            string str_U_id = U_Id();
            //根据登录编号修改个人信息
            int Login_Id = Convert.ToInt32("1");

            string jsonstr = "";

            //我的关注
            if (notice_type == "MyNotice")
            {
                UDlist = _be.FollowUser.Where(a => a.FollowUser_User1 == Login_Id).ToList().Join(_be.Users_Details, a => a.FollowUser_User2, b => b.Users_Details_ID, (x, y) => new Users_Details()
                {
                    Users_Details_Photo  = y.Users_Details_Photo,
                    Users_Details_Name   = y.Users_Details_Name,
                    Users_Details_Resume = y.Users_Details_Resume
                }).ToList();
            }
            //谁关注我的
            if (notice_type == "HeNotice")
            {
                UDlist = _be.FollowUser.Where(a => a.FollowUser_User2 == Login_Id).ToList().Join(_be.Users_Details, a => a.FollowUser_User1, b => b.Users_Details_ID, (x, y) => new Users_Details()
                {
                    Users_Details_Photo  = y.Users_Details_Photo,
                    Users_Details_Name   = y.Users_Details_Name,
                    Users_Details_Resume = y.Users_Details_Resume
                }).ToList();
            }
            //相互关注
            if (notice_type == "Notices")
            {
                //关系表之间先来个级查询
                //记录我关注的账号
                List <FollowUser> Flist_My = _be.FollowUser.Where(a => a.FollowUser_User1 == Login_Id).ToList();

                //相互关注就是条件:我中有你,你中有wo
                List <FollowUser> Flist = new List <FollowUser>();
                foreach (var item in Flist_My)
                {
                    FollowUser Follow = _be.FollowUser.Where(a => a.FollowUser_User1 == item.FollowUser_User2 && a.FollowUser_User2 == item.FollowUser_User1).FirstOrDefault();

                    Flist.Add(Follow);
                }
                //获得相互关注的用户
                UDlist = Flist.Join(_be.Users_Details, a => a.FollowUser_User1, b => b.Users_Details_ID, (x, y) => new Users_Details()
                {
                    Users_Details_Photo  = y.Users_Details_Photo,
                    Users_Details_Name   = y.Users_Details_Name,
                    Users_Details_Resume = y.Users_Details_Resume
                }).ToList();

                //}).Join(_be.Users_Details, a =>a.Notice.FollowUser_User1, b => b.Users_Details_ID, (x, y) => new Users_Details()
                //{

                //    Users_Details_Photo = y.Users_Details_Photo,
                //    Users_Details_Name = y.Users_Details_Name,
                //    Users_Details_Resume = y.Users_Details_Resume

                //}).ToList();
            }

            //序列化
            jsonstr = JsonConvert.SerializeObject(UDlist);


            return(Json(jsonstr, JsonRequestBehavior.AllowGet));
        }
コード例 #21
0
ファイル: FollowRepository.cs プロジェクト: jrocket/MOG
 public bool SaveChanges(FollowUser follow)
 {
     this.dbContext.Entry(follow).State = System.Data.Entity.EntityState.Modified;
     int result = this.dbContext.SaveChanges();
     return result > 0;
 }
 public void SetUp()
 {
     bus = new Bus();
     followUserHandler = new FollowUserHandler(bus);
     followUserCommand = new FollowUser(SourceUser, TargetUser);
 }
コード例 #23
0
ファイル: FollowService.cs プロジェクト: jrocket/MOG
        public int FollowUser(int followedId, int followerId)
        {
            FollowUser test = this.repo.GetFollowedUser(followedId, followerId);
            if (test != null)
            {
                return test.Id;
            }

            FollowUser f = new FollowUser() { FollowedId = followedId, FollowerId = followerId };
            return this.repo.Create(f);
        }
コード例 #24
0
 public void FollowUser(FollowUser followUser)
 {
     bus.SendCommand(followUser);
 }