예제 #1
0
        public void PrepareUserInfo(AspNetUserFullInfoViewModel p)
        {
            var _followService = this.Service <IFollowService>();
            var _postService   = this.Service <IPostService>();

            //number that this person following
            p.FollowCount = _followService.GetFollowingCount(p.Id);
            //number of people that follow this person
            p.FollowedCount = _followService.GetFollowerCount(p.Id);

            p.Followed = _followService.CheckFollowOrNot(p.Id, User.Identity.GetUserId());

            if (User.Identity.GetUserId().Equals(p.Id))
            {
                p.isOwner = true;
            }
            else
            {
                p.isOwner = false;
            }

            p.PostCount = _postService.GetPostCountOfUser(p.Id);
        }
예제 #2
0
        public ActionResult Index()
        {
            var _sportService = this.Service <ISportService>();
            var sports        = _sportService.GetActive()
                                .Select(s => new SelectListItem
            {
                Text  = s.Name,
                Value = s.Id.ToString()
            }).OrderBy(s => s.Value);

            ViewBag.Sport = sports;
            var        _userService = this.Service <IAspNetUserService>();
            var        userId       = User.Identity.GetUserId();
            AspNetUser curUser      = _userService.FirstOrDefaultActive(p => p.Id == userId);

            if (curUser == null)
            {
                return(RedirectToAction("PageNotFound", "Errors"));
            }
            else
            {
                AspNetUserFullInfoViewModel cu = Mapper.Map <AspNetUserFullInfoViewModel>(curUser);
                this.PrepareUserInfo(cu);
                ViewBag.User = cu;
            }

            //suggest news
            var         _newsService = this.Service <INewsService>();
            List <News> newsList     = new List <News>();

            foreach (var hobby in curUser.Hobbies)
            {
                List <News> list = _newsService.GetActive(p => p.Category.CategorySports.Where(f =>
                                                                                               f.SportId == hobby.SportId).ToList().Count > 0).ToList();
                newsList.AddRange(list);
            }

            if (newsList.Count == 0)
            {
                newsList = _newsService.GetActive().ToList();
            }
            if (newsList != null)
            {
                ViewBag.SuggestNews = newsList.FirstOrDefault();
            }

            //load group name
            var          _groupService = this.Service <IGroupService>();
            List <Group> groupList     = _groupService.GetActive(p => p.GroupMembers.Where(f =>
                                                                                           f.UserId == userId && f.Status == (int)GroupMemberStatus.Approved).ToList().Count > 0).ToList();

            if (groupList != null)
            {
                ViewBag.GroupList = groupList;
            }


            //suggest follower
            List <FollowSuggestViewModel> userList = new List <FollowSuggestViewModel>();
            var  Coord       = new GeoCoordinate();
            bool checkNearBy = false;

            if (curUser.Longitude != null && curUser.Latitude != null)
            {
                Coord       = new GeoCoordinate(curUser.Latitude.Value, curUser.Longitude.Value);
                checkNearBy = true;
            }
            var users = _userService.GetActive(p => p.Id != userId && p.AspNetRoles.Where(k =>
                                                                                          k.Name != "Quản trị viên" && k.Name != "Moderator").ToList().Count > 0 &&
                                               p.Follows.Where(f => f.Active == true && (f.FollowerId == userId)).ToList().Count == 0).ToList();

            foreach (var user in users)
            {
                FollowSuggestViewModel model = Mapper.Map <FollowSuggestViewModel>(user);
                model.weight = 0;
                foreach (var follow in user.Follows)
                {
                    if (follow.UserId == curUser.Id)
                    {
                        model.weight += 1;
                        break;
                    }
                }

                if (checkNearBy && (user.Longitude != null && user.Latitude != null))
                {
                    var userCoord = new GeoCoordinate(user.Latitude.Value, user.Longitude.Value);
                    var dis       = Coord.GetDistanceTo(userCoord);
                    if (Coord.GetDistanceTo(userCoord) < 5000)
                    {
                        model.weight += 2;
                    }
                }

                int hobbyCount = 1;
                foreach (var hobby in user.Hobbies)
                {
                    foreach (var curHobby in curUser.Hobbies)
                    {
                        if (hobby.SportId == curHobby.SportId)
                        {
                            model.weight    = model.weight + hobbyCount * 3;
                            model.sameSport = hobbyCount;
                            hobbyCount++;
                        }
                    }
                }
                userList.Add(model);
            }
            List <FollowSuggestViewModel> suggestUserList = userList.OrderByDescending(p => p.weight).Take(10).ToList();

            if (suggestUserList != null)
            {
                ViewBag.suggestUserList = suggestUserList;
            }

            //load follow numbers
            var _followService = this.Service <IFollowService>();
            var _postService   = this.Service <IPostService>();

            ViewBag.Following = _followService.GetActive(p => p.FollowerId == curUser.Id).Count();
            ViewBag.Follower  = _followService.GetActive(p => p.UserId == curUser.Id).Count();
            ViewBag.PostCount = _postService.GetActive(p => p.UserId == curUser.Id).Count();

            //get list of user that this user is following
            List <Follow> followingList = _followService.GetActive(f => f.FollowerId == curUser.Id).ToList();
            List <FollowDetailViewModel> followingListVM = Mapper.Map <List <FollowDetailViewModel> >(followingList);

            foreach (var item in followingListVM)
            {
                AspNetUser          user   = _userService.FirstOrDefaultActive(u => u.Id.Equals(item.UserId));
                AspNetUserViewModel userVM = Mapper.Map <AspNetUserViewModel>(user);
                item.User = userVM;
            }
            ViewBag.followingList = followingListVM;
            return(View());
        }
예제 #3
0
        public ActionResult saveProfile(AspNetUserFullInfoViewModel model, string hobbies)
        {
            var result       = new AjaxOperationResult();
            var _userService = this.Service <IAspNetUserService>();

            AspNetUser user = _userService.FindUser(model.Id);

            if (user != null)
            {
                user.FullName = model.FullName;
                user.Email    = model.Email;
                user.City     = model.City;
                user.Address  = model.Address;
                user.District = model.District;
                user.Ward     = model.Ward;
                if (user.Ward != null || user.District != null || user.City != null)
                {
                    StringBuilder localtion = new StringBuilder();
                    localtion.Append(user.Address);
                    localtion.Append(" " + user.Ward + " " + user.District + " " + user.City);
                    DataTable coordinate = getLocation(localtion.ToString());
                    double    latitude   = Double.Parse(coordinate.Rows[0]["Latitude"].ToString());
                    double    longtitude = Double.Parse(coordinate.Rows[0]["Longitude"].ToString());
                    user.Latitude  = latitude;
                    user.Longitude = longtitude;
                }

                if (_userService.UpdateUser(user) != null)
                {
                    if (!String.IsNullOrEmpty(hobbies))
                    {
                        string[] newHobbies = hobbies.Split(',');
                        if (newHobbies != null)
                        {
                            var _hobbyService = this.Service <IHobbyService>();

                            //find and delete old hobbies
                            List <Hobby> oldHobbies = _hobbyService.GetActive(h => h.UserId.Equals(user.Id)).ToList();
                            foreach (var item in oldHobbies)
                            {
                                _hobbyService.Delete(item);
                            }

                            //add new hobbies
                            foreach (var item in newHobbies)
                            {
                                if (!item.Equals(""))
                                {
                                    Hobby hb = new Hobby();
                                    hb.UserId  = user.Id;
                                    hb.SportId = Int32.Parse(item);
                                    _hobbyService.Create(hb);
                                }
                            }
                            result.Succeed = true;
                        }
                        else
                        {
                            result.Succeed = false;
                        }
                    }
                    else
                    {
                        result.Succeed = false;
                    }
                }
                else
                {
                    result.Succeed = false;
                }
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
예제 #4
0
        // GET: Group
        public ActionResult Index(int?id)
        {
            var _groupService       = this.Service <IGroupService>();
            var _groupMemberService = this.Service <IGroupMemberService>();
            var _postService        = this.Service <IPostService>();
            var _sportService       = this.Service <ISportService>();
            var _followService      = this.Service <IFollowService>();
            var _userService        = this.Service <IAspNetUserService>();
            var _challengeService   = this.Service <IChallengeService>();
            var _hobbyService       = this.Service <IHobbyService>();
            var _placeService       = this.Service <IPlaceService>();

            Group group = _groupService.FirstOrDefaultActive(g => g.Id == id);

            if (group != null)
            {
                GroupFullInfoViewModel model = Mapper.Map <GroupFullInfoViewModel>(group);

                //check current user role
                string curUserId = User.Identity.GetUserId();

                GroupMemberRole role = _groupMemberService.CheckRoleMember(curUserId, id.Value);

                switch (role)
                {
                case GroupMemberRole.Admin:
                    model.IsAdmin         = true;
                    model.IsMember        = true;
                    model.isPendingMember = false;
                    break;

                case GroupMemberRole.Member:
                    model.IsAdmin         = false;
                    model.IsMember        = true;
                    model.isPendingMember = false;
                    break;

                case GroupMemberRole.NotMember:
                    model.IsAdmin         = false;
                    model.IsMember        = false;
                    model.isPendingMember = false;
                    break;

                case GroupMemberRole.PendingMember:
                    model.IsAdmin         = false;
                    model.IsMember        = false;
                    model.isPendingMember = true;
                    break;
                }

                //List<GroupMember> listGroup = _groupMemberService.GetActive(g => g.UserId.Equals(curUserId)).ToList();
                //foreach (var item in listGroup)
                //{
                //    if(item.GroupId == model.Id)
                //    {
                //        model.IsMember = true;
                //        if(item.Admin)
                //        {
                //            model.IsAdmin = true;
                //        }
                //    }
                //}

                //post count
                model.PostCount = _postService.GetActive(p => p.GroupId == id).ToList().Count();

                //member count
                model.MemberCount = _groupMemberService.GetActive(g => g.GroupId == id && g.Status == (int)GroupMemberStatus.Approved).ToList().Count();

                if (model.PlaceId != null)
                {
                    var place = _placeService.FirstOrDefaultActive(p => p.Id == model.PlaceId);
                    if (place != null)
                    {
                        model.PlaceName = place.Name;
                    }
                }
                if (model.StartTime != null)
                {
                    model.StartTimeString = model.StartTime.Value.Hours.ToString("00") + ":" + model.StartTime.Value.Minutes.ToString("00");
                }
                if (model.EndTime != null)
                {
                    model.EndTimeString = model.EndTime.Value.Hours.ToString("00") + ":" + model.EndTime.Value.Minutes.ToString("00");
                }
                if (model.AvailableDays != null)
                {
                    var bits = new bool[8];
                    for (var i = 7; i >= 0; i--)
                    {
                        bits[i] = (model.AvailableDays & (1 << i)) != 0;
                    }
                    var dayOfWeek = "";
                    if (bits[1])
                    {
                        dayOfWeek += "CN ";
                    }
                    if (bits[2])
                    {
                        dayOfWeek += "T2 ";
                    }
                    if (bits[3])
                    {
                        dayOfWeek += "T3 ";
                    }
                    if (bits[4])
                    {
                        dayOfWeek += "T4 ";
                    }
                    if (bits[5])
                    {
                        dayOfWeek += "T5 ";
                    }
                    if (bits[6])
                    {
                        dayOfWeek += "T6 ";
                    }
                    if (bits[7])
                    {
                        dayOfWeek += "T7 ";
                    }
                    model.Days = dayOfWeek;
                }

                //get sport list for post
                var sports = _sportService.GetActive()
                             .Select(s => new SelectListItem
                {
                    Text  = s.Name,
                    Value = s.Id.ToString()
                }).OrderBy(s => s.Value);
                ViewBag.Sport = sports;

                var friends = new List <SelectListItem>();
                List <GroupMember> gmList = _groupMemberService.GetActive(g => g.GroupId == id.Value).ToList();
                //get followed friend
                friends = _followService.GetActive(f => f.FollowerId == curUserId)
                          .Select(s => new SelectListItem
                {
                    Text  = s.AspNetUser.FullName,
                    Value = s.AspNetUser.Id
                }).OrderBy(s => s.Value).ToList();

                int frCount = friends.Count();
                var tmpFrs  = new List <SelectListItem>();
                tmpFrs.AddRange(friends);
                for (int i = 0; i < frCount; i++)
                {
                    SelectListItem si = tmpFrs.ElementAt(i);
                    foreach (var it in gmList)
                    {
                        if (si.Value.Equals(it.UserId) || tmpFrs.ElementAt(i).Equals(curUserId))
                        {
                            friends.Remove(tmpFrs.ElementAt(i));
                        }
                    }
                }

                ViewBag.friends = friends;

                //member
                List <GroupMember> ListGroupMember = _groupMemberService.GetActive(g => g.GroupId == id && g.Status == (int)GroupMemberStatus.Approved).ToList();
                List <GroupMemberFullInfoModel> ListGroupMemberVM = Mapper.Map <List <GroupMemberFullInfoModel> >(ListGroupMember);
                for (int i = 0; i < ListGroupMember.Count(); i++)
                {
                    GroupMember gm   = ListGroupMember.ElementAt(i);
                    AspNetUser  user = _userService.FirstOrDefaultActive(u => u.Id == gm.UserId);
                    AspNetUserFullInfoViewModel userFull = Mapper.Map <AspNetUserFullInfoViewModel>(user);
                    ListGroupMemberVM[i].AspNetUser = userFull;
                }

                //list pending member
                List <GroupMember> ListPendingMember = _groupMemberService.GetActive(g => g.GroupId == id && g.Status == (int)GroupMemberStatus.Pending).ToList();
                List <GroupMemberFullInfoModel> ListPendingMemberVM = Mapper.Map <List <GroupMemberFullInfoModel> >(ListPendingMember);
                for (int i = 0; i < ListPendingMember.Count(); i++)
                {
                    GroupMember gm   = ListPendingMember.ElementAt(i);
                    AspNetUser  user = _userService.FirstOrDefaultActive(u => u.Id == gm.UserId);
                    AspNetUserFullInfoViewModel userFull = Mapper.Map <AspNetUserFullInfoViewModel>(user);
                    ListPendingMemberVM[i].AspNetUser = userFull;
                }

                //get list user that cur user followed
                List <Follow> listFollow = _followService.GetActive(f => f.FollowerId == curUserId).ToList();
                if (listFollow != null && listFollow.Count > 0)
                {
                    foreach (var followedUser in listFollow)
                    {
                        foreach (var groupMember in ListGroupMemberVM)
                        {
                            if (followedUser.UserId == groupMember.AspNetUser.Id)
                            {
                                groupMember.isFollowed = true;
                            }
                        }
                    }
                }

                //get list group that this user joined
                List <Group> groupList = _groupService.GetActive(p => p.GroupMembers.Where(f =>
                                                                                           f.UserId == curUserId && f.Status == (int)GroupMemberStatus.Approved).ToList().Count > 0).ToList();
                ViewBag.GroupList = groupList;

                //WWWWWWWWWWWWWWWWWWWWWWWWTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
                //get suggest group
                List <Group> groupListSG = _groupService.GetActive(p => p.GroupMembers.Where(f =>
                                                                                             f.UserId == curUserId).ToList().Count > 0).ToList();
                ViewBag.GroupList = groupList;
                List <Group> AllGroups  = _groupService.GetActive().ToList();
                List <Group> TempGroups = AllGroups.Except(groupListSG).ToList();

                List <Hobby> listHobbies   = _hobbyService.GetActive(h => h.UserId.Equals(curUserId)).ToList();
                List <Group> suggestGroups = new List <Group>();
                foreach (var item in TempGroups)
                {
                    foreach (var item1 in listHobbies)
                    {
                        if (item.SportId == item1.SportId)
                        {
                            suggestGroups.Add(item);
                        }
                    }
                }
                List <GroupFullInfoViewModel> suggestGroupsVM = Mapper.Map <List <GroupFullInfoViewModel> >(suggestGroups);

                //List<GroupMember> listGroup = _groupMemberService.GetActive(g => g.UserId.Equals(curUserId) && g.Status == (int)GroupMemberStatus.Approved).ToList();
                //List<Group> suggestGroups = _groupService.GetSuggestGroup(id.Value);
                //List<GroupFullInfoViewModel> suggestGroupsVM = Mapper.Map<List<GroupFullInfoViewModel>>(suggestGroups);
                //foreach (var item in suggestGroupsVM)
                //{
                //    item.MemberCount = _groupMemberService.GetActive(g => g.GroupId == item.Id).ToList().Count();
                //    foreach (var gm in listGroup)
                //    {
                //        if(gm.GroupId == item.Id)
                //        {
                //            item.IsMember = true;
                //        }
                //    }
                //}

                //get suggest group for challenge
                List <Group> suggestGroupChallenge = _groupService.GetActive(g => g.SportId == model.SportId && g.Id != model.Id).ToList();

                //get challenge request
                List <ChallengeDetailViewModel> challengeRequestList = Mapper.Map <List <ChallengeDetailViewModel> >(_challengeService.GetAllChallengeRequest(id.Value).ToList());

                //get list that this group was fighted
                List <ChallengeDetailViewModel> challengedList = Mapper.Map <List <ChallengeDetailViewModel> >(_challengeService.GetChallengedList(id.Value).ToList());

                //get not operate challenge list
                List <ChallengeDetailViewModel> notOperateChallengeList = Mapper.Map <List <ChallengeDetailViewModel> >(_challengeService.GetNotOperateChallengeList(id.Value).ToList());

                //get sent challenge request
                List <ChallengeDetailViewModel> sentChallengeRequest = Mapper.Map <List <ChallengeDetailViewModel> >(_challengeService.GetSentChallengeRequest(id.Value).ToList());

                ViewBag.sentChallengeRequest    = sentChallengeRequest;
                ViewBag.notOperateChallengeList = notOperateChallengeList;
                ViewBag.challengedList          = challengedList;
                ViewBag.challengeRequestList    = challengeRequestList;
                ViewBag.groupMember             = ListGroupMemberVM;
                ViewBag.pendingMembers          = ListPendingMemberVM;
                ViewBag.groupId               = id.Value;
                ViewBag.suggestGroups         = suggestGroupsVM;
                ViewBag.suggestGroupChallenge = suggestGroupChallenge;
                return(View(model));
            }
            else
            {
                return(RedirectToAction("PageNotFound", "Errors"));
            }
        }
예제 #5
0
        // GET: Profile
        public ActionResult Index(string userId)
        {
            var     _userService   = this.Service <IAspNetUserService>();
            var     _sportService  = this.Service <ISportService>();
            var     _followService = this.Service <IFollowService>();
            var     _groupService  = this.Service <IGroupService>();
            Country vietnam        = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH));
            var     province       = vietnam.VietNamese.ToList();
            IEnumerable <SelectListItem> provinceList = province.Select(m => new SelectListItem
            {
                Text  = m.Type + " " + m.Name,
                Value = m.Type + " " + m.Name
            }).OrderBy(s => s.Value).ToArray();

            ViewBag.ProvinceList = provinceList;

            AspNetUser user = _userService.FirstOrDefaultActive(u => u.Id.Equals(userId));

            if (user == null)
            {
                return(RedirectToAction("PageNotFound", "Errors"));
            }
            AspNetUserFullInfoViewModel model = Mapper.Map <AspNetUserFullInfoViewModel>(user);

            this.PrepareUserInfo(model);

            //suggest follower
            List <FollowSuggestViewModel> userList = new List <FollowSuggestViewModel>();
            var  Coord       = new GeoCoordinate();
            bool checkNearBy = false;

            if (user.Longitude != null && user.Latitude != null)
            {
                Coord       = new GeoCoordinate(user.Latitude.Value, user.Longitude.Value);
                checkNearBy = true;
            }
            var users = _userService.GetActive(p => p.Id != userId && p.Follows.Where(f => f.Active == true && (f.FollowerId == userId)).ToList().Count == 0).ToList();

            foreach (var item in users)
            {
                FollowSuggestViewModel followsug = Mapper.Map <FollowSuggestViewModel>(item);
                followsug.weight = 0;
                foreach (var follow in item.Follows)
                {
                    if (follow.UserId == user.Id)
                    {
                        followsug.weight += 1;
                        break;
                    }
                }

                if (checkNearBy && (item.Longitude != null && item.Latitude != null))
                {
                    var userCoord = new GeoCoordinate(item.Latitude.Value, item.Longitude.Value);
                    var dis       = Coord.GetDistanceTo(userCoord);
                    if (Coord.GetDistanceTo(userCoord) < 5000)
                    {
                        followsug.weight += 2;
                    }
                }

                int hobbyCount = 1;
                foreach (var hobby in user.Hobbies)
                {
                    foreach (var curHobby in user.Hobbies)
                    {
                        if (hobby.SportId == curHobby.SportId)
                        {
                            followsug.weight    = followsug.weight + hobbyCount * 3;
                            followsug.sameSport = hobbyCount;
                            hobbyCount++;
                        }
                    }
                }
                userList.Add(followsug);
            }
            List <FollowSuggestViewModel> suggestUserList = userList.OrderByDescending(p => p.weight).Take(10).ToList();

            if (suggestUserList != null)
            {
                ViewBag.suggestUserList = suggestUserList;
            }

            //get sport list for post
            var sports = _sportService.GetActive()
                         .Select(s => new SelectListItem
            {
                Text  = s.Name,
                Value = s.Id.ToString()
            }).OrderBy(s => s.Value);

            ViewBag.Sport = sports;

            //get all image of user
            ViewBag.userPostImages = this.GetAllPostImageOfUser(userId, 0, 12).ToList();

            //get all people that this user follow
            List <Follow>     following      = _followService.GetFollowingList(userId).ToList();
            List <AspNetUser> followingUsers = new List <AspNetUser>();

            foreach (var item in following)
            {
                AspNetUser us = _userService.FirstOrDefaultActive(u => u.Id == item.UserId);
                followingUsers.Add(us);
            }
            ViewBag.followingUsers = followingUsers;

            //get list group that this user joined
            List <Group> groupList = _groupService.GetActive(p => p.GroupMembers.Where(f =>
                                                                                       f.UserId == userId && f.Status == (int)GroupMemberStatus.Approved).ToList().Count > 0).ToList();

            if (groupList != null)
            {
                ViewBag.GroupList = groupList;
            }
            IEnumerable <SelectListItem> districtList = new List <SelectListItem>();

            if (model.City != null && model.City != "")
            {
                province = vietnam.VietNamese.Where(p => model.City.Equals(p.Type + " " + p.Name)).ToList();
                if (province != null && province.Count > 0)
                {
                    var district = province.First().Districts.ToList();
                    districtList = district.Select(m => new SelectListItem
                    {
                        Text  = m.Type + " " + m.Name,
                        Value = m.Type + " " + m.Name
                    }).OrderBy(s => s.Value).ToArray();
                }
            }
            ViewBag.DistrictList = districtList;

            string curUserId = User.Identity.GetUserId();
            //get list of user that this user is following
            List <Follow> followingList = _followService.GetActive(f => f.FollowerId == curUserId).ToList();
            List <FollowDetailViewModel> followingListVM = Mapper.Map <List <FollowDetailViewModel> >(followingList);

            foreach (var item in followingListVM)
            {
                AspNetUser          ur     = _userService.FirstOrDefaultActive(u => u.Id.Equals(item.UserId));
                AspNetUserViewModel userVM = Mapper.Map <AspNetUserViewModel>(ur);
                item.User = userVM;
            }
            ViewBag.followingList = followingListVM;

            IEnumerable <SelectListItem> wardList = new List <SelectListItem>();

            if (model.District != null && model.District != "")
            {
                province = vietnam.VietNamese.Where(p => model.City.Equals(p.Type + " " + p.Name) && p.Districts.Where(f =>
                                                                                                                       model.District.Equals(f.Type + " " + f.Name)).ToList().Count > 0).ToList();
                if (province != null && province.Count > 0)
                {
                    var districts = province.First().Districts.Where(p => model.District.Equals(p.Type + " " + p.Name)).ToList();
                    if (districts != null && districts.Count > 0)
                    {
                        var ward = districts.First().Wards.ToList();
                        wardList = ward.Select(m => new SelectListItem
                        {
                            Text  = m.Type + " " + m.Name,
                            Value = m.Type + " " + m.Name
                        }).OrderBy(s => s.Value).ToArray();
                    }
                }
            }
            ViewBag.WardList = wardList;
            return(View(model));
        }