Example #1
0
        //
        // 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);
        }
Example #2
0
        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);
        }
Example #3
0
 public void Delete(Course course)
 {
     db.UserCourses.DeleteAllOnSubmit(course.UserCourses);
     db.Courses.DeleteOnSubmit(course);
 }
Example #4
0
 //
 // Insert/Delete Methods
 public void Add(Course course)
 {
     db.Courses.InsertOnSubmit(course);
 }