Ejemplo n.º 1
0
        public ActionResult Update(CourseViewModels viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Categories = _dbContext.Categories.ToList();
                return(View("Create", viewModel));
            }
            var userId = User.Identity.GetUserId();
            var course = _dbContext.Courses.Single(c => c.Id == viewModel.Id && c.LecturerID == userId);

            course.place      = viewModel.place;
            course.Datetime   = viewModel.GetDateTime();
            course.CategoryId = viewModel.Category;

            _dbContext.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 2
0
        public ActionResult Create(CourseViewModels viewModels)
        {
            if (!ModelState.IsValid)
            {
                viewModels.Categories = _dbContext.CateGories.ToList();
                return(View("Create", viewModels));
            }
            var course = new Course
            {
                LecturerId = User.Identity.GetUserId(),
                DateTime   = viewModels.GetDateTime(),
                CategoryId = viewModels.Category,
                Place      = viewModels.Place
            };

            _dbContext.Courses.Add(course);
            _dbContext.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 3
0
        public ActionResult Create(CourseViewModels viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Categories = dbContext.Categories.ToList();
                return(View("Create", viewModel));
            }
            var cours = new Course
            {
                LecturerId = User.Identity.GetUserId(),
                DateTime   = viewModel.GetDateTime(),
                CategoryId = viewModel.Category,
                Place      = viewModel.Place
            };

            dbContext.Courses.Add(cours);
            dbContext.SaveChanges();
            return(RedirectToAction("Mine", "Courses"));
        }