public ActionResult AddResources(ClassResourcesVM vm) { if (!ModelState.IsValid) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (vm.Upload == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (vm.Upload.ContentLength == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var clr = new ClassResources() { ClassId = vm.ClassId, Title = vm.Upload.FileName }; var ext = Path.GetExtension(vm.Upload.FileName); var file = Path.GetFileNameWithoutExtension(clr.Title) + clr.ClassId + ext.ToLower(); clr.Path = "~/Assets/Uploads/ClassResources/" + file; vm.Upload.SaveAs(Path.Combine(Server.MapPath("~/Assets/Uploads/ClassResources/"), file)); _db.ClassResource.Add(clr); _db.SaveChanges(); return(PartialResources("PartialAllClassResources", clr.ClassId)); }
/// <summary> /// Returns a partial resource view based on a provided name and class id /// </summary> /// <param name="viewName">The name of the partial view to return</param> /// <param name="classId">The Class Id to query view data by</param> /// <returns></returns> private PartialViewResult PartialResources(string viewName, int classId) { var resources = ClassResourcesRepository.CreateRepo(); var mod = new ClassResourcesVM { Resources = resources.GetByClassId(classId) }; return(PartialView(viewName, mod)); }