Example #1
0
        /// <summary>
        /// Creates a new empty schedule in the database.
        /// </summary>
        /// <returns>A ViewModel that represents the new schedule</returns>
        public async Task <SharedScheduleViewModel> CreateScheduleAsync(string catalogId, ErrorReporter errorReporter)
        {
            var catalogs = await PaulRepository.GetCourseCataloguesAsync();

            var selectedCatalog = catalogs.FirstOrDefault(o => o.InternalID == catalogId);

            if (selectedCatalog == null)
            {
                errorReporter.Throw(
                    new ArgumentException($"A CourseCatalog with the specified ID '{catalogId}' does not exist"),
                    UserErrorsViewModel.GenericErrorMessage);
            }

            // Create a new schedule in DB
            var schedule = await PaulRepository.CreateNewScheduleAsync(selectedCatalog);

            var vm = new SharedScheduleViewModel(schedule);

            _loadedSchedules.Add(schedule.Id, vm);

            return(vm);
        }