public async Task <ValidationModel> EnrollStudent(StudentInfo studentInfo)
        {
            try
            {
                var validation = studentInfo.IsValid();
                if (!validation.IsValid)
                {
                    return new ValidationModel {
                               IsValid = false, Message = validation.Message
                    }
                }
                ;

                _courseUnitOfWork.StudentRepository.Add(studentInfo.Student);
                await _courseUnitOfWork.SaveChangesAsync();

                return(new ValidationModel {
                    IsValid = true, Message = $"{studentInfo.Student.Name} has been successfully enrolled."
                });
            }
            catch (Exception ex)
            {
                //Implement serilog for logging the error message
                return(new ValidationModel {
                    IsValid = false, Message = ex.Message
                });
            }
        }
        public async Task <ValidationModel> DeletRegisteration(int id)
        {
            try
            {
                if (id == 0)
                {
                    return new ValidationModel {
                               IsValid = false, Message = "Please provide a valid Id"
                    }
                }
                ;

                var registration = _courseUnitOfWork.StudentRegistrationRepository.GetById(id);
                var student      = _courseUnitOfWork.StudentRepository.GetById(registration.StudentId);
                var course       = _courseUnitOfWork.CourseRepository.GetById(registration.CourseId);

                course.SeatCount += 1;
                _courseUnitOfWork.StudentRegistrationRepository.Remove(registration);
                _courseUnitOfWork.CourseRepository.Edit(course);

                await _courseUnitOfWork.SaveChangesAsync();

                return(new ValidationModel {
                    IsValid = true, Message = $"{student.Name} has been successfully removed from {course.Title} course."
                });
            }
            catch (Exception ex)
            {
                return(new ValidationModel {
                    IsValid = false, Message = ex.Message
                });
            }
        }
Beispiel #3
0
        public async Task <ValidationModel> Createcourse(CourseInfo courseInfo)
        {
            try
            {
                var validation = courseInfo.IsValid();
                if (!validation.IsValid)
                {
                    return new ValidationModel {
                               IsValid = false, Message = validation.Message
                    }
                }
                ;

                _courseUnitOfWork.CourseRepository.Add(courseInfo.Course);
                await _courseUnitOfWork.SaveChangesAsync();

                return(new ValidationModel {
                    IsValid = true, Message = $"{courseInfo.Course.Title} has been successfully created."
                });
            }
            catch (Exception ex)
            {
                //Implement serilog for logging the error message
                throw new Exception(ex.Message);
            }
        }