コード例 #1
0
        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);
        }
コード例 #2
0
        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 });
        }
コード例 #3
0
 public ActionResult CreateResource(int id)
 {
     var viewModel = new CourseResourceViewModel { CourseId = id };
     ViewBag.CategoryId = new SelectList(_context.Categories, "Id", "Name");
     return View(viewModel);
 }
コード例 #4
0
        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);
        }