public async Task <CommandResult> Handle(LeaveCourseCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { return(request.Result); } StudyCourse course = await studyCourseRepository.GetById(request.Id); if (course is null) { AddError("The course doesn't exists."); return(request.Result); } bool userAlreadyEnroled = studyCourseRepository.CheckStudentEnrolled(request.Id, request.UserId); if (!userAlreadyEnroled) { AddError("User not enrolled to this course."); return(request.Result); } await studyCourseRepository.RemoveStudent(request.Id, request.UserId); request.Result.Validation = await Commit(unitOfWork); return(request.Result); }
public async Task <CommandResult> Handle(EnrollCourseCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { return(request.Result); } StudyCourse course = await studyCourseRepository.GetById(request.Id); if (course is null) { AddError("The course doesn't exists."); return(request.Result); } bool userAlreadyEnroled = studyCourseRepository.CheckStudentEnrolled(request.Id, request.UserId); if (userAlreadyEnroled) { AddError("User already enrolled to this course"); return(request.Result); } CourseMember student = new CourseMember { UserId = request.UserId }; await studyCourseRepository.AddStudent(request.Id, student); request.Result.Validation = await Commit(unitOfWork); return(request.Result); }
public void UpdateGroups(StudyCourse studyCourse, StudyGroup newStudyGroup) { if (studyCourse == null) { throw new ArgumentException("Argument 'studyCourse' is null"); } if (newStudyGroup == null) { throw new ArgumentException("Argument 'newStudyGroup' is null"); } bool foundGroup = false; foreach (var studyGroup in studyCourse.Groups) { if (studyGroup.TreeId == newStudyGroup.TreeId) { foundGroup = true; studyGroup.GroupName = newStudyGroup.GroupName; studyGroup.MinimalStudyCount = newStudyGroup.MinimalStudyCount; } } if (!foundGroup) { studyCourse.Groups.Add(newStudyGroup); } }
public void UpdateCourses(StudyProject studyProject, StudyCourse newStudyCourse) { if (studyProject == null) { throw new ArgumentException("Argument 'studyProject' is null"); } if (newStudyCourse == null) { throw new ArgumentException("Argument 'newStudyCourse' is null"); } bool foundCourse = false; foreach (var studyCourse in studyProject.Courses) { if (studyCourse.TreeId == newStudyCourse.TreeId) { foundCourse = true; studyCourse.CourseName = newStudyCourse.CourseName; studyCourse.BackgroundColor = newStudyCourse.BackgroundColor; } } // Add course to project if not exists if (!foundCourse) { studyProject.Courses.Add(newStudyCourse); } }
public async Task <OperationResultVo <Guid> > SaveCourse(Guid currentUserId, CourseViewModel vm) { int pointsEarned = 0; try { StudyCourse model; StudyCourse existing = await mediator.Query <GetCourseByIdQuery, StudyCourse>(new GetCourseByIdQuery(vm.Id)); if (existing != null) { model = mapper.Map(vm, existing); } else { model = mapper.Map <StudyCourse>(vm); } CommandResult result = await mediator.SendCommand(new SaveCourseCommand(model)); if (model.Id == Guid.Empty && result.Validation.IsValid) { pointsEarned += gamificationDomainService.ProcessAction(currentUserId, PlatformAction.CourseAdd); } return(new OperationResultVo <Guid>(model.Id, pointsEarned)); } catch (Exception ex) { return(new OperationResultVo <Guid>(ex.Message)); } }
public void CreateRowsFromStudyCourse(ISheet sheet, StudyCourse studyCourse) { int rowIndex = sheet.LastRowNum + 1; var courseRow = sheet.CreateRow(rowIndex); courseRow.CreateCell(0).SetCellValue("Mācību joma"); courseRow.CreateCell(1).SetCellValue(studyCourse.CourseName); courseRow.CreateCell(2).SetCellValue("10. klase"); courseRow.CreateCell(3).SetCellValue("11. klase"); courseRow.CreateCell(4).SetCellValue("12. klase"); courseRow.CreateCell(5).SetCellValue("KOPĀ"); courseRow.GetCell(0).CellStyle = _greyCellStyle; courseRow.GetCell(1).CellStyle = _greyCellStyle; courseRow.GetCell(2).CellStyle = _greyCenteredCellStyle; courseRow.GetCell(3).CellStyle = _greyCenteredCellStyle; courseRow.GetCell(4).CellStyle = _greyCenteredCellStyle; courseRow.GetCell(5).CellStyle = _greyCenteredCellStyle; foreach (var studyGroup in studyCourse.Groups) { CreateRowsFromStudyGroup(sheet, studyGroup); } }
private void RegisterPageButton_Click(object sender, EventArgs e) { studyCourse = new StudyCourse(studyCourse.ListModules(1), studyCourse.GetStudyCourseStatus(), studyCourse.GetStudyCourseNotes()); RegisterPage registerscreen = new RegisterPage(studyCourse); this.Hide(); registerscreen.Show(); }
private void StudyCourseButton_Click(object sender, EventArgs e) { studyCourse = new StudyCourse(studyCourse.ListModules(1), studyCourse.GetStudyCourseStatus(), studyCourse.GetStudyCourseNotes()); OverviewStudyCourse studycoursescreen = new OverviewStudyCourse(studyCourse); this.Hide(); studycoursescreen.Show(); }
public List <WorkType> Resolve(StudyCourse source, CourseViewModel destination, List <WorkType> destMember, ResolutionContext context) { string[] platforms = (source.SkillSet ?? string.Empty) .Split(new Char[] { '|' }); IEnumerable <WorkType> platformsConverted = platforms.Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => (WorkType)Enum.Parse(typeof(WorkType), x)); return(platformsConverted.ToList()); }
public StudyCourse GenerateNewCourse(Guid userId) { StudyCourse model = new StudyCourse { UserId = userId }; return(model); }
public void UpdateCourses(StudyCourse newStudyCourse) { if (newStudyCourse == null) { throw new ArgumentException("Argument 'newStudyCourse' is null"); } foreach (var studyProject in StudyProjects) { UpdateCourses(studyProject, newStudyCourse); } }
public OperationResultVo GenerateNewCourse(Guid currentUserId) { try { StudyCourse model = studyDomainService.GenerateNewCourse(currentUserId); CourseViewModel newVm = mapper.Map <CourseViewModel>(model); return(new OperationResultVo <CourseViewModel>(newVm)); } catch (Exception ex) { return(new OperationResultVo(ex.Message)); } }
public void UpdateStudies(StudyCourse studyCourse, Study newStudy) { if (studyCourse == null) { throw new ArgumentException("Argument 'studyCourse' is null"); } if (newStudy == null) { throw new ArgumentException("Argument 'newStudy' is null"); } foreach (var studyGroup in studyCourse.Groups) { UpdateStudies(studyGroup, newStudy); } }
public OperationResultVo GenerateNewCourse(Guid currentUserId) { try { StudyCourse model = studyDomainService.GenerateNewCourse(currentUserId); CourseViewModel vm = mapper.Map <CourseViewModel>(model); vm.FeaturedImage = SetFeaturedImage(currentUserId, vm.FeaturedImage, ImageRenderType.Full, Constants.DefaultCourseThumbnail); return(new OperationResultVo <CourseViewModel>(vm)); } catch (Exception ex) { return(new OperationResultVo(ex.Message)); } }
public OperationResultVo <Guid> SaveCourse(Guid currentUserId, CourseViewModel vm) { int pointsEarned = 0; try { StudyCourse model; StudyCourse existing = studyDomainService.GetCourseById(vm.Id); if (existing != null) { model = mapper.Map(vm, existing); } else { model = mapper.Map <StudyCourse>(vm); } if (vm.Id == Guid.Empty) { studyDomainService.AddCourse(model); vm.Id = model.Id; pointsEarned += gamificationDomainService.ProcessAction(currentUserId, PlatformAction.CourseAddition); } else { studyDomainService.UpdateCourse(model); } unitOfWork.Commit(); vm.Id = model.Id; return(new OperationResultVo <Guid>(model.Id, pointsEarned)); } catch (Exception ex) { return(new OperationResultVo <Guid>(ex.Message)); } }
public StudyCourse getCourseById(int id) { sqlConnection = null; sqlConnection = TimeTableDatabase.getConnection(); try { using (sqlConnection) { StudyCourse SQLItem = new StudyCourse(); string SQL = "SELECT [coursetypid],[shortname],[longname]" + " FROM [coursetyp] WHERE [coursetypid] = '" + id.ToString() + "';"; sqlConnection.Open(); SqlDataReader myReader = null; SqlCommand myCommand = new SqlCommand(SQL, sqlConnection); myReader = myCommand.ExecuteReader(); if (myReader.Read()) { SQLItem.ID = Convert.ToInt32(myReader["coursetypid"].ToString()); SQLItem.LongText = myReader["longname"].ToString(); SQLItem.ShortText = myReader["shortname"].ToString(); sqlConnection.Close(); sqlConnection = null; return(SQLItem); } else { sqlConnection.Close(); sqlConnection = null; return(null); } } } catch (System.Exception) { return(null); } }
public async Task <OperationResultVo> GetCourseById(Guid currentUserId, Guid id) { try { StudyCourse existing = await mediator.Query <GetCourseByIdQuery, StudyCourse>(new GetCourseByIdQuery(id)); CourseViewModel vm = mapper.Map <CourseViewModel>(existing); SetAuthorDetails(vm); SetPermissions(currentUserId, vm); vm.FeaturedImage = SetFeaturedImage(vm.UserId, vm.FeaturedImage, ImageRenderType.Full, Constants.DefaultCourseThumbnail); return(new OperationResultVo <CourseViewModel>(vm)); } catch (Exception ex) { return(new OperationResultVo(ex.Message)); } }
public OperationResultVo GetCourseById(Guid currentUserId, Guid id) { try { StudyCourse existing = studyDomainService.GetCourseById(id); CourseViewModel vm = mapper.Map <CourseViewModel>(existing); SetAuthorDetails(vm); SetPermissions(currentUserId, vm); vm.ThumbnailUrl = SetFeaturedImage(currentUserId, vm.ThumbnailUrl, ImageRenderType.Full); return(new OperationResultVo <CourseViewModel>(vm)); } catch (Exception ex) { return(new OperationResultVo(ex.Message)); } }
public StudyCourse[] getAllCourses() { sqlConnection = null; sqlConnection = TimeTableDatabase.getConnection(); try { using (sqlConnection) { StudyCourse SQLItem = new StudyCourse(); List <StudyCourse> list = new List <StudyCourse>(); string SQL = "SELECT [coursetypid],[shortname],[longname]" + " FROM [coursetyp];"; sqlConnection.Open(); SqlDataReader myReader = null; SqlCommand myCommand = new SqlCommand(SQL, sqlConnection); myReader = myCommand.ExecuteReader(); while (myReader.Read()) { SQLItem.ID = Convert.ToInt32(myReader["coursetypid"].ToString()); SQLItem.LongText = myReader["longname"].ToString(); SQLItem.ShortText = myReader["shortname"].ToString(); list.Add(SQLItem); SQLItem = new StudyCourse(); } sqlConnection.Close(); sqlConnection = null; return(list.ToArray()); } } catch (System.Exception) { return(null); } }
public Study FindStudyByTreeId(StudyCourse studyCourse, string treeId) { if (studyCourse == null) { throw new ArgumentException("Argument 'studyCourse' is null"); } if (String.IsNullOrEmpty(treeId)) { throw new Exception("Argument 'treeId' is null or empty!"); } foreach (var studyGroup in studyCourse.Groups) { var study = FindStudyByTreeId(studyGroup, treeId); if (study != null) { return(study); } } return(null); }
public SaveCourseCommand(StudyCourse course) : base(course.Id) { Course = course; }
public void AddCourse(StudyCourse model) { studyCourseRepository.Add(model); }
public void UpdateCourse(StudyCourse model) { studyCourseRepository.Update(model); }