Ejemplo n.º 1
0
        public dynamic GetUserSearch(string appName, ObjectId userId, DatingBookSearchInfo search, int limit, int offset)
        {
            dynamic result = null;

            long total = 0;
            var datingBookInfos = _userDataProvider.GetDatingBookUserInfos(appName, userId, search, limit, offset, out total);

            if (datingBookInfos.Count == 0)
            {
                result = new
                {
                    data = datingBookInfos,
                    total = total
                };

                return result;
            }

            var userLikesInfos = _userLikesDataProvider.GetUserLikes(appName, userId);
            var userFavoritesInfos = _userFavoritesDataProvider.GetUserFavorites(appName, userId);
            var getSixDataInfos = new List<dynamic>();

            for (int i = 0; i < datingBookInfos.Count; i++)
            {
                dynamic getSixDataInfo = new
                {
                    uid = datingBookInfos[i].Id,
                    ufname = datingBookInfos[i].FirstName,
                    gender = datingBookInfos[i].Gender,
                    age = DateTime.Now.Year - datingBookInfos[i].Birthday.Year,
                    picture = GenerateUserProfilePictureUrl(appName, datingBookInfos[i], 118, 118),
                    location = datingBookInfos[i].Location,
                    last_visit = datingBookInfos[i].DateModified,
                    favored = IsUserWasFavorited(datingBookInfos[i].ObjectId, userFavoritesInfos),
                    liked = IsUserWasLiked(datingBookInfos[i].ObjectId, userLikesInfos)
                };

                getSixDataInfos.Add(getSixDataInfo);
            }

            result = new
            {
                data = getSixDataInfos,
                total = total
            };

            return result;
        }
Ejemplo n.º 2
0
        public GetSixModule(GetSixProvider provider)
        {
            Post[CalculateRoutingPath("get_six")] = x =>
            {
                dynamic result = null;

                try
                {
                    if (Session[FACEBOOK_ID] == null)
                        throw new UnauthorizedAccessException();

                    var requestJson = GetRequestJson(Request.Body);

                    var userId = Session[DATINGBOOK_ID] == null ? ObjectId.Empty : (ObjectId)Session[DATINGBOOK_ID];

                    EnsureSessionInCache();

                    if (requestJson.type == "search")
                    {
                        var searchInfo = new DatingBookSearchInfo();

                        searchInfo.LocationCode = string.IsNullOrEmpty((string)requestJson.param1) ? 0 : int.Parse((string)requestJson.param1);
                        searchInfo.AgeStart = string.IsNullOrEmpty((string)requestJson.param2) ? 0 : int.Parse((string)requestJson.param2);
                        searchInfo.AgeEnd = string.IsNullOrEmpty((string)requestJson.param21) ? 0 : int.Parse((string)requestJson.param21);
                        searchInfo.Gender = requestJson.param3;
                        searchInfo.Status = requestJson.param4;
                        searchInfo.LookingFor = requestJson.param5;
                        searchInfo.GenderLooking = requestJson.param6;

                        result = provider.GetUserSearch((string)Session[APP_NAME], userId, searchInfo, 18, (int)requestJson.last);
                    }
                    if (requestJson.type == "fav")
                        result = provider.GetUserFavorites((string)Session[APP_NAME], userId, 18, (int)requestJson.last);

                }
                catch (Exception ex)
                {
                    _logger.Error(ex);

                    result = ex;
                }

                return new JsonResponse(result, false, _enableHashing);
            };
        }
Ejemplo n.º 3
0
        public List<DatingBookUserInfo> GetDatingBookUserInfos(string appName, ObjectId userId, DatingBookSearchInfo search, int limit, int offset, out long total)
        {
            var dataBase = _serverWrapper.ServerConnection.GetDatabase(appName);
            var collection = dataBase.GetCollection<DatingBookUserInfo>(DATING_BOOK_USERS_COLLECTION_NAME);

            List<IMongoQuery> queries = new List<IMongoQuery>();

            queries.Add(Query.NE("_id", userId));
            queries.Add(Query.EQ("is_deleted", false));

            if (!string.IsNullOrEmpty(search.Gender))
                queries.Add(Query.EQ("gender", search.Gender));

            if (search.AgeStart > 0)
                queries.Add(Query.LTE("birthday", DateTime.Now.AddYears(-search.AgeStart)));

            if (search.AgeEnd > 0)
                queries.Add(Query.GTE("birthday", DateTime.Now.AddYears(-search.AgeEnd)));

            if (search.LocationCode > 0)
                queries.Add(Query.EQ("location", search.LocationCode));

            if (!string.IsNullOrEmpty(search.GenderLooking))
                queries.Add(Query.Matches("looking_for_gender", string.Format("/{0}/", search.GenderLooking)));

            if (!string.IsNullOrEmpty(search.Status))
                queries.Add(Query.EQ("status", search.Status));

            if (!string.IsNullOrEmpty(search.LookingFor))
                queries.Add(Query.Matches("looking_for_status", string.Format("/{0}/", search.LookingFor)));

            total = collection.Find(Query.And(queries.ToArray())).Count();

            var datingBookUserInfos = collection.Find(Query.And(queries.ToArray()))
                .SetLimit(limit)
                .SetSkip(offset)
                .SetSortOrder(SortBy.Descending("last_visit"))
                .ToList();

            return datingBookUserInfos;
        }