示例#1
0
        public async Task <IActionResult> RegisterForNewsletter(NewsLetterRegistration registration)
        {
            // Attempt to validate the captcha code as an anti-spam mechanism.
            bool captchaPassedValidation;

            try
            {
                captchaPassedValidation = await _captcha.Validate(registration.Captcha);
            }
            catch (Exception ex)
            {
                // Error: Unknown error.
                _logger.LogError(ex, "An unknown exception occurred");

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

            // If the captcha failed validation, return bad request.
            if (!captchaPassedValidation)
            {
                return(BadRequest(APIError.RecaptchaFailure()));
            }

            MarketingUser marketingUser;

            try
            {
                // Register the user's email address in the database.
                marketingUser = await _newsletter.RegisterUser(registration.Name, registration.Email);
            }
            catch (MarketingUserAlreadySubscribedException ex)
            {
                // Error: User is already subscribed in the database.
                _logger.LogWarning(ex, "Failed to register marketing user. Email is already registered: {}", registration.Email);

                return(BadRequest(APIError.MarketingUserAlreadySubscribed()));
            }
            catch (Exception ex)
            {
                // Error: Unknown error.
                _logger.LogError(ex, "Exception occurred when attempting to register a marketing user.");

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

            try
            {
                // Send confirmation email to the user with unsubscribe link
                await _email.SendMarketWelcome(marketingUser);
            }
            catch (Exception ex)
            {
                // Error: Unknown error.
                _logger.LogError(ex, "An unknown error occurred when attempting to send marketing-welcome email.");

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

            return(Ok());
        }
示例#2
0
        public async Task <IActionResult> CloseDiningTable([FromRoute] string serviceId, [FromRoute] string tableId)
        {
            // Pull manager ID from the HTTP context
            string managerId = HttpContext.User.Identity.Name;

            try
            {
                // Close the dining table.
                await _managerService.CloseDiningTable(managerId, serviceId, tableId);

                // Return an empty OK status.
                return(Ok());
            }
            catch (TableNotFoundException e)
            {
                // Error: Table specified could not be found.
                _logger.LogInformation(e, "Could not find specified dining sitting. [service: {serviceId}, sitting: {tableId}]", serviceId, tableId);

                return(BadRequest(APIError.TableNotFound()));
            }
            catch (NoAccessException e)
            {
                // Error: Manager does not have sufficient permission to close the requested dining table.
                _logger.LogInformation(e, "Manager was denied access to close dining table. [mId: {managerId}, sId: {serviceId}]", managerId, serviceId);

                return(BadRequest(APIError.NoAccess()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to close dining table");

                return(BadRequest(APIError.UnknownError()));
            }
        }
        public async Task <IActionResult> GamingCheckInRequest([FromRoute] string venueId, [FromRoute] string areaId, [FromBody] GamingCheckInRequest checkIn)
        {
            try
            {
                // Check-in the patron to specified gaming area.
                await _patronService.SubmitGamingCheckIn(venueId, areaId, checkIn);

                // Log the check-in.
                _logger.LogInformation("Gaming check-in. [vId: {venueId}, aId: {areaId}]", venueId, areaId);

                // Return an empty OK status.
                return(Ok());
            }
            catch (VenueNotFoundException e)
            {
                // Error: Venue could not be found.
                _logger.LogInformation(e, "Venue could not be found to complete gaming check-in. [vId: {venueId}]", venueId);

                return(BadRequest(APIError.VenueNotFound()));
            }
            catch (AreaNotFoundException e)
            {
                _logger.LogInformation(e, "Could not find a gaming area in specified venue. [vId: {venueId}, aId: {areaId}]", venueId, areaId);

                return(BadRequest(APIError.AreaNotFound()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Gaming check-in failed. [vId: {venueId}, aId: {areaId}]", venueId, areaId);

                return(BadRequest(APIError.UnknownError()));
            }
        }
示例#4
0
        public async Task <IActionResult> GetSelf()
        {
            // Pull manager ID from the HTTP context
            string managerId = HttpContext.User.Identity.Name;

            try
            {
                // Use the manager ID to pull manager information.
                return(Ok(await _managerService.GetSelf(managerId)));
            }
            catch (ManagerNotFoundException e)
            {
                // Error: The manager specified in the request context does not exist.
                // This shouldn't really occur, since the authentication handler should fail before the request gets to the endpoint.
                _logger.LogError(e, "Session managerId resolved to unknown manager. [mId: {managerId}]", managerId);

                return(BadRequest(APIError.ManagerNotFound()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to pull authenticated manager information. [mId: {managerId}]", managerId);

                return(BadRequest(APIError.UnknownError()));
            }
        }
示例#5
0
        public async Task <IActionResult> CheckOutGamingPatron([FromRoute] string serviceId, [FromRoute] string patronId)
        {
            // Pull manager ID from the HTTP context.
            string managerId = HttpContext.User.Identity.Name;

            try
            {
                // Checkout the gaming patron.
                await _managerService.CheckOutGamingPatron(managerId, serviceId, patronId);

                // Return an empty OK status.
                return(Ok());
            }
            catch (PatronNotFoundException e)
            {
                // Error: Patron specified not found.
                _logger.LogInformation(e, "Could not find specified gaming patron for update. [mId: {managerId}, sId: {serviceId}, pId: {patronId}]", managerId, serviceId, patronId);

                return(BadRequest(APIError.PatronNotFound()));
            }
            catch (NoAccessException e)
            {
                // Error: Manager does not have sufficient permissions to checkout the gaming patron.
                _logger.LogInformation(e, "Manager was denied access to checkout gaming patron. [mId: {managerId}, sId: {serviceId}]", managerId, serviceId);

                return(BadRequest(APIError.NoAccess()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to checkout gaming patron");

                return(BadRequest(APIError.UnknownError()));
            }
        }
示例#6
0
        public async Task <IActionResult> UpdateDiningPatron(
            [FromRoute] string serviceId,
            [FromRoute] string tableId,
            [FromRoute] string checkInId,
            [FromRoute] string patronId,
            [FromBody] DiningPatronUpdateRequest update
            )
        {
            // Pull manager ID from the HTTP context.
            string managerId = HttpContext.User.Identity.Name;

            try
            {
                // Update the dining patron with new information.
                await _managerService.UpdateDiningPatron(managerId, serviceId, tableId, checkInId, patronId, update);

                // Return an empty OK status.
                return(Ok());
            }
            catch (TableNotFoundException e)
            {
                // Error: Table specified could not be found.
                _logger.LogInformation(e, "Could not find specified dining sitting to update patron. [service: {serviceId}, sitting: {tableId}]", serviceId, tableId);

                return(BadRequest(APIError.TableNotFound()));
            }
            catch (CheckInNotFoundExcption e)
            {
                // Error: Check-in specified could not be found.
                _logger.LogInformation(e, "Could not find specified dining check-in to update patron. [service: {serviceId}, sitting: {tableId}, checkIn: {checkInId}]", serviceId, tableId, checkInId);

                return(BadRequest(APIError.CheckInNotFound()));
            }
            catch (PatronNotFoundException e)
            {
                // Error: Patron specified for update does not exist.
                _logger.LogInformation(e, "Could not find specified dining patron for update. [mId: {managerId}, sId: {serviceId}, pId: {patronId}]", managerId, serviceId, patronId);

                return(BadRequest(APIError.PatronNotFound()));
            }
            catch (NoAccessException e)
            {
                // Error: Manager does not have sufficient access to update the dining patron.
                _logger.LogInformation(e, "Manager was denied access to update dining patron. [mId: {managerId}, sId: {serviceId}]", managerId, serviceId);

                return(BadRequest(APIError.NoAccess()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to update dining patron");

                return(BadRequest(APIError.UnknownError()));
            }
        }
示例#7
0
        public async Task <IActionResult> GetVenues()
        {
            // Pull manager ID from the HTTP context.
            string managerId = HttpContext.User.Identity.Name;

            try
            {
                // Return the list of venues which the manager can access.
                return(Ok(new { Venues = await _managerService.GetVenues(managerId) }));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to retrieve manager venues. [mId: {managerId}]", managerId);

                return(BadRequest(APIError.UnknownError()));
            }
        }
示例#8
0
        public async Task <IActionResult> UnsubscribeFromMarketing([FromRoute] string unsubscribeId)
        {
            try
            {
                // Unsubscribe the user from marketing emails.
                await _newsletter.UnsubscribeFromMarketing(unsubscribeId);

                // Return empty OK status.
                return(Ok());
            }
            catch (Exception ex)
            {
                // Error: Unknown error.
                _logger.LogWarning(ex, "Failed to unsubscribe user from marketing emails due to unknown error.");

                return(BadRequest(APIError.UnknownError()));
            }
        }
示例#9
0
        public async Task <IActionResult> MoveDiningGroup(
            [FromRoute] string serviceId,
            [FromRoute] string tableId,
            [FromRoute] string checkInId,
            [FromRoute] string tableNumber
            )
        {
            // Pull manager ID from the HTTP context.
            string managerId = HttpContext.User.Identity.Name;

            try
            {
                // Move the dining group and return the table ID.
                return(Ok(new { TableId = await _managerService.MoveDiningGroup(managerId, serviceId, tableId, checkInId, tableNumber) }));
            }
            catch (TableNotFoundException e)
            {
                // Error: Table specified could not be found.
                _logger.LogInformation(e, "Could not find specified dining sitting. [service: {serviceId}, sitting: {tableId}]", serviceId, tableId);

                return(BadRequest(APIError.TableNotFound()));
            }
            catch (CheckInNotFoundExcption e)
            {
                // Error: Check-in specified could not be found.
                _logger.LogInformation(e, "Could not find specified dining check-in. [service: {serviceId}, sitting: {tableId}, checkIn: {checkInId}]", serviceId, tableId, checkInId);

                return(BadRequest(APIError.CheckInNotFound()));
            }
            catch (NoAccessException e)
            {
                // Error: Manager does not have sufficient access to move the dining group.
                _logger.LogInformation(e, "Manager was denied access to move dining group. [mId: {managerId}, sId: {serviceId}]", managerId, serviceId);

                return(BadRequest(APIError.NoAccess()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to move dining check-in");

                return(BadRequest(APIError.UnknownError()));
            }
        }
        public async Task <IActionResult> DiningCheckIn([FromRoute] string venueId, [FromRoute] string areaId, [FromBody] DiningCheckInRequest checkIn)
        {
            try
            {
                // Check-in the group to the dining area.
                await _patronService.SubmitDiningCheckIn(venueId, areaId, checkIn);

                // Log the check-in.
                _logger.LogInformation("Dining check-in. [vId: {venueId}, aId: {areaId}, tN: {tableNumber}, count: {patronCount}]", venueId, areaId, checkIn.TableNumber, checkIn.People.Count);

                // Return empty OK status.
                return(Ok());
            }
            catch (VenueNotFoundException e)
            {
                // Error: Venue could not be found.
                _logger.LogInformation(e, "Venue could not be found to complete dining check-in. [vId: {venueId}]", venueId);

                return(BadRequest(APIError.VenueNotFound()));
            }
            catch (AreaNotFoundException e)
            {
                // Error: Are could not be found.
                _logger.LogInformation(e, "Could not find a dining area in specified venue. [vId: {venueId}, aId: {areaId}]", venueId, areaId);

                return(BadRequest(APIError.AreaNotFound()));
            }
            catch (ServiceNotFoundException e)
            {
                // Error: There is no active service in the specified area.
                _logger.LogInformation(e, "Venue area does not have an active service. [vId: {venueId}, aId: {areaId}]", venueId, areaId);

                return(BadRequest(APIError.AreaHasNoService()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Dining check-in failed. [vId: {venueId}, aId: {areaId}, tN: {tableNumber}, count: {patronCount}]", venueId, areaId, checkIn.TableNumber, checkIn.People.Count);

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

            try
            {
                // Stop the dining service.
                await _managerService.StopDiningService(managerId, venueId, areaId);

                // Return an empty OK status.
                return(Ok());
            }
            catch (NoAccessException e)
            {
                // Error: Manager does not have access to the area/venue which they tried to modify.
                _logger.LogInformation(e, "Manager was denied access to stop dining service. [mId: {managerId}, vId: {venueId}, aId: {areaId}]", managerId, venueId, areaId);

                return(BadRequest(APIError.NoAccess()));
            }
            catch (AreaNotFoundException e)
            {
                // Error: Area specified doesn't exist.
                _logger.LogError(e, "Cannot stop dining service in unknown area. [vId: {venueId}, aId: {areaId}]", venueId, areaId);

                return(BadRequest(APIError.AreaNotFound()));
            }
            catch (AreaHasNoActiveServiceException e)
            {
                // Error: Target area does not have an active service, and therefore cannot be stopped.
                _logger.LogError(e, "Cannot stop service in an area that has no active service. [vId: {venueId}, aId: {areaId}]", venueId, areaId);

                return(BadRequest(APIError.AreaHasNoActiveService()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to stop dining service [vId: {venueId}]", venueId);

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

            try
            {
                // Stop the gaming service in the venue + area.
                await _managerService.StopGamingService(managerId, venueId, areaId);

                // Return an empty OK status.
                return(Ok());
            }
            catch (NoAccessException e)
            {
                // Error: Manager does not have access to the target venue/area.
                _logger.LogInformation(e, "Manager was denied access to stop gaming service. [mId: {managerId}, vId: {venueId}, aId: {areaId}]", managerId, venueId, areaId);

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

                return(BadRequest(APIError.AreaNotFound()));
            }
            catch (AreaHasNoActiveServiceException e)
            {
                // Error: Area does not have an active service.
                _logger.LogInformation(e, "Gaming service cannot be stoppd as there is no active service in the specified venue/area. [vId: {venueId}, aId: {areaId}]", venueId, areaId);

                return(BadRequest(APIError.AreaHasNoActiveService()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to stop gaming service [vId: {venueId}]", venueId);

                return(BadRequest(APIError.UnknownError()));
            }
        }
        public async Task <IActionResult> GetVenueByURLName([FromRoute] string venueUrl)
        {
            try
            {
                return(Ok(await _venueService.GetVenueByURLName(venueUrl)));
            }
            catch (VenueNotFoundException)
            {
                // Error: Venue not found.
                _logger.LogInformation("Venue not found. [vUrl: {venueUrl}]", venueUrl);

                return(BadRequest(APIError.VenueNotFound()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to lookup venue. [vUrl: {venueUrl}]", venueUrl);

                return(BadRequest(APIError.UnknownError()));
            }
        }
示例#14
0
        public async Task <IActionResult> UpdatePassword([FromBody] UpdatePasswordRequest passwordInfo)
        {
            // Pull manager ID from the HTTP context.
            string managerId = HttpContext.User.Identity.Name;

            try
            {
                // Update the manager's password to the new value.
                await _managerService.UpdatePassword(managerId, passwordInfo.NewPassword);

                // Return an empty OK response, since there doesn't need to be any content.
                return(Ok());
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to update manager password. [mId: {managerId}]", managerId);

                return(BadRequest(APIError.UnknownError()));
            }
        }
        public async Task <IActionResult> GetVenueById([FromRoute] string venueId)
        {
            try
            {
                // Pull venue information and return it.
                return(Ok(await _venueService.GetVenueById(venueId)));
            }
            catch (VenueNotFoundException)
            {
                // Error: Venue not found.
                _logger.LogInformation("Venue not found. [vId: {venueId}]", venueId);

                return(BadRequest(APIError.VenueNotFound()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to lookup venue. [vId: {venueId}]", venueId);

                return(BadRequest(APIError.UnknownError()));
            }
        }
示例#16
0
        public async Task <IActionResult> Login([FromBody] ManagerLoginRequest login)
        {
            try
            {
                // Pull IP address from X-Forwarded-For.
                string ipAddress = HttpContext.Connection.RemoteIpAddress.ToString();

                // Attempt to perform a login, returning a ManagerLoginResponse on success
                return(Ok(await _managerService.Login(login, ipAddress)));
            }
            catch (BadLoginException)
            {
                // Error: Login credentials are invalid
                return(BadRequest(APIError.BadLogin()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to perform login for {username}", login.Username);

                return(BadRequest(APIError.UnknownError()));
            }
        }
示例#17
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()));
            }
        }
示例#18
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()));
            }
        }