Beispiel #1
0
        public async Task <CommonMealRegistration> UpdateRegistration(CommonMealRegistration registration)
        {
            var status = await _mealRepository.GetStatus(registration.CommonMealId);

            // Prevent registration if meal is closed (the GUI tries to prevent this - but might fail)
            if (status != "OPEN")
            {
                throw new AppException(AppErrorCodes.MealIsClosed, $"The meal with id '{registration.CommonMealId}' is not open for registration updates");
            }

            // Prevent registration if limit on meal size
            var maxPeopleStandard = _commonMealSettings.GetMaxPeople("STANDARD");
            var maxTakeAway       = _commonMealSettings.GetMaxPeople("TAKEAWAY");

            if (registration.Attending && (maxPeopleStandard > 0 || maxTakeAway > 0))
            {
                var registrations = await _registrationRepository.GetByCommonMealId(registration.CommonMealId);

                var othersAttendingStandard = registrations.Count(x => x.Attending && x.PersonId != registration.PersonId && !x.IsTakeAway);
                var othersAttendingTakeAway = registrations.Count(x => x.Attending && x.PersonId != registration.PersonId && x.IsTakeAway);

                if (!registration.IsTakeAway && othersAttendingStandard >= maxPeopleStandard)
                {
                    throw new AppException(AppErrorCodes.MealIsFull, $"The meal is full - maybe sign up for TAKE-AWAY instead?");
                }

                if (registration.IsTakeAway && othersAttendingTakeAway >= maxTakeAway)
                {
                    throw new AppException(AppErrorCodes.TakeAwayMealIsFull, $"The meal is full - maybe sign up for STANDARD instead?");
                }
            }

            registration.Timestamp = _timeProvider.Now();
            return(await _registrationRepository.Update(registration));
        }
Beispiel #2
0
        public async Task <CommonMealChef> UpdateChef(CommonMealChef chef)
        {
            var status = await _mealRepository.GetStatus(chef.CommonMealId);

            if (status != "OPEN")
            {
                throw new Exception($"The meal with id '{chef.CommonMealId}' is not open for chef changes");
            }

            chef.Timestamp = _timeProvider.Now();
            return(await _chefRepository.Update(chef));
        }