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);
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
        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());
        }
Esempio n. 10
0
        public StudyCourse GenerateNewCourse(Guid userId)
        {
            StudyCourse model = new StudyCourse
            {
                UserId = userId
            };

            return(model);
        }
Esempio n. 11
0
        public void UpdateCourses(StudyCourse newStudyCourse)
        {
            if (newStudyCourse == null)
            {
                throw new ArgumentException("Argument 'newStudyCourse' is null");
            }

            foreach (var studyProject in StudyProjects)
            {
                UpdateCourses(studyProject, newStudyCourse);
            }
        }
Esempio n. 12
0
        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));
            }
        }
Esempio n. 13
0
        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);
            }
        }
Esempio n. 14
0
        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));
            }
        }
Esempio n. 15
0
        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));
            }
        }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
        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));
            }
        }
Esempio n. 18
0
        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));
            }
        }
Esempio n. 19
0
        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);
            }
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
 public SaveCourseCommand(StudyCourse course) : base(course.Id)
 {
     Course = course;
 }
Esempio n. 22
0
 public void AddCourse(StudyCourse model)
 {
     studyCourseRepository.Add(model);
 }
Esempio n. 23
0
 public void UpdateCourse(StudyCourse model)
 {
     studyCourseRepository.Update(model);
 }