/// <summary> /// Update a dining patron's information with new values. /// </summary> /// <param name="managerId">Manager ID</param> /// <param name="serviceId">Target service ID</param> /// <param name="tableId">Target table ID</param> /// <param name="checkInId">Target check-in ID</param> /// <param name="patronId">Target patron ID</param> /// <param name="update">New patron information</param> public async Task UpdateDiningPatron(string managerId, string serviceId, string tableId, string checkInId, string patronId, DiningPatronUpdateRequest update) { // Ensure the manager has access to the given service. await _EnsureManagerCanAccessService(managerId, serviceId); // Pull the dining service information by service ID. DiningServiceDocument diningService = await _database.GetDiningServiceById(serviceId); // Check that the service is active if (!diningService.IsActive) { throw new ServiceIsNotActiveException(); } // Locate the specified table. var table = diningService.Sittings.Find(sitting => sitting.Id.Equals(tableId)); // Throw an error if the table doesn't exist. if (table == null) { throw new TableNotFoundException(); } // Locate the specified check-in. var checkIn = table.CheckIns.Find(ci => ci.Id.Equals(checkInId)); // Throw an error if the check-in doesn't exist. if (checkIn == null) { throw new CheckInNotFoundExcption(); } // Locate the specified patron. // Throw an error if the patron doesn't exist. var patron = checkIn.People.Find(p => p.Id.Equals(patronId)); if (patron == null) { throw new PatronNotFoundException(); } // Update the patron object with new information. patron.FirstName = update.FirstName; patron.PhoneNumber = update.PhoneNumber; // Persist change to the database. await _database.UpdateDiningPatron(serviceId, tableId, checkInId, patronId, patron); }