public ActionResult DeleteConfirmed(int id) { DonationBasket donationBasket = db.DonationBaskets.Find(id); db.DonationBaskets.Remove(donationBasket); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "BasketId,SupporterId,OrganizationId,DateCreated,BasketPending,Received")] DonationBasket donationBasket) { if (ModelState.IsValid) { db.Entry(donationBasket).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OrganizationId = new SelectList(db.NonprofitOrganizations, "OrganizationId", "UserId", donationBasket.OrganizationId); ViewBag.SupporterId = new SelectList(db.Supporters, "SupporterId", "FullName", donationBasket.SupporterId); return(View(donationBasket)); }
// GET: DonationBaskets/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DonationBasket donationBasket = db.DonationBaskets.Find(id); if (donationBasket == null) { return(HttpNotFound()); } return(View(donationBasket)); }
public DonationBasket CreateBasket(int organizationId, int supporterId) { DonationBasket newBasket = new DonationBasket() { SupporterId = supporterId, OrganizationId = organizationId, DateCreated = System.DateTime.Today, }; db.DonationBaskets.Add(newBasket); db.SaveChanges(); return(newBasket); }
// GET: DonationBaskets/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DonationBasket donationBasket = db.DonationBaskets.Find(id); if (donationBasket == null) { return(HttpNotFound()); } ViewBag.OrganizationId = new SelectList(db.NonprofitOrganizations, "OrganizationId", "UserId", donationBasket.OrganizationId); ViewBag.SupporterId = new SelectList(db.Supporters, "SupporterId", "FullName", donationBasket.SupporterId); return(View(donationBasket)); }
public ActionResult AddToBasket(CartItem cartItem) { cartItem.Product = db.DonationItem.Where(c => c.ItemId == cartItem.ProductId).First(); var supporter = db.Supporters.Where(c => c.SupporterId == cartItem.SupporterId).First(); DonationBasket basket = null; if (!db.DonationBaskets.Any(c => c.SupporterId == supporter.SupporterId && c.OrganizationId == cartItem.Product.RequestingOrganizationId)) { var newBasket = CreateBasket(cartItem.Product.RequestingOrganizationId, supporter.SupporterId); basket = newBasket; } if (db.DonationBaskets.Any(c => c.SupporterId == supporter.SupporterId && c.OrganizationId == cartItem.Product.RequestingOrganizationId)) { basket = db.DonationBaskets.Where(c => c.SupporterId == supporter.SupporterId && c.OrganizationId == cartItem.Product.RequestingOrganizationId).First(); } cartItem.BasketId = basket.BasketId; cartItem.DonationBasket = basket; db.Entry(cartItem).State = EntityState.Modified; db.SaveChanges(); return(View("Index", new { supporterId = supporter.SupporterId, organizationId = basket.OrganizationId })); }