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));
        }
示例#2
0
        public async Task <DetailedScheduledClassViewModel> BuildScheduledClassDetailsViewModel(string id)
        {
            var dto         = _scheduledClassReader.GetScheduledClass(id);
            var attendances = _classAttendanceReader.GetClassAttendanceByScheduledClass(id);

            if (dto == null || attendances == null)
            {
                return(null);
            }

            var viewModel = new DetailedScheduledClassViewModel()
            {
                Id             = dto.Id,
                ClassStartTime = dto.ClassStartTime,
                ClassTypeName  = dto.ClassTypeName,
                InstructorName = dto.InstructorName,
                IsCancelled    = dto.IsCancelled,
                Attendances    = attendances
            };

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