public async Task <ActionResult> MarkSystemBodyAs(
            long systemBodyId,
            string comment,
            bool isPointOfInterest,
            string provingUrl = null)
        {
            var idSubmittingUser   = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var previousSubmission = _db
                                     .SystemEval
                                     .Where(e => e.IdSubmittingUser == idSubmittingUser)
                                     .OrderBy(e => e.DateOfCreation)
                                     .FirstOrDefault();

            if (previousSubmission != null)
            {
                if (previousSubmission.DateOfCreation.AddMinutes(2) > DateTimeOffset.UtcNow)
                {
                    return(new StatusCodeResult(StatusCodes.Status429TooManyRequests));
                }
            }

            var system = _db.System.FirstOrDefault(e => e.SystemBody.Any(f => f.SystemBodyId == systemBodyId));

            var lastKnownLocation = await _userTracker.LastKnownLocation(idSubmittingUser, _db);

            if (lastKnownLocation.SystemName != system.Name)
            {
                return(BadRequest(
                           $"You are not listed to be in the system '{lastKnownLocation.SystemName}' please try again at '{lastKnownLocation.NextLookupIn:G}'"));
            }

            _db.SystemEval.Add(new SystemEval()
            {
                IdSystemBody     = systemBodyId,
                Comment          = comment,
                DateOfCreation   = DateTimeOffset.UtcNow,
                IdSubmittingUser = idSubmittingUser,
                State            = isPointOfInterest,
                ProveImage       = provingUrl
            });

            await _db.SaveChangesAsync();

            if (_db.System
                .Where(e => e.SystemBody.Any(f => f.SystemBodyId == systemBodyId))
                .All(f =>
                     f.SystemBody
                     .Where(f => f.SystemBodyRing.Any(g => g.Type == "Icy"))
                     .All(e => e.SystemEval.Any(g => g.IdSubmittingUser == idSubmittingUser))))
            {
                var firstOrDefault = _db.System.FirstOrDefault(e => e.SystemBody.Any(f => f.SystemBodyId == systemBodyId));
                await _db.Database.ExecuteSqlInterpolatedAsync(
                    $"UPDATE [System] SET [System].[Explored] = [System].[Explored] + 1 WHERE [System].[SystemId] = {firstOrDefault.SystemId}");
            }
            return(Ok());
        }
Esempio n. 2
0
        public async Task <ActionResult> GetCurrentPosition()
        {
            var lastKnownLocation = await _tracker.LastKnownLocation(User.FindFirstValue(ClaimTypes.NameIdentifier), _db);

            var knownSystem = _db.System.FirstOrDefault(e => e.Name == lastKnownLocation.SystemName);

            return(Ok(new CurrentSystemLookupViewModel()
            {
                SystemViewModel = _mapper.Map <SystemViewModel>(knownSystem),
                CurrentSystem = lastKnownLocation.SystemName,
                NextPossibleLookup = lastKnownLocation.NextLookupIn
            }));
        }