Ejemplo n.º 1
0
        // deprecated
        public async Task <CourseResponse> SaveAsync(Course course)
        {
            try
            {
                await _courseRepository.AddAsync(course);

                await _unitOfWork.CompleteAsync();

                return(new CourseResponse(course));
            } catch (Exception e)
            {
                return(new CourseResponse("Has ocurred an error saving the Course" + e.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <CreateCourseCommandResponse> Handle(CreateCourseCommand request, CancellationToken cancellationToken)
        {
            var createCourseCommandResponse = new CreateCourseCommandResponse();
            var validator        = new CreateCourseCommandValidator(repo);
            var validationResult = await validator.ValidateAsync(request);

            if (validationResult.Errors.Count > 0)
            {
                createCourseCommandResponse.Success = false;
                foreach (var error in validationResult.Errors)
                {
                    createCourseCommandResponse.ValidationErrors.Add(error.ErrorMessage);
                }
            }
            if (createCourseCommandResponse.Success)
            {
                var course    = mapper.Map <Course>(request);
                var newCourse = await repo.AddAsync(course);
            }
            var email = new Email()
            {
                To = "*****@*****.**", Subject = "Test Msg", Body = $"Request: {request}",
            };

            try
            {
                await emailService.SendEmail(email);
            }
            catch (Exception ex) {
                //ignore
            }


            return(createCourseCommandResponse);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(CancellationToken cancellationToken)
        {
            Course course = new Course();

            course            = mapper.Map(Model, course);
            course.CreateDate = DateTime.Now;
            string imageUploadpath = Path.Combine(hostingEnvironment.WebRootPath, "images", "CourseImages");
            string imgNewFileName  = await fileHandler.UploadFileAsync(Model.UploadedImage, imageUploadpath, cancellationToken);

            fileHandler.CreateImageThumb(Path.Combine(imageUploadpath, imgNewFileName), Path.Combine(imageUploadpath, "CourseImageThumb", imgNewFileName), 80);

            string videoUploadPath  = Path.Combine(hostingEnvironment.WebRootPath, "CourseDemo");
            string videoNewFileName = await fileHandler.UploadFileAsync(Model.DemoFile, videoUploadPath, cancellationToken);

            course.ImageName    = imgNewFileName;
            course.DemoFileName = videoNewFileName;

            course.Keywordkeys = Model.Keywords.Select(k => new Keyword
            {
                Title = k
            }).ToList();
            await courseRepository.AddAsync(course, cancellationToken);

            return(RedirectToPage("/Admin/CourseManagement/Index"));
        }
Ejemplo n.º 4
0
        public async Task <CourseDetailDto> AddCourseWithRelations(CourseDetailDto courseDetailDto)
        {
            var course1 = courseDetailDto.CourseDetailDtoToCourse();
            var service = await _courseRepository.AddAsync(course1);

            return(service.CourseToCourseDetailDto());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> updateCourse(CourseInfo info)
        {
            // if(courseId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            // return Unauthorized();
            if (info.courseId != 0)
            {
                //var course = await _CourseService.GetCourseByIdAsync(info.courseId);
                //   course = info;
                if (await _CourseService.UpdateCourse(info))
                {
                    _log.LogInformation("Hello, course uptaded!");
                    return(Ok());
                }
            }
            else
            {
                var res = _mapper.Map <Course>(info);
                await _CourseService.AddAsync(res);

                _log.LogInformation("Hello, course uptaded!");
                return(Ok());
            }
            _log.LogInformation("Hello, course not uptaded!");
            return(BadRequest());
        }
        public async Task HandleAsync(CreateCourse command, ICorrelationContext context)
        {
            if (command.Price < 0)
            {
                throw new CoursesManagementException("invalid_course_price",
                                                     "Product quantity cannot be negative.");
            }

            if (await _courseRepository.ExistsAsync(command.Name))
            {
                throw new CoursesManagementException("course_already_exists",
                                                     $"Course: '{command.Name}' already exists.");
            }

            var subject = await _subjectRepository.GetAsync(command.SubjectId);


            var course = new Course(command.Id, command.Name,
                                    command.Description, command.OtherDetails, command.Price, command.StartTime,
                                    command.EndTime, State.Started, 30, command.AuthorId, command.SubjectId);
            await _courseRepository.AddAsync(course);

            await _busPublisher.PublishAsync(new CourseCreated(command.Id, command.Name,
                                                               command.Description, command.OtherDetails, command.Price, command.StartTime, command.EndTime, command.Status, command.MaxMember, subject.Name), context);
        }
Ejemplo n.º 7
0
        public async Task Handle(CourseCreatedEvent notification, CancellationToken cancellationToken)
        {
            var course = new CourseDto(notification.AggregateId.ToString(), notification.Name);

            await _courseRepository.AddAsync(course);

            _sender.SendMessagesAsync <CourseCreatedEvent>(notification).GetAwaiter().GetResult();
        }
Ejemplo n.º 8
0
 public async Task Add(CourseModel model)
 {
     var courseEntity = new CourseEntity
     {
         Specialization = model.Specialization
     };
     await _repository.AddAsync(courseEntity);
 }
Ejemplo n.º 9
0
        public async Task AddCourseAsync(CourseDTO courseDto)
        {
            var course    = mapper.Map <Course>(courseDto);
            var teacherId = (await userRepository.FindByEmailAsync(courseDto.TeacherEmail)).Id;

            course.CourseMembers.Add(
                new CourseMember()
            {
                TeacherId = teacherId
            });
            await courseRepository.AddAsync(course);

            await courseRepository.SaveChangesAsync();
        }
Ejemplo n.º 10
0
        public async Task CreateCourseAsync(CreateCourseDto course)
        {
            Course courseToDb = new() { Name = course.Name, GroupId = course.GroupId };

            courseToDb = await _courseRepository.AddAsync(courseToDb);

            await _courseRepository.UnitOfWork.SaveChangesAsync();

            var teachers = await CreateTeacherCourses(courseToDb.Id, course.TeacherIds);

            courseToDb.Teachers = teachers;
            _courseRepository.Update(courseToDb);
            await _courseRepository.UnitOfWork.SaveChangesAsync();
        }
Ejemplo n.º 11
0
        public async Task <CourseResponse> SaveAsync(Course course)
        {
            try
            {
                await _courseRepository.AddAsync(course);

                await _unitOfWork.CompleteAsync();

                return(new CourseResponse(course));
            }
            catch (Exception ex)
            {
                return(new CourseResponse($"An error ocurred while saving the course: {ex.Message}"));
            }
        }
Ejemplo n.º 12
0
        public async Task CreateAsync(Guid courseId, string name, int size, string city, string description,
                                      string field, string level, string subject)
        {
            var course = await _courseRepository.GetAsync(courseId);

            if (course != null)
            {
                throw new Exception($"Course with course id: '{courseId}' already exists.");
            }
            var courseDetails = await _courseDetailsProvider.GetAsync(subject, field, level);

            course = new Course(courseDetails, name, size, city, description);

            await _courseRepository.AddAsync(course);
        }
Ejemplo n.º 13
0
        public async Task <Guid> Handle(CreateCourseCommand request, CancellationToken cancellationToken)
        {
            var validator        = new CreateCourseCommandValidator();
            var validationResult = await validator.ValidateAsync(request);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult);
            }

            var @course = _mapper.Map <Course>(request);

            @course = await _courseRepository.AddAsync(@course);

            return(@course.Id);
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> OnPostAsync()
        {
            var emptyCourse = new Course();

            if (await TryUpdateModelAsync <Course>(
                    emptyCourse,
                    "course", // Prefix for form value.
                    s => s.CourseID, s => s.DepartmentID, s => s.Title, s => s.Credits))
            {
                await _courseRepository.AddAsync(emptyCourse);

                return(RedirectToPage("./Index"));
            }

            // Select DepartmentID if TryUpdateModelAsync fails.
            await PopulateDepartmentsDropDownList(_departmentRepository, emptyCourse.DepartmentID);

            return(Page());
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(OnGet());
            }

            var emptyCourse = new Course();

            if (await TryUpdateModelAsync <Course>(
                    emptyCourse,
                    "course",
                    s => s.Id, s => s.DepartmentId, s => s.Title, s => s.Credits))
            {
                await _courseRepository.AddAsync(emptyCourse);

                return(RedirectToPage("./Index"));
            }

            return(OnGet());
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Post([FromBody] CourseDTO dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Course c = new Course {
                Name          = dto.Name,
                Acronym       = dto.Acronym,
                CoordinatorId = dto.CoordinatorId
            };

            if (!await _repo.AddAsync(c))
            {
                throw new Exception("Unable to Add Course");
            }

            c = await _repo.GetByIdAsync(c.Id);

            return(Created(Routes.CourseEntry, new { Id = c.Id }));
        }
Ejemplo n.º 17
0
        //CRUD METHODS

        //Create---------
        public async Task <CourseResponse> SaveAsync(int inscriptionProcessId, Course course)
        {
            //find inscription process
            if (await FindInscriptionProcessById(inscriptionProcessId) == null)
            {
                return(new CourseResponse($"Inscription process with id: {inscriptionProcessId} not found"));
            }

            //now add
            try
            {
                await _courseRepository.AddAsync(inscriptionProcessId, course);

                await _unitOfWork.CompleteAsync();

                return(new CourseResponse(course));
            }
            catch (Exception ex)
            {
                return(new CourseResponse($"An error ocurred while saving the course: {ex.Message}"));
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Create a new course.
        /// </summary>
        /// <param name="course"></param>
        /// <returns></returns>
        public async Task <Result <CourseInfo> > AddCourseAsync(CourseInfo course)
        {
            var courseDb = _mapper.Map <CourseInfo, CourseDb>(course);

            courseDb.Date = DateTime.Now;
            try
            {
                await _courseRepository.AddAsync(courseDb);

                return(Result <CourseInfo> .Ok(_mapper.Map <CourseInfo>(courseDb)));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return((Result <CourseInfo>)Result.Fail($"Cannot save course. {e.Message}"));
            }
            catch (DbUpdateException e)
            {
                return((Result <CourseInfo>)Result.Fail($"Cannot save course. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return((Result <CourseInfo>)Result.Fail($"Invalid course. {e.Message}"));
            }
        }
Ejemplo n.º 19
0
        public async Task <Course> CreateAsync(Course course)
        {
            if (string.IsNullOrEmpty(course.Code))
            {
                throw new ValidationException(CourseErrors.EmptyCode);
            }

            if (await _repository.GetByCodeAsync(course.Code) != null)
            {
                throw new ValidationException(CourseErrors.AlreadyExistsCode);
            }

            if (course.PrerequisiteCourseId.HasValue &&
                await _repository.GetAsync(course.PrerequisiteCourseId.Value) == null)
            {
                throw new ValidationException(CourseErrors.InvalidPrerequisiteCourse);
            }

            var createdCourse = await _repository.AddAsync(course);

            await _uow.CommitAsync();

            return(createdCourse);
        }
Ejemplo n.º 20
0
 public async Task HandleAsync(AddCourse command)
 {
     var course = new Course(command.CourseId, command.Title, command.Description, command.Tags,
                             new List <Guid>());
     await _repository.AddAsync(course);
 }
Ejemplo n.º 21
0
        public async Task <Course> AddAsync(Course course)
        {
            var tempCourse = await _courseRepository.AddAsync(course);

            return(tempCourse);
        }
Ejemplo n.º 22
0
        public async Task <Response <CourseAddDto> > AddAsync(Course course)
        {
            await _courseRepository.AddAsync(course);

            return(Response <CourseAddDto> .Success(_mapper.Map <CourseAddDto>(course), 200));
        }
Ejemplo n.º 23
0
        public async Task Add(Course course)
        {
            await _courseRepository.AddAsync(course);

            await _courseRepository.SaveChangesAsync();
        }