コード例 #1
0
        private async Task <OutOfSchedulePeriods> CheckOutPeriodExistanceAsync(long scheduleId)
        {
            OutOfSchedulePeriods schedule = await OutOfScheduleRepo.FindById(scheduleId);

            if (schedule == null)
            {
                throw new Exception(String.Format("There is no schedule record with id {0}", scheduleId));
            }
            return(schedule);
        }
コード例 #2
0
        public async Task <bool> RemoveOutOfScheduleIntervalAsync(long employerId, long restaurantId, long scheduleId)
        {
            EmployersRestaurants connection = await CheckEmployerRestaurantAsync(employerId, restaurantId);

            CheckTheLoggedInPerson();

            OutOfSchedulePeriods current = await CheckOutPeriodExistanceAsync(scheduleId);

            await OutOfScheduleRepo.RemoveAsync(current);

            return(true);
        }
コード例 #3
0
        public async Task <OutOfSchedulePeriods> AddOutOfScheduleIntervalAsync(long employerId, long restaurantId, long openScheduleId, DateTimeOffset startOn, DateTimeOffset endsOn, string description)
        {
            EmployersRestaurants connection = await CheckEmployerRestaurantAsync(employerId, restaurantId);

            OpenHoursSchedule work = await CheckScheduleExistanceAsync(openScheduleId);

            if (restaurantId != work.RestaurantId)
            {
                throw new Exception("Operation not permitted. Cannot add schedule for other restaurants.");
            }

            CheckTheLoggedInPerson();

            if (startOn.CompareTo(endsOn) >= 0)
            {
                throw new Exception(String.Format("Invalid period range. The period range can not start on: {0} and ends on {1}.", startOn.ToString("s"), endsOn.ToString("S")));
            }

            DateTimeOffset current = DateTimeOffset.UtcNow;

            if (endsOn.CompareTo(current) <= 0)
            {
                throw new Exception(String.Format("The interval ({0} - {1}) is before current time {2}, and can not be added.", startOn.ToString("s"), endsOn.ToString("s"), current.ToString("s")));
            }

            DateTimeOffset real = startOn.CompareTo(current) <= 0 ? current : startOn;

            OutOfSchedulePeriods outSchedule = new OutOfSchedulePeriods
            {
                OutOfSchedulePeriodStarts = real,
                OutOfSchedulePeriodEnds   = endsOn,
                Description         = description,
                OpenHoursScheduleId = openScheduleId
            };

            List <OutOfSchedulePeriods> existingSchedules = await OutOfScheduleRepo.GetAllInPeriod(openScheduleId, real, endsOn);

            if (existingSchedules.Count == 0)
            {
                await OutOfScheduleRepo.AddAsync(outSchedule, this.ModifierId);

                return(outSchedule);
            }

            throw new Exception("There are overlapping periods");
        }