public void AddToCart(Chapter chapter) { // Get the matching cart and album instances var cartItem = storeDB.Carts.SingleOrDefault(c => c.CartId == DownloadCartId && c.ChapterId == chapter.ChapterId); if (cartItem == null) { // Create a new cart item if no cart item exists cartItem = new Cart { ChapterId = chapter.ChapterId, CartId = DownloadCartId, Count = 1, DateCreated = DateTime.Now }; storeDB.Carts.Add(cartItem); } else { // If the item does exist in the cart, then add one to the quantity cartItem.Count++; } // Save changes storeDB.SaveChanges(); }
public ActionResult Create(Chapter chapter) { if (ModelState.IsValid) { db.Chapters.Add(chapter); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "CourseName", chapter.CourseId); ViewBag.InstructorId = new SelectList(db.Instructors, "UserID", "InstructorName", chapter.InstructorId); return View(chapter); }
public ActionResult Edit(Chapter chapter) { if (ModelState.IsValid) { db.Entry(chapter).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "CourseName", chapter.CourseId); ViewBag.InstructorId = new SelectList(db.Instructors, "UserID", "InstructorName", chapter.InstructorId); return View(chapter); }