Exemple #1
0
        /// <summary>
        /// Check-in a group of patrons to a dining service.
        /// </summary>
        /// <param name="venueId">Target venue ID</param>
        /// <param name="areaId">Target area ID</param>
        /// <param name="checkIn">Check-in information</param>
        public async Task SubmitDiningCheckIn(string venueId, string areaId, DiningCheckInRequest checkIn)
        {
            // Lookup venue information.
            // This will throw an error if the venue doesn't exist.
            var venue = await _database.GetVenueById(venueId);

            // Find an area that matches the requested areaId.
            var area = venue.DiningAreas.Find(a => a.Id == areaId);

            // Throw an exception if the area doesn't exist.
            if (area == null)
            {
                throw new AreaNotFoundException();
            }

            // Throw an exception if the area isn't open.
            if (!area.IsOpen)
            {
                throw new AreaIsClosedException();
            }

            // Throw an error if there is no active service.
            if (area.ActiveService == "NONE")
            {
                throw new ServiceNotFoundException();
            }

            // Create a new check-in.
            CheckInDocument checkInDocument = new CheckInDocument
            {
                Id     = ObjectId.GenerateNewId().ToString(),
                Time   = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                People = new List <DiningPatronDocument>()
            };

            // Add patrons from the request into the check-in.
            checkIn.People.ForEach(person =>
            {
                checkInDocument.People.Add(new DiningPatronDocument
                {
                    Id          = ObjectId.GenerateNewId().ToString(),
                    FirstName   = person.FirstName,
                    PhoneNumber = person.PhoneNumber
                });
            });

            // Save the check-in to a new table, or append to an existing table.
            await _database.CreateOrAppendDiningCheckIn(area.ActiveService, checkIn.TableNumber, checkInDocument);
        }