Exemplo n.º 1
0
        /// <summary>
        /// Shows the course data specified for what course the user is in and based off of
        /// the pairing.
        /// </summary>
        /// <param name="courseID"></param>
        /// <returns></returns>
        #region Handlers
        public async Task <IActionResult> OnGetAsync(int courseID)
        {
            //gets the course from the database based off of the course ID.
            Course = await _context.GetCourseAsync(courseID);

            //Gets the Client profile by passing in their username to the GetClientAsync
            //function in the applicationDbContext
            var appUser = await _context.GetClientAsync(Username);

            //Sets the appuser as a Client
            var client = appUser.Client;

            //checks to see if the course exists or if the course exists
            //if not then returns message saying not able to find course id for that specified user
            if (Course == null || client == null)
            {
                return(NotFound($"Unable to course user with ID '{courseID}' for user {Username}"));
            }

            //checks to see if the Client ID for the user matches the one associated with course
            //if not then returns error message telling the user they cannot find the user id for that
            //course
            else if (Course.Pair.ClientID != client.ID)
            {
                return(NotFound($"Unable to course user with ID '{courseID}' for user {Username}"));
            }

            else
            {
                return(Page());
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var courseID = id.GetValueOrDefault();

            Course = await _context.GetCourseAsync(courseID);

            var appUser = await _context.GetMentorAsync(Username);

            var mentor = appUser.Mentor;

            await CheckRole(_context, _userManager, Course.Pair.JoinCode);

            if (Course == null || mentor == null)
            {
                return(NotFound($"Unable to course user with ID '{courseID}' for user {Username}"));
            }
            else if (Course.Pair.MentorID != mentor.ID)
            {
                return(NotFound($"Unable to course user with ID '{courseID}' for user {Username}"));
            }

            else
            {
                return(Page());
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Edit(Course course)
        {
            if (ModelState.IsValid)
            {
                var cCourse = await _courseRepository.GetAsync(course.Id);

                if (cCourse == null)
                {
                    var nCourse = new Data.Course
                    {
                        ShortName = course.ShortName,
                        FullName  = course.FullName
                    };
                    await _courseRepository.InsertAsync(nCourse);
                }
                else
                {
                    cCourse.ShortName = course.ShortName;
                    cCourse.FullName  = course.FullName;
                    await _courseRepository.UpdateAsync(cCourse);
                }


                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 4
0
        public void Store(CourseVM courseVM)
        {
            // VALIDATE IF ALREADY EXITS THIS COURSE
            var existingCourse = _courseRepository.GetCourse(courseVM.Name);

            if (existingCourse != null)
            {
                throw new ArgumentException("Course already exists");
            }

            // VALIDATE TARGET AUDIENCE
            if (!Enum.TryParse <TargetAudience>(courseVM.TargetAudience, out var targetAudicence))
            {
                throw new ArgumentException("Invalid Target Audience");
            }

            // PREPARE DATA
            var course = new Data.Course(courseVM.Name,
                                         courseVM.Description,
                                         courseVM.Workload,
                                         targetAudicence,
                                         courseVM.Value);

            // RESULT
            _courseRepository.Store(course);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync()
        {
            var mentor = await _context.GetMentorAsync(Username);

            var mentorID = mentor.Mentor.ID;
            var pair     = await _context.GetPairAsync(mentorID, JoinCode);

            if (pair == null)
            {
                return(NotFound());
            }

            var pairID = pair.PairID;


            var course = new Data.Course
            {
                CourseName = CourseName,
                PairID     = pairID,
                StartDate  = StartDate,
                EndDate    = EndDate
            };

            var success = await _context.AddCourseAsync(course);

            if (!success)
            {
                return(RedirectToPage("/Error"));
            }

            var dbCourse = await _context.GetCourseAsync(course);

            var courseID = dbCourse.CourseID;

            var subject = course.CourseName + " New Course Created";
            var message = $"<h1>Hello!</h1> <p>A new course: {course.CourseName} was just created<p/>.";

            var protege = await _context.GetProtegeByIDAsync(course.Pair.ProtegeID);

            var client = await _context.GetClientByIDAsync(course.Pair.ClientID);

            if (protege != null)
            {
                await _emailSender.SendEmailAsync(protege.AppUser.Email, subject, message);
            }
            if (mentor != null)
            {
                await _emailSender.SendEmailAsync(mentor.Email, subject, message);
            }
            if (client != null)
            {
                await _emailSender.SendEmailAsync(client.AppUser.Email, subject, message);
            }

            return(RedirectToPage("./Index", new { id = courseID }));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 拆分课时
        /// </summary>
        /// <param name="course"></param>
        /// <returns></returns>
        private IList <Data.Course> SplitCourses(Data.Course course)
        {
            var result = new List <Data.Course>();

            if (course.ClassHour == 1)
            {
                result.Add(course);
                return(result);
            }

            if (course.ClassHour > 1)
            {
                //开始时间匹配
                var duration = _schedule.FirstOrDefault(p => p.Start == course.StartTime);
                if (duration == null)
                {
                    throw new Exception("未找到对应时段");
                }

                for (var index = duration.Index; index < duration.Index + course.ClassHour; index++)
                {
                    var tempDuration = _schedule.FirstOrDefault(p => p.Index == index);
                    if (duration == null)
                    {
                        throw new Exception("未找到对应时段");
                    }
                    var tempCourse = new Data.Course();
                    tempCourse.Category       = course.Category;
                    tempCourse.Region         = course.Region;
                    tempCourse.Group          = course.Group;
                    tempCourse.CourseName     = course.CourseName;
                    tempCourse.CourseDetail   = course.CourseDetail;
                    tempCourse.Lecturer       = course.Lecturer;
                    tempCourse.LecturerDetail = course.LecturerDetail;
                    tempCourse.Date           = course.Date;
                    tempCourse.StartTime      = tempDuration.Start;
                    tempCourse.EndTime        = tempDuration.End;
                    tempCourse.ClassHour      = 1;
                    tempCourse.MaxNumber      = course.MaxNumber;
                    tempCourse.Class          = course.Class;
                    tempCourse.Sector         = course.Sector;
                    tempCourse.Career         = course.Career;
                    result.Add(tempCourse);
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        private async Task FillDB(DetiContext db)
        {
            var user = await _db.Users.FirstOrDefaultAsync(u => u.Login == "hackadmin" && u.Password == Util.GetEncryptedBytes("hackadmin"));

            if (user == null)
            {
                var admin = new Data.User()
                {
                    Login      = "******",
                    Password   = Util.GetEncryptedBytes("hackadmin"),
                    FirstName  = "--", LastName = "---",
                    MiddleName = "---", Role =
                        Role.Admin
                };

                var profession = new Data.Profession()
                {
                    Name         = "test prof",
                    ImgURL       = @"https://sun9-29.userapi.com/1-WgAmlkOwd-1_sW7Wp_uUlWFEjHdkAsZLxiLg/JCI0QEBnKX8.jpg",
                    ProfessionID = 0
                };

                var category = new Data.Category()
                {
                    ImgURL     = @"https://sun9-29.userapi.com/1-WgAmlkOwd-1_sW7Wp_uUlWFEjHdkAsZLxiLg/JCI0QEBnKX8.jpg",
                    Name       = "test cat",
                    CategoryID = 0
                };

                _db.ProfessionCategories.Add(new ProfessionCategory()
                {
                    Category = category, Profession = profession
                });

                var course = new Data.Course()
                {
                };


                _db.Users.Add(admin);
                await _db.SaveChangesAsync();
            }
            ;
        }
Exemplo n.º 8
0
        private async Task HandleQuestionWorkflow(IDialogContext context, Microsoft.Bot.Connector.Activity activity, Data.Course course, QuestionModel questionModel)
        {
            var       predictiveQnAService = new PredictiveQnAService(course.Id);
            QnAAnswer response             = await predictiveQnAService.GetAnswer(questionModel.QuestionText);

            // if result, check confidence level
            if (response != null && response.Score > Convert.ToDouble(course.PredictiveQnAConfidenceThreshold))
            {
                await HandleBotAnswerWorkflow(context, activity, questionModel, response, questionModel.TeamId);
            }
            else
            {
                // a score of 0 or a score below threshold both result in regular workflow
                await HandleTagAdminWorkflow(activity, questionModel, questionModel.TeamId, course.Id);
            }
        }
Exemplo n.º 9
0
        private async Task FillDB(DetiContext db)
        {
            var user = await _db.Users.FirstOrDefaultAsync(u => u.Login == "hackadmin" && u.Password == Util.GetEncryptedBytes("hackadmin"));

            if (user == null)
            {
                var admin = new Data.User()
                {
                    Login      = "******",
                    Password   = Util.GetEncryptedBytes("hackadmin"),
                    FirstName  = "--", LastName = "---",
                    MiddleName = "---", Role =
                        Role.Admin
                };

                var profession = new Data.Profession()
                {
                    Name         = "Программист",
                    ImgURL       = @"https://sun9-29.userapi.com/1-WgAmlkOwd-1_sW7Wp_uUlWFEjHdkAsZLxiLg/JCI0QEBnKX8.jpg",
                    ProfessionID = 0
                };

                var profession1 = new Data.Profession()
                {
                    Name         = "Специалист по VR",
                    ImgURL       = @"https://sun9-29.userapi.com/1-WgAmlkOwd-1_sW7Wp_uUlWFEjHdkAsZLxiLg/JCI0QEBnKX8.jpg",
                    ProfessionID = 0
                };

                var category = new Data.Category()
                {
                    ImgURL     = @"https://sun9-29.userapi.com/1-WgAmlkOwd-1_sW7Wp_uUlWFEjHdkAsZLxiLg/JCI0QEBnKX8.jpg",
                    Name       = "Информационные технологии",
                    CategoryID = 0
                };

                _db.ProfessionCategories.Add(new ProfessionCategory()
                {
                    Category = category, Profession = profession
                });
                _db.ProfessionCategories.Add(new ProfessionCategory()
                {
                    Category = category, Profession = profession1
                });

                var course = new Data.Course()
                {
                    Name            = "Изучение основ Java",
                    Address         = "ул. Пушкина д. 10а",
                    ApproxTime      = "15",
                    DifficultyLevel = "2",
                    ImgURL          = "http://www.juntech.ru/sites/default/files/inline-images/java.png",
                    Info            = "На занятиях этого направления Вы: " +
                                      "- познакомитесь с синтаксисом языка; " +
                                      "- рассмотрите элементы объектно-ориентированного программирования; " +
                                      "- поработаете с данными и алгоритмами; " +
                                      "- изучите графику и интерфейсы;" +
                                      "-освоите один из самых популярных языков. " +
                                      "Рекомендовано для 12 - 18 лет.",
                    ScheduleList = new List <Schedule>()
                    {
                        new Schedule()
                        {
                            Marker = "ПН-ПТ",
                            Time   = "15:30"
                        },
                        new Schedule()
                        {
                            Marker = "СБ",
                            Time   = "12:10"
                        }
                    },
                };

                var course1 = new Data.Course()
                {
                    Name            = "Разработка VR и AR приложений",
                    Address         = "ул. Пушкина д. 10а",
                    ApproxTime      = "21",
                    DifficultyLevel = "5",
                    ImgURL          = "http://www.juntech.ru/sites/default/files/inline-images/%D0%B2%D0%B8%D0%B0%D1%80.png",
                    Info            = "На занятиях этого направления Вы: " +
                                      "- научитесь разбираться в технологиях и адаптировать их под свои проекты; " +
                                      "- будете применять самостоятельные разработки приложений виртуальной (VR), дополненной (AR) и смешанной (MR) реальности для различных устройств; " +
                                      "- разберете приемы программирования в контексте игрового движка Unity. " +
                                      "- освоите ААА-пайплайн в 3D- моделировании (разработка lowpoly-модели с разверткой и простой текстурой). " +
                                      "Рекомендовано для 12 - 18 лет.",
                    ScheduleList = new List <Schedule>()
                    {
                        new Schedule()
                        {
                            Marker = "ПН-ПТ",
                            Time   = "13:20"
                        },
                        new Schedule()
                        {
                            Marker = "СБ",
                            Time   = "10:00"
                        }
                    },
                };

                var skill = new Skill()
                {
                    Name = "Программирование"
                };
                _db.ProfessionCourses.Add(new ProfessionCourse()
                {
                    Profession = profession, Course = course
                });
                _db.ProfessionCourses.Add(new ProfessionCourse()
                {
                    Profession = profession, Course = course1
                });
                _db.CourseSkills.Add(new CourseSkills()
                {
                    Course = course, Skill = skill
                });
                _db.CourseSkills.Add(new CourseSkills()
                {
                    Course = course1, Skill = skill
                });
                _db.Users.Add(admin);
                await _db.SaveChangesAsync();
            }
            ;
        }
Exemplo n.º 10
0
        /// <summary>
        /// 从Excel解析课程数据
        /// </summary>
        /// <param name="excelStream"></param>
        /// <returns></returns>
        public IList <Data.Course> ParseFromExcel(Stream excelStream)
        {
            XSSFWorkbook workbook = new XSSFWorkbook(excelStream);
            //获取excel的第一个sheet
            ISheet sheet = workbook.GetSheetAt(0);
            IList <Data.Course> courseList = new List <Data.Course>();

            IEnumerator rows = sheet.GetRowEnumerator();

            while (rows.MoveNext())
            {
                IRow row = (IRow)rows.Current;
                if (row.RowNum == 0)
                {
                    continue;                 //第一行表头,跳过
                }
                if (row == null)
                {
                    break;             //读到
                }
                var rowIndex = sheet.PhysicalNumberOfRows;

                var tempCourse = new Data.Course();
                tempCourse.Category       = row.GetCell(0)?.StringCellValue;
                tempCourse.Region         = row.GetCell(1)?.StringCellValue;
                tempCourse.Group          = row.GetCell(2)?.StringCellValue;
                tempCourse.CourseName     = row.GetCell(3)?.StringCellValue;
                tempCourse.CourseDetail   = row.GetCell(4)?.StringCellValue;
                tempCourse.Lecturer       = row.GetCell(5)?.StringCellValue;
                tempCourse.LecturerDetail = row.GetCell(6)?.StringCellValue;
                tempCourse.Date           = row.GetCell(7)?.DateCellValue;
                tempCourse.StartTime      = row.GetCell(8)?.DateCellValue.ToShortTimeString();
                tempCourse.EndTime        = row.GetCell(9)?.DateCellValue.ToShortTimeString();
                tempCourse.ClassHour      = (int)row.GetCell(10)?.NumericCellValue;
                tempCourse.MaxNumber      = (int)row.GetCell(11)?.NumericCellValue;
                tempCourse.Class          = row.GetCell(12)?.StringCellValue;
                if (row.GetCell(13).NumericCellValue.ToString() == "1")
                {
                    tempCourse.Sector = "17-19";
                }

                if (row.GetCell(14).NumericCellValue.ToString() == "1")
                {
                    tempCourse.Career = "17-19";
                }

                if (row.GetCell(15).NumericCellValue.ToString() == "1")
                {
                    tempCourse.Career = "16-18";
                }

                if (row.GetCell(16).NumericCellValue.ToString() == "1")
                {
                    tempCourse.MainTeacher = true;
                }

                courseList.Add(tempCourse);
            }


            return(courseList);
        }