public async Task <int> AddClassAttendance(CreateClassAttendanceViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(await Task.FromResult(ClassAttendanceResponse.UnspecifiedError));
            }

            var scheduledClass = _scheduledClassReader.GetScheduledClass(viewModel.ScheduledClassId);

            if (scheduledClass == null)
            {
                return(await Task.FromResult(ClassAttendanceResponse.ClassNotFound));
            }
            if (scheduledClass.IsCancelled)
            {
                return(await Task.FromResult(ClassAttendanceResponse.ClassCancelled));
            }

            var dto = new ClassAttendanceDto()
            {
                Id                 = Guid.NewGuid().ToString(),
                EnrolledDate       = DateTime.UtcNow,
                EnrolledBy         = viewModel.EnrolledBy,
                AttendeeId         = viewModel.AttendeeId,
                ScheduledClassId   = viewModel.ScheduledClassId,
                ScheduledClassName = scheduledClass.ClassTypeName,
                NoShow             = false
            };

            bool isSuccess = _classAttendanceWriter.AddClassAttendance(dto);

            return(await Task.FromResult(isSuccess?ClassAttendanceResponse.Success : ClassAttendanceResponse.UnspecifiedError));
        }
Exemple #2
0
        // GET: ClassAttendance/Create
        public async Task <ActionResult> Create(string scid)
        {
            if (scid == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var scheduledClass = await _classAttendanceService.GetScheduledClass(scid);

            var viewModel = new CreateClassAttendanceViewModel(scheduledClass);

            return(View(viewModel));
        }
Exemple #3
0
        public async Task <ActionResult> Create(CreateClassAttendanceViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                viewModel.AttendeeId = User.Identity.GetUserId();

                var response = await _classAttendanceService.AddClassAttendance(viewModel);

                switch (response)
                {
                case ClassAttendanceResponse.Success:
                    _logger.Info($"User ID {viewModel.AttendeeId} has successfully signed up for scheduled class {viewModel.ScheduledClassId}");
                    return(RedirectToAction("Index"));

                case ClassAttendanceResponse.ClassCancelled:
                    ModelState.AddModelError("", "Class has been cancelled. Sorry!");
                    _logger.Info($"User ID {viewModel.AttendeeId} attempted to sign up for scheduled class {viewModel.ScheduledClassId} which has since been cancelled");
                    break;

                case ClassAttendanceResponse.ClassNotFound:
                    ModelState.AddModelError("", "Class not found. Please try again");
                    _logger.Info($"User ID {viewModel.AttendeeId} attempted to sign up for scheduled class {viewModel.ScheduledClassId} which does not exist");
                    break;

                case ClassAttendanceResponse.UnspecifiedError:
                    _logger.Info($"User ID {viewModel.AttendeeId} attempted to sign up for scheduled class, but something went wrong");
                    ModelState.AddModelError("", "Something has gone wrong. Please refresh the page and try again");
                    break;

                default:
                    ModelState.AddModelError("", "Error");
                    break;
                }
            }

            return(View(viewModel));
        }