public ActionResult Shipped(Guid id) { Order order = db.Orders.Find(id); order.Status = (byte)OrderStatus.Shipped; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId); return(View(product)); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { if (Request.Files.Count > 0 && Request.Files[0] != null) { string filePath = Path.Combine(HttpContext.Server.MapPath("~/Content/ProductImages"), Path.GetFileName(Request.Files[0].FileName)); Request.Files[0].SaveAs(filePath); product.ProductImageUrl = filePath; } db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId); return(View(product)); }
public ActionResult Order(Order order) { try { if (ValidateInput(order)) { order.OrderDate = DateTime.UtcNow; order.Status = (byte)OrderStatus.New; order.OrderId = Guid.NewGuid(); order.Description = order.Description ?? ""; ProductOrderViewModel viewData = (ProductOrderViewModel)Session["ProductOrderViewModel"]; order.Total = viewData.CartTotal; foreach (var cart in viewData.CartItems) { OrderDetail orderDetail = new OrderDetail(); orderDetail.OrderDetailId = Guid.NewGuid(); orderDetail.Quantity = cart.Count; orderDetail.UnitPrice = cart.Product.Price; orderDetail.ProductId = cart.ProductId; orderDetail.OrderId = order.OrderId; db.OrderDetails.Add(orderDetail); } db.Orders.Add(order); db.SaveChanges(); Session["ProductOrderViewModel"] = null; return(Json(new Order { IsSuccess = true, ErrorMessage = "" })); } } catch (Exception ex) { return(Json(new Order { IsSuccess = false, ErrorMessage = ErrorMessage })); } return(Json(new Order { IsSuccess = false, ErrorMessage = ErrorMessage })); }
public ActionResult AddressAndPayment(FormCollection values) { var order = new Order(); TryUpdateModel(order); try { if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false) { return(View(order)); } else { order.Username = User.Identity.Name; order.OrderDate = DateTime.Now; //Save Order storeDB.Orders.Add(order); storeDB.SaveChanges(); //Process the order var cart = ShoppingCart.GetCart(this.HttpContext); cart.CreateOrder(order); return(RedirectToAction("Complete", new { id = order.OrderId })); } } catch { //Invalid - redisplay with errors return(View(order)); } }