Пример #1
0
        public ActionResult Create(Courses newcourses)
        {
            if (ModelState.IsValid)
            {
                _coursesrepositories.CreateCourse(newcourses);
                return(RedirectToAction(nameof(Index)));
            }

            return(View(newcourses));
        }
        public CourseResponse CreateCourse(CreateCourseRequest request)
        {
            var response = new CreateCourseRequestValidator().Validate(request).ToResponse <CourseResponse>();

            if (!response.IsSuccessful)
            {
                return(response);
            }

            var course = new Course()
            {
                CourseName        = request.CourseName,
                CourseDescription = request.CourseDescription,
                Semester          = request.Semester,
            };

            var programsCourses = request.Programs
                                  .Select(x => new ProgramsCourses
            {
                Course      = course,
                ProgramId   = x.ProgramId,
                IsMandatory = x.IsMandatory,
            }).ToList();

            try
            {
                response.Course = _coursesRepository.CreateCourse(course, programsCourses, request.Prerequisites);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
                response.IsSuccessful = false;
                response.Errors.Add("An error has occurred while inserting course");
            }

            return(response);
        }
        public async Task <int> Handle(CreateCourseCommand command, CancellationToken token)
        {
            var course = _mapper.Map <Course>(command);

            return(await _repository.CreateCourse(course));
        }
Пример #4
0
        public async Task <bool> CreateCourse(CreateCourseDto course)
        {
            await _coursesRepository.CreateCourse(course);

            return(true);
        }
Пример #5
0
 public void CreateCourse(CreateCourseDto createCourse)
 {
     _courseRepository.CreateCourse(createCourse);
 }