public ActionResult Update(CourseView coursesView) { if (!ModelState.IsValid) { coursesView.Categories = _dbContext.Categories.ToList(); return(View("Create", coursesView)); } var userId = User.Identity.GetUserId(); var coures = _dbContext.Courses.Single(c => c.Id == coursesView.Id && c.LectureId == userId); coures.Place = coursesView.Place; coures.DateTime = coursesView.GetDateTime(); coures.CategoryId = coursesView.Category; _dbContext.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Create(CourseView viewModel) { if (!ModelState.IsValid) { viewModel.Categories = _dbContext.Categories.ToList(); return(View("Create", viewModel)); } var course = new Course { LectureId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), CategoryId = viewModel.Category, Place = viewModel.Place }; _dbContext.Courses.Add(course); _dbContext.SaveChanges(); return(RedirectToAction("Index", "Home")); }