예제 #1
0
        public async Task <Courses> CreateCourse(CourseCreateModel courseCreateModel)
        {
            //if(courseCreateModel.TeacherProfile.TeacherId )

            var course = new Courses()
            {
                CourseName   = courseCreateModel.CourseName,
                Description  = courseCreateModel.Description,
                CourseTypeId = courseCreateModel.CourseType,
                Teacher      = new TeacherProfile
                {
                    TeacherId = courseCreateModel.TeacherId,
                }
            };

            var courses = await _dbContext.Courses.AddAsync(course);

            _dbContext.SaveChanges();
            return(course);
        }
예제 #2
0
        public ActionResult Create()
        {
            var courseCreateModel = new CourseCreateModel();
            var users             = UserManager.Users.ToList();
            var tutors            = users.Where(user => UserManager.IsInRoleAsync(user.Id, ElectiveBLL.Constants.TUTOR_ROLE_NAME).Result);

            courseCreateModel.TutorSelectList = tutors.Select(tutor => new SelectListItem()
            {
                Value = tutor.Id,
                Text  = string.Format("{0} {1} {2}", tutor.FirstName, tutor.SecondName, tutor.UserName)
            });

            var subjects = SubjectManager.Subjects.ToList();

            courseCreateModel.SubjectSelectList = subjects.Select(subject => new SelectListItem()
            {
                Value = subject.SubjectName,
                Text  = subject.SubjectName
            });
            return(View(courseCreateModel));
        }
예제 #3
0
 public async Task <ActionResult <Response> > Create(CourseCreateModel model)
 {
     return(await _courseService.Create(model, User));
 }
예제 #4
0
        public async Task <ActionResult> Create(CourseCreateModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var course = new Course()
                    {
                        CourseName = model.CourseName, EndDate = model.EndDate, StartDate = model.StartDate
                    };
                    var result = await CourseManager.CreateAsync(course);

                    if (!result.Succeeded)
                    {
                        log.Info("Cannot create course");
                        AddErrors(result);
                        return(View("Create", model));
                    }

                    if (model.Subjects != null)
                    {
                        result = await CourseManager.AddToSubjectsAsync(course.Id, model.Subjects.ToArray());

                        if (!result.Succeeded)
                        {
                            log.Info("Cannot add course to subjects");
                            AddErrors(result);
                            return(View("Create", model));
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(model.TutorId))
                    {
                        result = await UserManager.AddToCourseAsync(model.TutorId, course.Id, true);

                        if (!result.Succeeded)
                        {
                            log.Info("Cannot add tutor to course");
                            AddErrors(result);
                            return(View("Create", model));
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Failed to create course", ex);
                    return(RedirectToAction("InternalError", "Error"));
                }
                return(RedirectToAction("Index", "Course"));
            }

            try
            {
                var users  = UserManager.Users.ToList();
                var tutors = users.Where(user => UserManager.IsInRoleAsync(user.Id, ElectiveBLL.Constants.TUTOR_ROLE_NAME).Result);
                model.TutorSelectList = tutors.Select(tutor => new SelectListItem()
                {
                    Value = tutor.Id,
                    Text  = string.Format("{0} {1} {2}", tutor.FirstName, tutor.SecondName, tutor.UserName)
                });

                var subjects = SubjectManager.Subjects.ToList();
                model.SubjectSelectList = subjects.Select(subject => new SelectListItem()
                {
                    Value = subject.SubjectName,
                    Text  = subject.SubjectName
                });
            }
            catch (Exception ex)
            {
                log.Error("Failed to turn users and courses into courseCreateModel", ex);
                return(RedirectToAction("InternalError", "Error"));
            }
            return(View("Create", model));
        }