protected void Page_Load(object sender, EventArgs e)
        {
            string     code        = Request.QueryString["code"];
            string     accessToken = GoogleUtil.GetAccessToken(code).Result;
            AccountDTO accountDTO  = GoogleUtil.GetUserInfo(accessToken).Result;

            if (!CheckLogin(accountDTO.Email))
            {
                int idInsert = InsertAccount(accountDTO.Email, accountDTO.Picture, accountDTO.Fullname);
                if (idInsert != -1)
                {
                    accountDTO.AccountID = idInsert;
                    Session["USER"]      = accountDTO;
                    Session["AccountID"] = idInsert;
                }
            }
            Response.Redirect("HomePage.aspx");
        }
Example #2
0
        // TODO make Application service to move data building logic out of controller

        public async Task <IActionResult> LocationsByCount()
        {
            var user = await _userService.CurrentUser();

            var locations = _timelineRepository
                            .GetTimelineData(user)
                            .LocationsByCount()
                            .OrderByDescending(location => location.Value)
                            .Select(entry => new LocationCountModel
            {
                LocationId   = entry.Key.Id,
                LocationName = entry.Key.Name,
                Address      = entry.Key.Address,
                VisitCount   = entry.Value,
                MapsLink     = GoogleUtil.MapsLink(entry.Key.Latitude, entry.Key.Longitude)
            })
                            .ToList();

            return(View(locations));
        }
        public async Task OnGet()
        {
            var timelineData = _timelineRepository.GetTimelineData(await _userService.CurrentUser());

            if (timelineData == null)
            {
                return;
            }

            var startDate = DateTime.MinValue;
            var endDate   = DateTime.MaxValue;

            if (DateTime.TryParse(Request.Query["start"], out var queryStart))
            {
                startDate = queryStart;
            }
            if (DateTime.TryParse(Request.Query["end"], out var queryEnd))
            {
                endDate = queryEnd;
            }

            timelineData = timelineData?.ForPeriod(startDate, endDate);

            PlaceVisitCount      = timelineData?.PlaceVisits.Count ?? 0;
            ActivitySegmentCount = timelineData?.ActivitySegments.Count ?? 0;

            if (!string.IsNullOrWhiteSpace(Request.Query["lat"]) && !string.IsNullOrWhiteSpace(Request.Query["lng"]) && !string.IsNullOrWhiteSpace(Request.Query["r"]))
            {
                var lat = double.Parse(Request.Query["lat"], CultureInfo.InvariantCulture);
                var lng = double.Parse(Request.Query["lng"], CultureInfo.InvariantCulture);
                var r   = int.Parse(Request.Query["r"], CultureInfo.InvariantCulture);

                var daysVisited = timelineData.DaysVisited(lat, lng, r)
                                  .OrderBy(date => date.Date)
                                  .ToList();
                VisitCount     = daysVisited.Count;
                VisitDays      = VisitCount == 0 ? null : daysVisited;
                MapsLink       = GoogleUtil.MapsLink(lat, lng, 10);
                LocationRadius = string.Format("{0} km", (r / 1000.0).ToString("N", CultureInfo.InvariantCulture));
            }

            AsyncSections.Add(new CollapsibleAsync
            {
                Endpoint = Url.Action("locationsByCount", "timeline"),
                Id       = "locationsByCount",
                Title    = "Locations by number of visits"
            });

            AsyncSections.Add(new CollapsibleAsync
            {
                Endpoint = Url.Action("travelMethodsByCount", "timeline"),
                Id       = "travelMethodsByCount",
                Title    = "Travel methods by count"
            });

            AsyncSections.Add(new CollapsibleAsync
            {
                Endpoint = Url.Action("travelMethodsByDistance", "timeline"),
                Id       = "travelMethodsByDistance",
                Title    = "Travel methods by distance"
            });
        }