// 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)); } }
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); }
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")); }
public async Task <CourseDetailDto> AddCourseWithRelations(CourseDetailDto courseDetailDto) { var course1 = courseDetailDto.CourseDetailDtoToCourse(); var service = await _courseRepository.AddAsync(course1); return(service.CourseToCourseDetailDto()); }
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); }
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(); }
public async Task Add(CourseModel model) { var courseEntity = new CourseEntity { Specialization = model.Specialization }; await _repository.AddAsync(courseEntity); }
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(); }
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(); }
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}")); } }
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); }
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); }
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()); }
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()); }
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 })); }
//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}")); } }
/// <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}")); } }
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); }
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); }
public async Task <Course> AddAsync(Course course) { var tempCourse = await _courseRepository.AddAsync(course); return(tempCourse); }
public async Task <Response <CourseAddDto> > AddAsync(Course course) { await _courseRepository.AddAsync(course); return(Response <CourseAddDto> .Success(_mapper.Map <CourseAddDto>(course), 200)); }
public async Task Add(Course course) { await _courseRepository.AddAsync(course); await _courseRepository.SaveChangesAsync(); }