// // GET: /Courses/Create public ActionResult Create() { var course = new Course() { StartDate = DateTime.Now.AddDays(1), EndDate = DateTime.Now.AddDays(7) }; ViewData["defaultCosts"] = new SelectList(defaultCosts); return View(course); }
public ActionResult Create(Course course, FormCollection collection) { if (ModelState.IsValid) { try { var coursePrices = Request["CoursePrices"]; var courseDescriptions = Request["CourseDescriptions"]; if (!String.IsNullOrEmpty(coursePrices)) { var descriptions = courseDescriptions.Split(','); var prices = coursePrices.Split(','); for (int i = 0; i < prices.Count(); i++) { course.Costs.Add(new Cost { CourseId = course.CourseId, Description = descriptions[i], Price = Convert.ToDecimal(prices[i].Replace(".",",")) }); } } if (course.IsValid) { courseRepository.Add(course); courseRepository.Save(); } else { throw new Exception(); } return RedirectToAction("Details", new { id = course.CourseId }); } catch { ViewData["defaultCosts"] = GenerateCostList(course.Costs.ToList()); ViewData["selectedCosts"] = course.Costs.ToList(); ModelState.AddRuleViolations(course.GetRuleViolations()); } } return View(course); }
public void Delete(Course course) { db.UserCourses.DeleteAllOnSubmit(course.UserCourses); db.Courses.DeleteOnSubmit(course); }
// // Insert/Delete Methods public void Add(Course course) { db.Courses.InsertOnSubmit(course); }