Пример #1
0
 public List<UserBM> GeteUserByName(string searchTerm,DataTableParams param)
 {
     //Pagination logic Math.Min returns the least from both values
     var _searchQuery = param.SearchOptions.value == null ? searchTerm : param.SearchOptions.value;
     int RecordsToFetch = Math.Min(GetUserCountByName(_searchQuery) - param.RecordsToSkip, param.RecordsToTake);
     List<User> userList =   uow.UserRepository.Find(x=>x.Name.Contains(searchTerm));
     return userList.OrderBy(x => x.Name).Skip(param.RecordsToSkip).Take(RecordsToFetch).ToList().ConvertAll<UserBM>(new Converter<User, UserBM>(ConvertToBM));
 }
Пример #2
0
        public ActionResult People(GlobalSearchText GlobalSearchText, int RecordsToTake, int RecordsToSkip, List<DataTableConfig> Columns)
        {
            List<FriendBM> people = new List<FriendBM>();

            string _searchtext = GlobalSearchText.value != null ? GlobalSearchText.value : SessionManager.InstanceCreator.Get<string>("SearchText").ToString();

            FriendBL frnd = new FriendBL();
            DataTableParams param = new DataTableParams();
            param.RecordsToSkip = RecordsToSkip;
            param.RecordsToTake = RecordsToTake;
            param.SearchOptions = GlobalSearchText;
            param.ColumnConfiguration = Columns;
            people = frnd.GetUsersWithFriendStatus(_searchtext, CurrentUser.Id, param);
            return Json(people);
        }
Пример #3
0
        public JsonResult GetFriends(GlobalSearchText GlobalSearchText, int RecordsToTake, int RecordsToSkip, List<DataTableConfig> Columns)
        {
            FriendBL frndBL = new FriendBL();
            List<FriendBM> lsFrndBM = new List<FriendBM>();
            DataTableParams param = new DataTableParams();
            param.RecordsToSkip = RecordsToSkip;
            param.RecordsToTake = RecordsToTake;
            param.SearchOptions = GlobalSearchText;
            param.ColumnConfiguration = Columns;
            UserBM CurrentUser = SessionManager.InstanceCreator.Get<UserBM>(SessionKey.User);

            lsFrndBM = frndBL.GetFriendListById(CurrentUser.Id, param);

            return Json(lsFrndBM);
        }
Пример #4
0
        public List<FriendBM> GetUsersWithFriendStatus(string SearchString, int UserId, DataTableParams param)
        {
            UserBL userObj = new UserBL();
            CurrentUser = UserId;

            List<UserBM> Users = userObj.GeteUserByName(SearchString,param).Where(x=>x.Id != UserId).ToList();
            return Users.ConvertAll<FriendBM>(new Converter<UserBM, FriendBM>(ConvertToFriendBM));
        }
Пример #5
0
        public List<FriendBM> GetFriendListById(int CurrentUserId, DataTableParams param)
        {
            ProWorldzContext context = new ProWorldzContext();

            //Join User & Frien table to find current users frient with Accepted status
            //Join with GeneralInfo to get users Image
            //IQueryable<FriendBM> frndCollection =

            //   (from frnd in context.Friend
            //    join curUser in context.Users on
            //    frnd.UserId equals curUser.Id
            //    join genInfo in context.UserGeneralInfomation on
            //    frnd.FriendId equals genInfo.UserId
            //    into t
            //    from rt in t.DefaultIfEmpty()
            //    where frnd.FriendShipStatusId == (int)FriendShipStatus.Accepted && curUser.Id == CurrentUserId
            //    select new FriendBM
            //    {
            //        FriendName = curUser.Name,
            //        FriendCommunity = curUser.CommunityName,
            //        FriendImage = rt.Image != "" ? rt.Image : "",
            //        Id = frnd.Id,
            //        FriendId = frnd.FriendId,
            //        UserId = curUser.Id
            //    });

            var b = from user in context.Users
                    join fr in context.Friend
                    on user.Id equals fr.UserId
                    where user.Id == CurrentUserId && fr.FriendShipStatusId == (int)FriendShipStatus.Accepted
                    select new { fr.FriendId, fr.UserId };

            IQueryable<FriendBM> frndCollection = from curUser in context.Users
                                                  join genInfo in context.UserGeneralInfomation
                                                  on curUser.Id equals genInfo.UserId
                                                  into t
                                                  from rt in t.DefaultIfEmpty()
                                                  where b.Any(o => o.FriendId == curUser.Id)
                                                  select new FriendBM
                                                  {
                                                      FriendName = curUser.Name,
                                                      FriendCommunity = curUser.CommunityName,
                                                      FriendImage = rt.Image !=null ? rt.Image : "",
                                                      FriendId = curUser.Id,
                                                      UserId = b.Where(x => x.FriendId == curUser.Id).Select(x => x.UserId).FirstOrDefault()
                                                  };

            //Pagination logic Math.Min returns the least from both values
            int RecordsToFetch = Math.Min(frndCollection.Count() - param.RecordsToSkip, param.RecordsToTake);
            frndCollection = frndCollection.OrderBy(x => x.FriendName).Skip(param.RecordsToSkip).Take(RecordsToFetch);

            //Searching
            if (param.SearchOptions.value != null)
            {
                frndCollection = frndCollection.Where(x => x.FriendName.Contains(param.SearchOptions.value));
            }

            return frndCollection.ToList();

            //***Problem with lambda it fills the FriendUser Model with Current User info not with Friend's Info***//

            //IQueryable<Friend> frndCollection = context.Friend.Where(x => x.UserId == CurrentUserId
            //    && x.FriendShipStatusId == (int)FriendShipStatus.Accepted).
            //    OrderBy(x => x.FriendUser.Name);
            //int RecordsToFetch = Math.Min(frndCollection.Count() - param.RecordsToSkip, param.RecordsToTake);
            //frndCollection = frndCollection.Skip(RecordsToFetch).Take(param.RecordsToSkip);
            // List<FriendBM> frndBM = frndCollection.ToList().ConvertAll<FriendBM>(new Converter<Friend, FriendBM>(ConvertToBM));
        }