Esempio n. 1
0
        public async Task <ActionResult <BaseResult> > CompleteTripByIdAsync([FromQuery, Required] int tripId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var currentCulture = _customRequestCultureProvider.DetermineProviderCultureResult(HttpContext);

            var login = HttpContext.User.Identity.Name;

            var userAuth = await _authService.GetActiveUserByLoginAsNoTrackingAsync(login);

            if (userAuth.ForceRelogin)
            {
                throw new UnauthorizedException(string.Empty);
            }

            var trip = await _tripService.GetByIdAsync(tripId, currentCulture);

            if (trip.UserId != userAuth.UserId)
            {
                throw new UnauthorizedException("The trip does not belong to the user");
            }

            return(await _tripService.CompleteAsync(tripId));
        }