Exemple #1
0
        public async Task SaveScheduleAsync(SharedScheduleViewModel scheduleVM)
        {
            await Task.FromResult(0);

            //TODO: Figure out a way to update entities in database (including Schedules)
            //await PaulRepository.StoreScheduleInDatabase(scheduleVM.Schedule);

            if (!scheduleVM.Users.Any())
            {
                // Schedule no longer in use -> unload it
                _loadedSchedules.Remove(scheduleVM.Id);
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        /// <summary>
        /// Loads the schedule with the specified ID either from
        /// cache or from the database.
        /// </summary>
        /// <param name="scheduleId">Schedule ID</param>
        /// <returns>
        /// A ViewModel representing the schedule or null if no
        /// schedule with the specified ID exists
        /// </returns>
        public SharedScheduleViewModel GetOrLoadSchedule(string scheduleId)
        {
            SharedScheduleViewModel scheduleVm;

            if (_loadedSchedules.TryGetValue(scheduleId, out scheduleVm))
            {
                return(scheduleVm);
            }
            else
            {
                var schedule = PaulRepository.GetSchedule(scheduleId);

                if (schedule == null)
                {
                    // Schedule with that ID does not exist
                    return(null);
                }

                var vm = new SharedScheduleViewModel(schedule);
                _loadedSchedules.Add(scheduleId, vm);
                return(vm);
            }
        }