public async Task <IActionResult> Create(CourseVm model) { if (ModelState.IsValid) { var course = new Course() { Name = model.Name, ShortName = model.ShortName, StartDate = model.StartDate, EndDate = model.EndDate, ShortDescription = model.ShortDescription, Description = model.Description, Status = CourseStatus.Created, CreatedDate = DateTime.Now, LastUpdated = DateTime.Now, Tag = model.Tag, NumberOfModule = model.NumberOfModule }; if (model.Image != null) { course.Image = hostingEnvironment.UploadFileToFolder(model.Image); } _context.Add(course); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <ApiResult <CourseVm> > GetCourseById(int id) { var course = await _context.Courses.FindAsync(id); if (course == null) { return(new ApiErrorResult <CourseVm>("Không tìm thấy ")); } var teacher = await _context.Teachers.FindAsync(course.Id_Teacher); var subject = await _context.Subjects.FindAsync(course.Id_Subject); var data = new CourseVm() { Id_Course = course.Id_Course, Name = course.Name, NameTeacher = teacher.FullName, NameSubject = subject.Name, DateBegin = course.DateBegin, DateEnd = course.DateEnd, SchoolYear = course.SchoolYear, Semester = course.Semester, DateCreate = course.DateCreate, DateUpdate = course.DateUpdate, }; return(new ApiSuccessResult <CourseVm>(data)); }
public async Task <CourseVm> GetCourseById(int id) { Course courseEntity = await _dbContext.Courses.SingleAsync(x => x.Id == id); CourseVm courseVm = CourseVm.FromEntity(courseEntity); return(courseVm); }
public async Task <IEnumerable <CourseVm> > GetAllCourses() { IEnumerable <Course> courseEntities = await _dbContext.Courses.ToListAsync(); IEnumerable <CourseVm> courseVms = courseEntities.Select(x => CourseVm.FromEntity(x)); return(courseVms); }
/// <summary> /// Get course details with students that are enrolled in this course. /// </summary> public async Task <CourseVm> GetCourseWithStudents(int courseId) { Course courseEntity = await _dbContext.Courses. Include(x => x.Students). SingleAsync(x => x.Id == courseId); CourseVm courseVm = CourseVm.FromEntity(courseEntity); return(courseVm); }
public async Task <IActionResult> CreateCourse([FromBody] CourseVm vm) { var desc = vm.Description; var c = new CourseVm(); c.Description = desc; var course = Mapper.Map <Course>(c); await _regentsMongoContext.Courses.InsertOneAsync(course); return(Ok()); }
// GET: Courses/Create public IActionResult Create() { var Courses = new CourseVm(); ViewBag.NoOfModules = Enumerable.Range(1, 15).Select(e => new SelectListItem() { Text = e.ToString(), Value = e.ToString() }).ToArray(); return(View(Courses)); }
/// <summary> /// Get course details with students that aren't enrolled in this course. /// </summary> public async Task <CourseVm> GetCourseWithStudentsToAdd(int courseId) { Course courseEntity = await _dbContext.Courses. Include(x => x.Students). SingleOrDefaultAsync(x => x.Id == courseId); // Exclude students that are already enrolled in this course. IList <int> studentToExcludeIds = courseEntity.Students.Select(x => x.Id).ToList(); IList <Student> studentsToAdd = await _dbContext.Students. Where(x => studentToExcludeIds.Contains(x.Id) == false). ToListAsync(); // Course class is used as "add student model". Students property has different meaning. It represents students that currently aren't enrolled in course - potential course candidates. // Replace enrolled students with course candidates. courseEntity.Students = studentsToAdd; CourseVm addStudentVm = CourseVm.FromEntity(courseEntity); return(addStudentVm); }
public async Task <IActionResult> Details(int id) { CourseVm course = await _courseRepository.GetCourseById(id); return(View(course)); }
public object EditCourse(CourseVm data) { var currUser = dispatcher.Query(new GetEntitiesQuery<Teacher>()).First(t => RouteData != null && t.Email == RouteData.Values["user"].ToString()); if (currUser.IsAdmin != null && (bool)!currUser.IsAdmin) RedirectToAction("Login", "Account"); if (data.LanguageName == null && !data.LanguageName.IsNotEmpty()) { Response.TrySkipIisCustomErrors = true; Response.StatusCode = 400; return "Язык введён некорректно!"; } var course = new Language(); if (data.Id != null) course = dispatcher.Query(new GetEntityByIdQuery<Language>(data.Id)); course.LanguageName = data.LanguageName; if (data.IconFile != null && data.IconFile.IsEmpty()) { var file = data.IconFile; if (file != null && file.ContentLength != 0) { const string imageDirectory = "Content\\images\\"; var path = AppDomain.CurrentDomain.BaseDirectory + imageDirectory; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var filename = course.LanguageName + Path.GetExtension(file.FileName); file.SaveAs(path + filename); course.IconPath = "\\" + imageDirectory + filename; } } dispatcher.Push(new EditCourseCommand(course)); var lenguages = dispatcher.Query(new GetEntitiesQuery<Language>()); var lenguagesVm = lenguages.Select(lenguage => new CourseVm(lenguage)).ToList(); return PartialView("Language/_AdminLanguagesList", lenguagesVm); }
public ActionResult EditLanguageModal(int id = 0) { if (id == 0) return View("Language/_EditLanguageModal"); var lenguage = dispatcher.Query(new GetEntityByIdQuery<Language>(id)); var lenguageVm = new CourseVm(lenguage); return View("Language/_EditLanguageModal", lenguageVm); }
public async Task <IActionResult> AddStudent(int courseId) { CourseVm addStudentModel = await _courseRepository.GetCourseWithStudentsToAdd(courseId); return(View(addStudentModel)); }
public async Task <IActionResult> Index(int courseId) { CourseVm course = await _courseRepository.GetCourseWithStudents(courseId); return(View(course)); }