예제 #1
0
        public Course(string title, int maxEnrollments, CourseTemplate courseTemplate, string note, decimal price, bool isLive, string overView)
        {
            Title = title;
            MaxEnrollments = maxEnrollments;
            CourseTemplate = courseTemplate;
            Note = note;
            Price = price;
            IsLive = isLive;
            OverView = overView;

        }
        public async Task<ActionResult> Create(CourseViewModel form, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                IList<string> filesList = null;
                if (file != null)
                    filesList = GenerateVersions(file);

                if (filesList != null)
                {
                    form.BigPic = filesList[2];
                    form.MediumPic = filesList[1];
                    form.SmallPic = filesList[0];
                }

                var course = new CourseTemplate
                {
                    Title = form.Title,
                    Price = form.Price,
                    Description = form.Description,
                    BigPic = form.BigPic,
                    MediumPic = form.MediumPic,
                    SmallPic = form.SmallPic,
                    IsLive = form.IsLive,
                    SupplierId = form.SupplierId,
                    ProductTypeId = form.ProductTypeId,
                    CategoryId = form.CategoryId,
                    CourseLevelId = form.CourseLevelId,
                    OverView = form.OverView,
                    Note = form.Note,
                    Tax1Id = form.TaxId1,
                    Tax2Id = form.TaxId2,
                    Tax3Id = form.TaxId3
                };
                _context.CourseTemplates.Add(course);

                await _context.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            var suppliers = RolesService.GetCourseAuthors(_roleManager, _userManager);
            ViewBag.SupplierId = new SelectList(suppliers, "Id", "LfName");
            ViewBag.ProductTypeId = new SelectList(_context.ProductTypes, "Id", "Name", form.ProductTypeId);
            ViewBag.CourseLevelId = new SelectList(_context.CourseLevels, "Id", "Name", form.CourseLevelId);
            ViewBag.CategoryId = new SelectList(_context.Categories, "Id", "Name");
            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(form);
        }