Esempio n. 1
0
        public async Task <IActionResult> StartGamingService([FromRoute] string venueId, [FromRoute] string areaId)
        {
            // Pull manager ID from the HTTP context.
            string managerId = HttpContext.User.Identity.Name;

            try
            {
                // Start a new gaming service and return it.
                return(Ok(new { Service = await _managerService.StartGamingService(managerId, venueId, areaId) }));
            }
            catch (NoAccessException e)
            {
                // Error: Manager does not have access to the specified venue and area.
                _logger.LogInformation(e, "Manager was denied access to start gaming service. [mId: {managerId}, vId: {venueId}, aId: {areaId}]", managerId, venueId, areaId);

                return(BadRequest(APIError.NoAccess()));
            }
            catch (AreaNotFoundException e)
            {
                // Error: Target area does not exist, or could not be found.
                _logger.LogError(e, "Cannot start gaming service in an unknown area. [vId: {venueId}, aId: {areaId}]", venueId, areaId);

                return(BadRequest(APIError.AreaNotFound()));
            }
            catch (AreaHasActiveServiceException)
            {
                // Error: Target area already has an active service, and therefore cannot have a new service started.
                return(BadRequest(APIError.AreaHasActiveService()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to start gaming service [vId: {venueId}]", venueId);

                return(BadRequest(APIError.UnknownError()));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> StartDiningService([FromRoute] string venueId, [FromRoute] string areaId)
        {
            // Pull manager ID from the HTTP context.
            string managerId = HttpContext.User.Identity.Name;

            try
            {
                // Start a new service and return it.
                return(Ok(new { Service = await _managerService.StartDiningService(managerId, venueId, areaId) }));
            }
            catch (NoAccessException e)
            {
                // Error: Manager does not have access to create/start a dining service in the given area.
                _logger.LogInformation(e, "Manager was denied acess to start dining service. [mId: {managerId}, vId: {venueId}, aId: {areaId}]", managerId, venueId, areaId);

                return(BadRequest(APIError.NoAccess()));
            }
            catch (AreaNotFoundException e)
            {
                // Error: The requested area does not exist.
                _logger.LogError(e, "Cannot start dining service in unknown area. [vId: {venueId}, aId: {areaId}]", venueId, areaId);

                return(BadRequest(APIError.AreaNotFound()));
            }
            catch (AreaHasActiveServiceException)
            {
                // Error: The area specified already has an active service which needs to be stopped before it can be started again.
                return(BadRequest(APIError.AreaHasActiveService()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to start dining service [vId: {venueId}]", venueId);

                return(BadRequest(APIError.UnknownError()));
            }
        }