示例#1
0
        public ActionResult Create(CreateCourseModel courseModel)
        {
            if (ModelState.IsValid)
            {
                Course course = new Course();
                //set creator to current user
                course.Creator = db.UserProfiles.Find(WebSecurity.CurrentUserId);
                course.Members = new List <UserProfile>();
                course.Members.Add(course.Creator);

                course.Description = courseModel.Description;
                course.Name        = courseModel.Name;
                course.Image       = courseModel.Image.FileName;

                course             = db.Courses.Add(course);
                course.DateCreated = DateTime.Now;

                //persist changes and refresh so we get an courseId
                course.DateCreated = DateTime.Now;

                db.SaveChanges();
                db.Entry(course).GetDatabaseValues();

                course.Image = FileHelper.SaveFile(courseModel.Image, "Course", course.Id.ToString());

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(courseModel));
        }
示例#2
0
        public IActionResult Create(CreateCourseModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }
            this.courses.Create(model);

            return(this.RedirectToAction(nameof(Courses)));
        }
        public IActionResult CreateCourse(CreateCourseModel createCourseModel)
        {
            Course course = new Course
            {
                Date        = DateTime.Now,
                Subject     = createCourseModel.Subject,
                TeacherName = createCourseModel.TeacherName,
                Inform      = createCourseModel.Inform,
            };

            _courseRepository.Create(course);
            return(CreatedAtRoute("GetId", new { Id = course.Id }, course));
        }
示例#4
0
        public void Create(CreateCourseModel courseModel)
        {
            using (this.db)
            {
                this.db.Courses.Add(new Course
                {
                    Name        = courseModel.Name,
                    Description = courseModel.Description,
                    StartDate   = courseModel.StartDate,
                    EndDate     = courseModel.EndDate,
                });

                this.db.SaveChanges();
            }
        }
示例#5
0
        public IActionResult CreateCourse([FromBody] CreateCourseModel model)
        {
            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }

            var response = _courseService.CreateCourse(CreateCourseModelToCourseMapper.Map(model));

            if (!response.Success)
            {
                return(BadRequest());
            }

            return(Ok(response));
        }
        public JsonResult CreateCourse([DataSourceRequest]  DataSourceRequest request, CreateCourseModel course)
        {
            if (course == null || !ModelState.IsValid)
            {
                return Json(new[] { course }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
            }

            if (course.CourseTypeId <= 0)
            {
                ModelState.AddModelError(nameof(course.CourseTypeId), "Please select course type");
                return Json(new[] { course }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
            }

            var createdCourse = this.coursesServices.CreateCourse(course);

            return Json(new[] { createdCourse }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
        }
        public CourseViewModel CreateCourse(CreateCourseModel course)
        {
            var courseType = this.Data.CourseTypes
                .GetById(course.CourseTypeId);

            var newCourse = new Course()
            {
                Name = course.Name,
                Description = course.Description,
                IndividualCoursePrice = course.IndividualCoursePrice,
                CourseTypeId = course.CourseTypeId
            };

            courseType.Courses.Add(newCourse);
            this.Data.SaveChanges();

            var createdCourse = this.GetCourseById(newCourse.Id);
            return createdCourse;
        }
示例#8
0
        public static Course Map(CreateCourseModel model)
        {
            var newTopics = new Collection <Topic>();

            foreach (var topic in model.Topic)
            {
                newTopics.Add(new Topic
                {
                    Topicname = topic.Topicname
                });
            }

            return(new Course
            {
                CourseName = model.CourseName,
                CourseDescription = model.CourseDescription,
                InstructorId = model.InstructorId,
                Topic = newTopics
            });
        }
示例#9
0
        public ActionResult Create()
        {
            UserGetResponse ugr = _userCom.GetUser(User.Identity.Name);

            ViewBag.User = ugr.firstName + " " + ugr.lastName;
            ///ViewBag.User = MvcApplication.userName;
            CreateCourseModel ccm = new CreateCourseModel();

            ccm.Users = new List <GT.BuddyUp.WebApp.Models.CourseUser>()
            {
                new GT.BuddyUp.WebApp.Models.CourseUser()
                {
                    emailId = User.Identity.Name, role = GT.BuddyUp.WebApp.Models.Role.Teacher
                }
            };
            //ccm.DesiredSkillSets = new List<Skill>() {new Skill() { skill = "Java", requiredSkillLevel = SkillLevel.Beginner} };
            ccm.AvailableTerms = getAvailableTerms();
            ccm.Questions      = new List <GT.BuddyUp.WebApp.Models.Question>();
            return(View(ccm));
        }
示例#10
0
        public async Task <ActionResult> Create(CreateCourseModel model)
        {
            if (ModelState.IsValid)
            {
                CourseAddRequest car = new CourseAddRequest()
                {
                    CourseCode = model.CourseCode,
                    CourseName = model.CourseName,
                    //DesiredSkillSets = model.DesiredSkillSets,
                    GroupSize              = model.GroupSize,
                    CourseDescription      = model.CourseDescription,
                    PreferSimiliarSkillSet = model.PreferSimiliarSkillSet,
                    Term     = model.Term,
                    userList = new List <CourseNewUser>()
                };
                switch (model.GroupType)
                {
                case "Study Group":
                    car.GroupType = "Study";
                    break;

                case "Project Group (Open Projects)":
                    car.GroupType = "OpenProject";
                    break;

                case "Project Group (Closed Projects)":
                    car.GroupType = "ClosedProject";
                    break;
                }

                if (model.Users != null && model.Users.Count > 0)
                {
                    foreach (var user in model.Users)
                    {
                        car.userList.Add(new CourseNewUser()
                        {
                            emailId  = user.emailId,
                            roleCode = user.role.ToString()
                        });
                    }
                }

                bool result = _courseCom.AddCourse(car);
                if (result) //Course is added, now generate intelligent question set and add questionnaire
                {
                    QuestionnaireAddRequest qar = new QuestionnaireAddRequest()
                    {
                        IsATemplate       = false,
                        QuestionnaireCode = DateTime.UtcNow.ToString("MMddyyHmmss"),
                        Questions         = new List <DomainDto.Question>()
                    };
                    List <string> timeZones = TimeZoneInfo.GetSystemTimeZones().Select(x => x.DisplayName).ToList();
                    qar.Questions.Add(new DomainDto.Question()
                    {
                        questionText  = "In what timezone are you mostly available?",
                        questionType  = "MultipleChoice",
                        answerChoices = timeZones
                    });
                    List <string> timeSlots = new List <string>()
                    {
                        "6:00 AM - 9:00 AM",
                        "9:00 AM - 12:00 PM",
                        "12:00 PM - 3:00 PM",
                        "3:00 PM - 6:00 PM",
                        "6:00 PM - 9:00 PM",
                        "9:00 PM - 12:00 AM",
                        "Anytime",
                        "I am not available"
                    };
                    qar.Questions.Add(new DomainDto.Question()
                    {
                        questionText  = "During weekday, what time are you available for group calls?",
                        questionType  = "MultipleChoice",
                        answerChoices = timeSlots
                    });
                    qar.Questions.Add(new DomainDto.Question()
                    {
                        questionText  = "During weekends, what time are you available for group calls?",
                        questionType  = "MultipleChoice",
                        answerChoices = timeSlots
                    });

                    if (model.GenerateIntelligentQuestionnaire)
                    {
                        if (model.DesiredSkillSets != null)
                        {
                            foreach (var skl in model.DesiredSkillSets.Split(','))
                            {
                                qar.Questions.Add(new DomainDto.Question()
                                {
                                    questionText  = "What is your expertise in " + skl.Trim(),
                                    questionType  = "MultipleChoice",
                                    answerChoices = new List <string>()
                                    {
                                        "Beginner", "Intermediate", "Expert"
                                    }
                                });
                            }
                        }
                    }

                    if (model.Questions != null && model.Questions.Count > 0)
                    {
                        foreach (var q in model.Questions)
                        {
                            qar.Questions.Add(new DomainDto.Question()
                            {
                                questionType  = q.QuestionType,
                                questionText  = q.QuestionText,
                                answerChoices = q.AnswerChoices.Split(',').ToList(),
                                Priority      = getPriority(q.Priority)
                            });
                        }
                    }
                    bool res = _questionnaireCom.AddQuestionnaire(qar);
                    if (res)//Questionnaire is added, update course with questionnaire
                    {
                        CourseUpdateRequest cur = new CourseUpdateRequest()
                        {
                            CourseCode        = model.CourseCode,
                            QuestionnaireCode = qar.QuestionnaireCode
                        };
                        bool resp = _courseCom.UpdateCourse(cur);
                        if (!resp)
                        {
                            ModelState.AddModelError("", "Oops! Course was added, but someting wrong happened while adding questionnaire to course");
                            return(View(model));
                        }
                    }
                    //MvcApplication.courses.Add(model.CourseCode, model.CourseName);
                    //MvcApplication.courseDescription.Add(model.CourseCode, model.CourseDescription);
                    return(RedirectToAction("Teacher", "Course"));
                }
            }
            ModelState.AddModelError("", "Oops! Something wrong happened! Please try again.");
            return(View(model));
        }
示例#11
0
        private bool validateCreateCourseModel(CreateCourseModel cm, User owner)
        {
            var newCourse = new Course {
                Name = cm.Name, Description = cm.Description, Owner = owner.UserName
            };

            if (!TryValidateModel(newCourse))
            {
                return(false);
            }

            int fakeId = 0;
            int index  = 0; //used for iterating through files

            try
            {
                var a = cm.Lessons.Count();
                if (cm.Lessons.Count() > 10)
                {
                    return(false);
                }

                foreach (string lesson in cm.Lessons)
                {
                    var newResource = new Resource();
                    {
                        newResource.Path = "./ App_Data / Resources / " + fakeId + " - " + index + ".pdf";
                        newResource.Name = cm.Files[index].FileName;
                    }

                    if (!TryValidateModel(newResource))
                    {
                        return(false);
                    }

                    index++;

                    JObject parsedObject = JObject.Parse(lesson);
                    var     newLesson    = new Lesson
                    {
                        Name        = parsedObject.GetValue("name").ToString(),
                        Description = parsedObject.GetValue("description").ToString(),
                        CourseId    = fakeId,
                        ResourceId  = fakeId
                    };

                    if (!TryValidateModel(newLesson))
                    {
                        return(false);
                    }
                }

                if (cm.Exercises != null) // excercises can be null and valid since they're optional
                {
                    if (cm.Exercises.Count() > 10)
                    {
                        return(false);
                    }

                    foreach (string exercise in cm.Exercises)
                    {
                        JObject parsedObject = JObject.Parse(exercise);
                        var     newExercise  = new Exercise
                        {
                            Name        = parsedObject.GetValue("name").ToString(),
                            Description = parsedObject.GetValue("description").ToString(),
                            CourseId    = fakeId
                        };

                        if (!TryValidateModel(newExercise))
                        {
                            return(false);
                        }

                        if (parsedObject.GetValue("questions").Count() == 0 || parsedObject.GetValue("questions").Count() > 100)
                        {
                            return(false);
                        }

                        foreach (JObject question in parsedObject.GetValue("questions"))
                        {
                            var newQuestion = new Question
                            {
                                Sentence   = question.GetValue("sentence").ToString(),
                                Points     = float.Parse(question.GetValue("points").ToString()),
                                ExerciseId = fakeId
                            };

                            if (!TryValidateModel(newQuestion))
                            {
                                return(false);
                            }

                            if (question.GetValue("answers").Count() < 2 || question.GetValue("answers").Count() > 5)
                            {
                                return(false);
                            }

                            foreach (JObject answer in question.GetValue("answers"))
                            {
                                var newAnswer = new Answer
                                {
                                    Sentence   = answer.GetValue("sentence").ToString(),
                                    IsCorrect  = Convert.ToBoolean(answer.GetValue("isCorrect").ToString()),
                                    QuestionId = fakeId
                                };

                                if (!TryValidateModel(newAnswer))
                                {
                                    return(false);
                                }
                                ;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
示例#12
0
        public async Task <IActionResult> Create([FromForm] CreateCourseModel cm)
        {
            var owner     = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
            var newCourse = new Course {
                Name = cm.Name, Description = cm.Description, Owner = owner.UserName
            };

            bool isValid = validateCreateCourseModel(cm, owner);

            if (!isValid)
            {
                return(Json(new { message = "Course creation failed!" }));
            }

            db.Courses.Add(newCourse);
            db.SaveChanges();

            var courseId = newCourse.Id;
            int index    = 0; //used for iterating through files

            foreach (string lesson in cm.Lessons)
            {
                var resourceId = 0;

                using (var stream = new FileStream("./App_Data/Resources/" + newCourse.Id + "-" + index + ".pdf", FileMode.Create))
                {
                    await cm.Files[index].CopyToAsync(stream);
                    var newResource = new Resource();
                    {
                        newResource.Path = "./App_Data/Resources/" + newCourse.Id + "-" + index + ".pdf";
                        newResource.Name = cm.Files[index].FileName;
                    }

                    db.Resources.Add(newResource);
                    db.SaveChanges();
                    index++;
                    resourceId = newResource.Id;
                }

                JObject parsedObject = JObject.Parse(lesson);
                var     newLesson    = new Lesson
                {
                    Name        = parsedObject.GetValue("name").ToString(),
                    Description = parsedObject.GetValue("description").ToString(),
                    CourseId    = courseId,
                    ResourceId  = resourceId
                };

                db.Lessons.Add(newLesson);
                db.SaveChanges();
            }

            if (cm.Exercises != null)
            {
                foreach (string exercise in cm.Exercises)
                {
                    JObject parsedObject = JObject.Parse(exercise);
                    var     newExercise  = new Exercise
                    {
                        Name        = parsedObject.GetValue("name").ToString(),
                        Description = parsedObject.GetValue("description").ToString(),
                        CourseId    = courseId
                    };

                    db.Exercises.Add(newExercise);
                    db.SaveChanges();

                    var exerciseId = newExercise.Id;

                    foreach (JObject question in parsedObject.GetValue("questions"))
                    {
                        var newQuestion = new Question
                        {
                            Sentence   = question.GetValue("sentence").ToString(),
                            Points     = float.Parse(question.GetValue("points").ToString()),
                            ExerciseId = exerciseId
                        };

                        db.Questions.Add(newQuestion);
                        db.SaveChanges();

                        var questionId = newQuestion.Id;

                        foreach (JObject answer in question.GetValue("answers"))
                        {
                            var newAnswer = new Answer
                            {
                                Sentence   = answer.GetValue("sentence").ToString(),
                                IsCorrect  = Convert.ToBoolean(answer.GetValue("isCorrect").ToString()),
                                QuestionId = questionId
                            };

                            db.Answers.Add(newAnswer);
                            db.SaveChanges();
                        }
                    }
                }
            }
            return(Json(new { message = "Success!" }));
        }
示例#13
0
        public async Task <IActionResult> Update([FromForm] UpdateCourseModel cm)
        {
            var owner             = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
            var createCourseModel = new CreateCourseModel
            {
                Name        = cm.Name,
                Description = cm.Description,
                Lessons     = cm.Lessons,
                Exercises   = cm.Exercises,
                Files       = (List <IFormFile>)cm.Files
            };

            bool isValid = validateCreateCourseModel(createCourseModel, owner);

            if (!isValid)
            {
                return(Json(new { message = "Course update failed!" }));
            }

            var appPath = PlatformServices.Default.Application.ApplicationBasePath;

            appPath = appPath.Remove(appPath.Length - 24);

            var updateCourse = db.Courses.FirstOrDefault(c => c.Id == cm.Id);

            updateCourse.Name        = cm.Name;
            updateCourse.Description = cm.Description;
            db.Courses.Update(updateCourse);
            db.SaveChanges();

            var existingResourceIds = db.Lessons.Where(l => l.CourseId == updateCourse.Id).Select(l => l.ResourceId).ToList();

            foreach (int resourceId in existingResourceIds)
            {
                string path = db.Resources.Where(r => r.Id == resourceId).Select(r => r.Path).ToString();
                System.IO.File.Delete(@path);
            }

            JObject toRemove = JObject.Parse(cm.Removed);

            foreach (JValue lessonId in toRemove.GetValue("lessonIds"))
            {
                int id             = int.Parse(lessonId.ToString());
                var removeLesson   = db.Lessons.FirstOrDefault(a => a.Id == id);
                var removeResource = db.Resources.FirstOrDefault(r => r.Id == removeLesson.ResourceId);
                db.Lessons.Remove(removeLesson);
                db.SaveChanges();
                db.Resources.Remove(removeResource);
                db.SaveChanges();
            }
            foreach (JValue exerciseId in toRemove.GetValue("exerciseIds"))
            {
                int id             = int.Parse(exerciseId.ToString());
                var removeExercise = db.Exercises.First(a => a.Id == id);
                db.Exercises.Remove(removeExercise);
                db.SaveChanges();
            }
            foreach (JValue questionId in toRemove.GetValue("questionIds"))
            {
                int id             = int.Parse(questionId.ToString());
                var removeQuestion = db.Questions.First(a => a.Id == id);
                db.Questions.Remove(removeQuestion);
                db.SaveChanges();
            }
            foreach (JValue answerId in toRemove.GetValue("answerIds"))
            {
                int id           = int.Parse(answerId.ToString());
                var removeAnswer = db.Answers.First(a => a.Id == id);
                db.Answers.Remove(removeAnswer);
                db.SaveChanges();
            }

            var courseId = updateCourse.Id;
            int index    = 0; //used for iterating through files

            foreach (string lesson in cm.Lessons)
            {
                using (var stream = new FileStream("./App_Data/Resources/" + updateCourse.Id + "-" + index + ".pdf", FileMode.Create))//create new file
                {
                    await cm.Files[index].CopyToAsync(stream);
                }

                JToken  result;
                JObject parsedObject = JObject.Parse(lesson);
                if (parsedObject.TryGetValue("id", out result))
                {
                    int lessonId     = int.Parse(parsedObject.GetValue("id").ToString());
                    var updateLesson = db.Lessons.FirstOrDefault(l => l.Id == lessonId);
                    updateLesson.Name        = parsedObject.GetValue("name").ToString();
                    updateLesson.Description = parsedObject.GetValue("description").ToString();
                    db.Lessons.Update(updateLesson);
                    db.SaveChanges();

                    var updateResource = db.Resources.FirstOrDefault(r => r.Id == updateLesson.ResourceId);

                    updateResource.Name = cm.Files[index].FileName;
                    updateResource.Path = "./App_Data/Resources/" + updateCourse.Id + "-" + index + ".pdf";
                    db.Resources.Update(updateResource);
                    db.SaveChanges();
                }
                else
                {
                    var newResource = new Resource();
                    {
                        newResource.Path = "./App_Data/Resources/" + updateCourse.Id + "-" + index + ".pdf";
                        newResource.Name = cm.Files[index].FileName;
                    }

                    db.Resources.Add(newResource);
                    db.SaveChanges();
                    int resourceId = newResource.Id;

                    var newLesson = new Lesson
                    {
                        Name        = parsedObject.GetValue("name").ToString(),
                        Description = parsedObject.GetValue("description").ToString(),
                        CourseId    = courseId,
                        ResourceId  = resourceId // if its new lesson cm[Files] will be different than null since user will have to provide a file
                    };

                    db.Lessons.Add(newLesson);
                    db.SaveChanges();
                }
                index++;
            }

            if (cm.Exercises != null)
            {
                foreach (string exercise in cm.Exercises)
                {
                    int     exerciseId;
                    JToken  result;
                    JObject parsedObject = JObject.Parse(exercise);
                    if (parsedObject.TryGetValue("id", out result))
                    {
                        var updateExercise = db.Exercises.FirstOrDefault(l => l.Id == int.Parse(parsedObject.GetValue("id").ToString()));
                        updateExercise.Name        = parsedObject.GetValue("name").ToString();
                        updateExercise.Description = parsedObject.GetValue("description").ToString();

                        db.Exercises.Update(updateExercise);
                        db.SaveChanges();

                        exerciseId = updateExercise.Id;
                    }
                    else
                    {
                        var newExercise = new Exercise
                        {
                            Name        = parsedObject.GetValue("name").ToString(),
                            Description = parsedObject.GetValue("description").ToString(),
                            CourseId    = updateCourse.Id
                        };

                        db.Exercises.Add(newExercise);
                        db.SaveChanges();

                        exerciseId = newExercise.Id;
                    }
                    foreach (JObject question in parsedObject.GetValue("questions"))
                    {
                        int questionId;
                        if (question.TryGetValue("id", out result))
                        {
                            var updateQuestion = db.Questions.FirstOrDefault(q => q.Id == int.Parse(question.GetValue("id").ToString()));
                            updateQuestion.Sentence = question.GetValue("sentence").ToString();
                            updateQuestion.Points   = float.Parse(question.GetValue("points").ToString());

                            db.Questions.Update(updateQuestion);
                            db.SaveChanges();

                            questionId = updateQuestion.Id;
                        }
                        else
                        {
                            var newQuestion = new Question
                            {
                                Sentence   = question.GetValue("sentence").ToString(),
                                Points     = float.Parse(question.GetValue("points").ToString()),
                                ExerciseId = exerciseId
                            };

                            db.Questions.Add(newQuestion);
                            db.SaveChanges();

                            questionId = newQuestion.Id;
                        }

                        foreach (JObject answer in question.GetValue("answers"))
                        {
                            if (answer.TryGetValue("id", out result))
                            {
                                var updateAnswer = db.Answers.FirstOrDefault(a => a.Id == int.Parse(answer.GetValue("id").ToString()));
                                updateAnswer.Sentence  = answer.GetValue("sentence").ToString();
                                updateAnswer.IsCorrect = Convert.ToBoolean(answer.GetValue("isCorrect").ToString());

                                db.Answers.Update(updateAnswer);
                                db.SaveChanges();
                            }
                            else
                            {
                                var newAnswer = new Answer
                                {
                                    Sentence   = answer.GetValue("sentence").ToString(),
                                    IsCorrect  = Convert.ToBoolean(answer.GetValue("isCorrect").ToString()),
                                    QuestionId = questionId
                                };

                                db.Answers.Add(newAnswer);
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }
            return(Json(new { message = "Success!" }));
        }