public async Task <ActionResult> Create(string className, DateTime startTime)
        {
            var instructors = await _scheduledClassService.GetAllInstructorNames();

            var viewModel = new CreateScheduledClassViewModel(className, startTime, instructors);

            return(View(viewModel));
        }
        public async Task <ActionResult> Create(CreateScheduledClassViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                bool isSuccess = await _scheduledClassService.AddScheduledClass(viewModel);

                if (isSuccess)
                {
                    _logger.Info($"Scheduled class {viewModel.ClassTypeName}, starting at {viewModel.ClassStartTime} has been created with {viewModel.InstructorName} assigned as instructor");
                    return(RedirectToAction("Index"));
                }
            }
            return(View(viewModel));
        }
Пример #3
0
        public async Task <bool> AddScheduledClass(CreateScheduledClassViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(await Task.FromResult(false));
            }

            ScheduledClassDto dto = new ScheduledClassDto()
            {
                Id             = Guid.NewGuid().ToString(),
                ClassStartTime = viewModel.ClassStartTime,
                ClassTypeName  = viewModel.ClassTypeName,
                InstructorName = viewModel.InstructorName,
                IsCancelled    = false
            };

            bool isSuccess = _scheduledClassWriter.AddScheduledClass(dto);

            return(await Task.FromResult(isSuccess));
        }