public async Task<ActionResult> Edit(int id)
        {
            if (id == 0)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var course =
                await
                    _context.CourseTemplates.Include(p => p.Supplier)
                        .Include(p => p.ProductType)
                        .Include(c => c.Category)
                        .FirstOrDefaultAsync(i => i.Id == id);
            if (course == null)
            {
                return HttpNotFound();
            }

            var courseTemplateResources = _context.CourseTemplateResources.Include(r => r.Resource)
                .Where(c => c.CourseTemplateId == id).ToList()
                .Select(r => new CourseResourceDto
                {
                    Id = r.Id,
                    Name = r.Resource.Name,
                    Location = r.Resource.Location,
                    UploadedFileName = r.Resource.UploadedFileName,
                    SubmittedBy = r.Resource.SubmittedBy,
                    ResourceId = r.ResourceId,
                    CourseId = id
                });

            var courseScos =
                _context.CourseScos.Include(c => c.CourseTemplate)
                    .Include(c => c.Sco)
                    .AsQueryable()
                    .Where(c => c.CourseTemplateId == id)
                    .OrderBy(c => c.CatalogueNumber);
            var viewModel = new EditCourseViewModel
            {
                Id = course.Id,
                Title = course.Title,
                Description = course.Description,
                BigPic = course.BigPic,
                SmallPic = course.SmallPic,
                MediumPic = course.MediumPic,
                Price = course.Price,
                ProductTypeId = course.ProductTypeId ?? "COURSE",
                SupplierId = course.SupplierId ?? "",
                Note = course.Note,
                OverView = course.OverView,
                TaxId1 = course.Tax1Id,
                TaxId2 = course.Tax2Id,
                TaxId3 = course.Tax3Id,
                CourseTemplateResources = courseTemplateResources,
                CourseScos = courseScos,
                CourseTemplateId = id
            };

            var suppliers = RolesService.GetCourseAuthors(_roleManager, _userManager);
            ViewBag.SupplierId = new SelectList(suppliers, "Id", "LfName", course.SupplierId);
            ViewBag.ProductTypeId = new SelectList(_context.ProductTypes, "Id", "Name", course.ProductTypeId);
            ViewBag.CourseLevelId = new SelectList(_context.CourseLevels, "Id", "Name", course.CourseLevelId);
            ViewBag.CourseCategoryId = new SelectList(_context.Categories, "Id", "Name", course.CategoryId);
            ViewBag.ImagePath = "/Content/images/StorePics/" + course.SmallPic;
            ViewBag.Title = "Edit Course Template: " + course.Title;
            ViewBag.TaxId1 = new SelectList(_context.Taxes, "Id", "Name", course.Tax1Id);
            ViewBag.TaxId2 = new SelectList(_context.Taxes, "Id", "Name", course.Tax2Id);
            ViewBag.TaxId3 = new SelectList(_context.Taxes, "Id", "Name", course.Tax3Id);

            return View(viewModel);
        }
        public async Task<ActionResult> Edit(EditCourseViewModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                IList<string> filesList = null;
                if (file != null)
                    filesList = GenerateVersions(file);

                var course = _context.CourseTemplates.FirstOrDefault(i => i.Id == model.Id);
                if (course != null)
                {
                    course.Title = model.Title;
                    course.Description = HttpUtility.HtmlDecode(model.Description);
                    if (filesList != null)
                    {
                        course.BigPic = filesList[2];
                        course.MediumPic = filesList[1];
                        course.SmallPic = filesList[0];
                    }
                    course.Price = model.Price;
                    course.ProductTypeId = model.ProductTypeId;
                    course.SupplierId = model.SupplierId.ToString(CultureInfo.InvariantCulture);
                    course.CourseLevelId = model.CourseLevelId;
                    course.Tax1Id = model.TaxId1;
                    course.Tax2Id = model.TaxId2;
                    course.Tax3Id = model.TaxId3;

                    course.Note = HttpUtility.HtmlDecode(model.Note);
                    course.OverView = HttpUtility.HtmlDecode(model.OverView);


                    _context.Entry(course).State = EntityState.Modified;
                }
                await _context.SaveChangesAsync();
                return RedirectToAction("Index");
            }
            ViewBag.SupplierId = new SelectList(_context.Users, "Id", "LfName", model.SupplierId);
            ViewBag.ProductTypeId = new SelectList(_context.ProductTypes, "Id", "Name", model.ProductTypeId);
            ViewBag.CourseLevelId = new SelectList(_context.CourseLevels, "Id", "Name", model.CourseLevelId);
            ViewBag.CourseCategoryId = new SelectList(_context.Categories, "Id", "Name", model.CategoryId);
            ViewBag.ImagePath = "/Content/images/StorePics/" + model.SmallPic;
            ViewBag.Title = "Edit " + model.Title;
            ViewBag.TaxId1 = new SelectList(_context.Taxes, "Id", "Name");
            ViewBag.TaxId2 = new SelectList(_context.Taxes, "Id", "Name");
            ViewBag.TaxId3 = new SelectList(_context.Taxes, "Id", "Name");

            return View(model);
        }
        public async Task<ActionResult> Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var course = await _context.CourseTemplates.Include(p => p.ProductMaker).Include(p => p.ProductType).Include(c=>c.Category).FirstOrDefaultAsync(i => i.Id == id);
            if (course == null)
            {
                return HttpNotFound();
            }

            var viewModel = new EditCourseViewModel
            {
                Title = course.Title,
                Description = course.Description,
                BigPic = course.BigPic,
                SmallPic = course.SmallPic,
                MediumPic=course.MediumPic,
                Price = course.Price,
                ProductTypeId = course.ProductTypeId ?? "COURSE",
                SupplierId = course.SupplierId ?? "",
                Note = course.Note,
                OverView = course.OverView,
                TaxId1= course.Tax1Id,
                TaxId2= course.Tax2Id,
                TaxId3 = course.Tax3Id
            };


            ViewBag.SupplierId = new SelectList(_context.Users, "Id", "LfName", course.SupplierId);
            ViewBag.ProductTypeId =  new SelectList(_context.ProductTypes, "Id", "Name", course.ProductTypeId);
            ViewBag.CourseLevelId =  new SelectList(_context.CourseLevels, "Id", "Name", course.CourseLevelId);
            ViewBag.CourseCategoryId =     new SelectList(_context.Categories, "Id", "Name", course.CategoryId);
            ViewBag.ImagePath = "/Content/images/StorePics/" + course.SmallPic;
            ViewBag.Title = "Edit " + course.Title;
            ViewBag.TaxId1 = new SelectList(_context.Taxes, "Id", "Name", course.Tax1Id);
            ViewBag.TaxId2 = new SelectList(_context.Taxes, "Id", "Name", course.Tax2Id);
            ViewBag.TaxId3 = new SelectList(_context.Taxes, "Id", "Name", course.Tax3Id);

            return View(viewModel);
        }