public ActionResult EditResource(CourseResourceViewModel form)
        {
            if (!ModelState.IsValid)
            {
                return View(form);
            }

            var resource = _context.Resources.SingleOrDefault(i => i.Id == form.Resource.Id);

            if (resource == null)
            {
                return RedirectToAction("CourseResources", "ManageCourses", new { id = form.CourseId });
            }

            resource.Name = form.Resource.Name;
            resource.Description = form.Resource.Description;
            resource.Instructions = form.Resource.Instructions;
            //resource.IsLive = form.IsLive;
            resource.Location = form.Resource.Location;

            _context.Entry(resource).State = EntityState.Modified;
            _context.SaveChanges();

            return RedirectToAction("CourseResources", "ManageCourses", new { id = form.CourseId });
        }
        public ActionResult EditResource(int id)
        {
            var viewModel = new CourseResourceViewModel();
            var courseResource = _context.CourseResources.SingleOrDefault(i => i.Id == id);

            viewModel.Resource = _context.Resources
                .SingleOrDefault(i => i.Id == courseResource.ResourceId);
            if (courseResource != null) viewModel.CourseId = courseResource.CourseId;

            ViewBag.ResourceTypeId = new SelectList(_context.ResourceTypes, "Id", "ParentId");
            if (viewModel.Resource == null)
            {
                return this.RedirectToAction(c => c.CourseResources(id));
                    //.WithError("Unable to find the issue.  Maybe it was deleted?");
            }

            return View(viewModel);
        }
        public async Task<ActionResult> CreateResource(CourseResourceViewModel form, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    string fileName = Path.GetFileName(file.FileName);
                    if (fileName != null)
                    {
                        var destinationPath = Path.Combine(Server.MapPath("~/Content/Resources"), fileName);
                        file.SaveAs(destinationPath);
                    }
                    form.Resource.UploadedFileName = fileName;
                }


                var courseId = form.CourseId;
                _context.Resources.Add(form.Resource);
                await _context.SaveChangesAsync();
                var courseResource = new CourseResource
                {
                    CourseId = courseId,
                    ResourceId = form.Resource.Id
                };
                _context.CourseResources.Add(courseResource);
                await _context.SaveChangesAsync();

                //return RedirectToAction("CourseResources", "ManageCourses", new { id = cohortId });
                return RedirectToAction("Board", "Courses", new { area="", id = courseId });
            }

           // ViewBag.ResourceTypeId = new SelectList(_context.ResourceTypes, "Id", "ParentId", form.Resource.ResourceTypeId);
            return View(form);
        }
 public ActionResult CreateResource(int id)
 {
     var viewModel = new CourseResourceViewModel();
     viewModel.ProductId = id;
     viewModel.CourseId = id;
     ViewBag.ResourceTypeId = new SelectList(_context.ResourceTypes, "Id", "ParentId");
     return View(viewModel);
 }
        public ActionResult AssociateResourceWithCohort(CourseResourceViewModel model)
        {
            var cohortId = Convert.ToInt32(model.CourseId);
            var resourceId = Convert.ToInt32(model.ResourceId);
            var courseResource = new CourseResource
            {
                CourseId = cohortId,
                ResourceId = resourceId
            };

            _context.CourseResources.Add(courseResource);
            _context.SaveChanges();
            return RedirectToAction("CourseResources", "ManageCourses", new { id = cohortId });
        }
        public ActionResult AssociateResourceWithCohort(int id)
        {
            var course = _context.Courses.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);
        }