Exemple #1
0
        public PartialViewResult GetCourseLastFive()
        {
            var model = new CourseCreateVM();

            model.Courses = _courseManager.GetCourseLastFive();

            return(PartialView("~/Views/Shared/Course/_CoursePartialDetails.cshtml", model));
        }
Exemple #2
0
        public PartialViewResult EntryForm()
        {
            CourseCreateVM course = new CourseCreateVM();


            course.SelectListItemsOrganization = _selectOptionId.SelectOrganization();

            return(PartialView("~/Views/Shared/Course/_CourseManagePartialCreate.cshtml", course));
        }
Exemple #3
0
        public ActionResult EditCourse(int id)
        {
            var courseVm = new CourseCreateVM();

            if (id > 0)
            {
                var course = _courseManager.GetById(id);

                course.SelectListItemsOrganization = _selectOptionId.SelectOrganization();

                courseVm = Mapper.Map <CourseCreateVM>(course);
            }


            return(View(courseVm));
        }
Exemple #4
0
        public ActionResult EditCourse(CourseCreateVM vm)
        {
            var course = Mapper.Map <Course>(vm);

            var isUpdated = _courseManager.Update(course);


            if (isUpdated)
            {
                ViewBag.Msg = "Success";

                return(RedirectToAction("CourseDetails"));
            }

            ViewBag.Msg = "Failed";
            return(RedirectToAction("CourseDetails"));
        }
Exemple #5
0
        public string AddCourse(CourseCreateVM vm)
        {
            var course = Mapper.Map <Course>(vm);


            if (ModelState.IsValid)
            {
                bool isAdded = _courseManager.Add(course);
                if (isAdded)
                {
                    return("Successfully Saved");
                }
                else
                {
                    return("Did not saved.");
                }
            }


            return("Sorry! Error Occured.");
        }
 public IActionResult Create(CourseCreateVM model)
 {
     if (ModelState.IsValid)
     {
         var entity = new CourseModel
         {
             Id              = 0,
             Name            = model.Name,
             CourseCode      = model.CourseCode,
             Subject         = model.Subject,
             Description     = model.Description,
             PaymentRequired = model.PaymentRequired,
             Price           = model.Price,
             AuthorId        = long.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier))
         };
         _context.Add(entity);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         return(View(model));
     }
 }
        public async Task <IActionResult> Create(CourseCreateVM courseCreateVM, List <int> List, List <string> Userlist)
        {
            var users = await _usermanager.GetUsersInRoleAsync("CourseManager");

            ViewBag.Roles = users;

            ViewBag.Categories = _db.Categories.ToList();
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

            if (ModelState["Photo"].ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
            {
                return(View());
            }

            if (!courseCreateVM.Photo.IsImage())
            {
                ModelState.AddModelError("Photo", "Zehmet olmasa shekil formati sechin");
                return(View());
            }

            if (courseCreateVM.Photo.MaxLength(2000))
            {
                ModelState.AddModelError("Photo", "Shekilin olchusu max 200kb ola biler");
                return(View());
            }


            string path     = Path.Combine("img", "course");
            string fileName = await courseCreateVM.Photo.SaveImg(_env.WebRootPath, path);

            if (List.Count() == 0)
            {
                TempData["Error"] = "Pls choose categoryasdfggd";
                return(View());
            }

            Course newcourse = new Course
            {
                Title         = courseCreateVM.Title,
                Image         = fileName,
                Description   = courseCreateVM.Description,
                StartTime     = courseCreateVM.StartTime,
                Duration      = courseCreateVM.Duration,
                ClassDuration = courseCreateVM.ClassDuration,
                SkilLevel     = courseCreateVM.SkilLevel,
                Language      = courseCreateVM.Language,
                StudentsCount = courseCreateVM.StudentsCount,
                Assesments    = courseCreateVM.Assesments,
                CourseFee     = courseCreateVM.CourseFee,
                AboutCourse   = courseCreateVM.AboutCourse,
                HowToApply    = courseCreateVM.HowToApply,
                Certification = courseCreateVM.Certification
            };
            List <CourseUser> courseUsers = new List <CourseUser>();

            foreach (var item in Userlist)
            {
                CourseUser course = new CourseUser
                {
                    AppUserId = item,
                    CourseId  = newcourse.Id
                };
                courseUsers.Add(course);
            }
            newcourse.CourseUsers = courseUsers;

            List <CourseCategory> courseCategories = new List <CourseCategory>();

            foreach (var item in List)
            {
                CourseCategory courseCategory = new CourseCategory
                {
                    CourseId   = newcourse.Id,
                    CategoryId = item
                };
                courseCategories.Add(courseCategory);
            }
            newcourse.CourseCategories = courseCategories;

            await _db.Courses.AddAsync(newcourse);

            _db.SaveChanges();
            var callbackUrl = Url.Action(
                "Detail",
                "Course",
                new { Id = courseCreateVM.Id },
                protocol: HttpContext.Request.Scheme);
            EmailService  email = new EmailService();
            List <string> e     = _db.Subscriptions.Select(x => x.Email).ToList();
            await email.SendEmailAsync(e, "Yeni course",
                                       "Yeni Course: <a href=https://localhost:44375/Courses/Detail/" + $"{newcourse.Id}" + ">link</a>");

            return(RedirectToAction(nameof(Index)));
        }