コード例 #1
0
        // GET api/EqualConnections
        public HttpResponseMessage Post(UserComparisonRequestDTO parameters)
        {
            Services.Log.Info("EqualConnectionsController entered!");
            MobileServiceContext context = new MobileServiceContext();
            List<BasicUserInfoDTO> equal = new List<BasicUserInfoDTO>();

            List<Account> userConnections = context.ConnectRequests.Where(cr => cr.Accepted.Value && (cr.RequestUserId == parameters.UserId || cr.ConnectUserId == parameters.UserId)).Select(cr => ((cr.ConnectUserId == parameters.UserId) ? cr.RequestUser : cr.ConnectUser)).ToList();
            List<Account> user2Connections = context.ConnectRequests.Where(cr => cr.Accepted.Value && (cr.RequestUserId == parameters.CompUserId || cr.ConnectUserId == parameters.CompUserId)).Select(cr => ((cr.ConnectUserId == parameters.CompUserId) ? cr.RequestUser : cr.ConnectUser)).ToList();

            IEnumerable<Account> intersect = userConnections.Intersect<Account>(user2Connections);

            foreach (Account account in intersect)
            {
                if (account != null)
                {
                    BasicUserInfoDTO userInfo = new BasicUserInfoDTO();
                    userInfo.AccountId = account.Id;
                    UserInfo ui = context.UserInfos.First(uinfo => uinfo.UserId == account.Id);
                    userInfo.Age = ui.Age;
                    userInfo.Status = ui.About;
                    userInfo.Username = account.Username;
                    userInfo.FirstName = ui.FirstName;
                    userInfo.LastName = ui.LastName;
                    userInfo.ProfilePicUrl = ui.ProfilePicUrl;
                    equal.Add(userInfo);
                }
            }
            return this.Request.CreateResponse(HttpStatusCode.OK, equal);
        }
コード例 #2
0
        // POST api/CompareUsers
        public HttpResponseMessage Post(UserComparisonRequestDTO userComparisonRequest)
        {
            Services.Log.Info("Entered CompareUsers!");
            MobileServiceContext context = new MobileServiceContext();
            UserComparison lastUserComparison = context.UserComparisons.Where(x => (x.UserId == userComparisonRequest.UserId && x.CompUserId == userComparisonRequest.CompUserId) || (x.UserId == userComparisonRequest.CompUserId && x.CompUserId == userComparisonRequest.UserId)).OrderByDescending(x => x.CreatedAt).FirstOrDefault();
            //if(lastUserComparison != null)
            //{
            //    if(!context.UserInfos.Any(x => x.UserId == userComparisonRequest.UserId && x.UpdatedAt > lastUserComparison.CreatedAt) &&
            //        !context.UserInfos.Any(x => x.UserId == userComparisonRequest.UserId && x.UpdatedAt > lastUserComparison.CreatedAt))
            //    {
            //        //No Profile changes since last update
            //        return this.Request.CreateResponse(HttpStatusCode.OK, lastUserComparison);
            //    }
            //}

            if (userComparisonRequest.CompareObjects == null)
                userComparisonRequest.CompareObjects = ProfileData.GetAllProfileDataObjects();

            UserInfo userInfo = context.UserInfos.Include("UserInfoDetails").FirstOrDefault(uiDet => uiDet.UserId == userComparisonRequest.UserId);
            UserInfo compUserInfo = context.UserInfos.Include("UserInfoDetails").FirstOrDefault(uiDet => uiDet.UserId == userComparisonRequest.CompUserId);

            UserInfoDetail mergedUserInfo = JsonUtil.MergeUserInfoDetails(userInfo.UserInfoDetails);
            UserInfoDetail mergedCompUserInfo = JsonUtil.MergeUserInfoDetails(compUserInfo.UserInfoDetails);

            UserComparison userComp = ProfileComparisonUtil.CompareUserProfiles(JsonConvert.DeserializeObject<ProfileData>(mergedUserInfo.JsonInfo),
                                                                                   JsonConvert.DeserializeObject<ProfileData>(mergedCompUserInfo.JsonInfo), userComparisonRequest.CompareObjects);
            userComp.Id = Guid.NewGuid().ToString();
            userComp.UserId = userComparisonRequest.UserId;
            userComp.CompUserId = userComparisonRequest.CompUserId;

            context.UserComparisons.Add(userComp);

            context.SaveChanges();
            Services.Log.Info("CompareUsers finished");
            return this.Request.CreateResponse(HttpStatusCode.OK, userComp);
        }