public ActionResult DeleteConfirmed(Guid id) { ShippingInfos shippingInfos = db.Shippings.Find(id); db.Shippings.Remove(shippingInfos); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,Address")] ShippingInfos shippingInfos) { shippingInfos.Email = User.Identity.Name; if (ModelState.IsValid) { db.Entry(shippingInfos).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shippingInfos)); }
public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Address")] ShippingInfos shippingInfos) { if (ModelState.IsValid) { shippingInfos.ID = Guid.NewGuid(); shippingInfos.Email = User.Identity.Name; db.Shippings.Add(shippingInfos); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shippingInfos)); }
// GET: ShippingInfos/Delete/5 public ActionResult Delete(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ShippingInfos shippingInfos = db.Shippings.Find(id); if (shippingInfos == null) { return(HttpNotFound()); } return(View(shippingInfos)); }
public ActionResult Index([Bind(Include = "FirstName,LastName,Address,Email,DateOfOrder,OrderID,SaveShipping")] AnonymShippingInfos dto, FormCollection form) { StoreContext db = new StoreContext(); string userID = HelperMethods.GetUserID(User, Session); List <OrderItem> itemList = new List <OrderItem>(); Dictionary <Product, int> productList = HelperMethods.GetBasketEntriesToId(userID); string ddl = form["shippingAddress"]; if (!string.IsNullOrEmpty(ddl)) { var shippingInfo = db.Shippings .Where(x => x.FirstName + " " + x.LastName + " " + x.Address == ddl) .SingleOrDefault(x => x.Email == User.Identity.Name); dto.FirstName = shippingInfo.FirstName; dto.LastName = shippingInfo.LastName; dto.Address = shippingInfo.Address; } else { if (dto.SaveShipping) { var shippingInfo = new ShippingInfos() { Address = dto.Address, Email = User.Identity.Name, FirstName = dto.FirstName, LastName = dto.LastName, ID = Guid.NewGuid() }; db.Shippings.Add(shippingInfo); } } if (User.Identity.IsAuthenticated) { dto.Email = User.Identity.Name; } foreach (var entry in productList) { OrderItem item = new OrderItem(); item.Quantity = entry.Value; item.Status = OrderStatus.Active; item.ProductID = entry.Key.ID.ToString(); item.Price = (int)entry.Key.Price; item.ID = Guid.NewGuid(); itemList.Add(item); } Order order = new Order() { OrderId = dto.OrderID, FirstName = dto.FirstName, LastName = dto.LastName, Email = dto.Email, Address = dto.Address, Date = dto.DateOfOrder, UserID = userID, Items = itemList }; db.Orders.Add(order); db.SaveChanges(); List <BasketEntry> basketEntries = db.BasketEntries.Where(x => x.UserID == userID).ToList(); foreach (BasketEntry entry in basketEntries) { db.BasketEntries.Remove(entry); } db.SaveChanges(); //return RedirectToAction("Index"); return(View(dto)); }