public async Task<ActionResult> CreateResource(CourseResourceViewModel form, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { var fileName = Path.GetFileName(file.FileName); if (fileName != null) { var destinationPath = Path.Combine(Server.MapPath("~/Content/Resources"), fileName); file.SaveAs(destinationPath); } form.Resource.UploadedFileName = fileName; } form.Resource.Location = StripHttp(form.Resource.Location); var courseId = form.CourseId; _context.Resources.Add(form.Resource); await _context.SaveChangesAsync(); var courseResource = new CourseTemplateResource { CourseTemplateId = courseId, ResourceId = form.Resource.Id }; _context.CourseTemplateResources.Add(courseResource); await _context.SaveChangesAsync(); return RedirectToAction("CourseResources", "CourseTemplates", new { id = courseId }); } //ViewBag.ResourceTypeId = new SelectList(_context.ResourceTypes, "Id", "ParentId", form.Resource.CategoryId); return View(form); }
public ActionResult AssociateResourceWithCourse(CourseResourceViewModel model) { var courseId = Convert.ToInt32(model.CourseId); var resourceId = Convert.ToInt32(model.ResourceId); var courseResource = new CourseTemplateResource { CourseTemplateId = courseId, ResourceId = resourceId }; _context.CourseTemplateResources.Add(courseResource); _context.SaveChanges(); return RedirectToAction("Edit", "CourseTemplates", new { id = courseId }); }
public ActionResult CreateResource(int id) { var viewModel = new CourseResourceViewModel { CourseId = id }; ViewBag.CategoryId = new SelectList(_context.Categories, "Id", "Name"); return View(viewModel); }
public ActionResult AssociateResourceWithCourse(int id) { var course = _context.CourseTemplates.Find(id); ViewBag.Title = "Add Resource Associated With " + course.Title; ViewBag.ResourceId = new SelectList(_context.Resources, "Id", "Name"); var viewModel = new CourseResourceViewModel { ResourceId = "", CourseId = id }; return View(viewModel); }