public CartController(IUpdateCart updateCart, ICreateCart createCart, IGetCart getCart, ICartService cartService, CartEditModel cartModel) { this.CartEditModel = cartModel; this._updateCart = updateCart; this._createCart = createCart; this._getCart = getCart; this._cartService = cartService; }
// GET: Cart/Edit/5 public ActionResult Edit(int id) { this.CartEditModel = this._cartService.FillData(id); if (this.CartEditModel.Image != null && this.CartEditModel.Title != null && this.CartEditModel.Description != null) { return(View(this.CartEditModel)); } else { return(PartialView("_404")); } }
public ActionResult Delete(CartEditModel cartEditModel) { sqlCommand = new SqlCommand(); try { string type = "Delete"; sqlCommand = this._updateCart.UpdateCartData(cartEditModel, type); } catch (Exception ex) { ViewBag.FileStatus = ex; } return(RedirectToAction("Index", "Home")); }
public SqlCommand CreateCartData(CartEditModel cartEditModel) { using (sqlConnection = new SqlConnection(SqlConn.ConnectionString)) { sqlConnection.Open(); sqlCommand = new SqlCommand("SpMasterCart", sqlConnection); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@StatementType", "Insert"); sqlCommand.Parameters.AddWithValue("@CartTitle", cartEditModel.Title); sqlCommand.Parameters.AddWithValue("@CartDesc", cartEditModel.Description); sqlCommand.Parameters.AddWithValue("@CartImage", cartEditModel.Image); sqlCommand.ExecuteNonQuery(); } return(sqlCommand); }
public ActionResult Create(CartEditModel cartEditModel, HttpPostedFileBase Image) { sqlCommand = new SqlCommand(); try { if (Image != null) { string filename = System.IO.Path.GetFileName(Image.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/UploadedFiles"), filename); cartEditModel.Image = Image.FileName; Image.SaveAs(path); ViewBag.ImageUrl = "~/UploadedFiles" + filename; } ViewBag.FileStatus = "File uploaded successfully."; sqlCommand = this._createCart.CreateCartData(cartEditModel); } catch (Exception) { ViewBag.FileStatus = "Error while file uploading."; } return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult> Index(CartEditModel model) { if (!ModelState.IsValid) { var svcOrder = await CartUserService.GetCartOrderAsync(GetUserId()); if (svcOrder == null) { AddFeedbackMessage(FeedbackMessageTypes.Informational, "Your shopping cart is empty."); return(RedirectToAction("Index", "Order")); } var order = ModelFactory.CreateCartEditModel(svcOrder); return(View(order)); } // Apply changes to cart. // var actionData = this.GetActionData(); switch (actionData.ActionName) { case Actions.Delete: { var orderItemId = int.Parse(actionData.ActionParameter); var result = await CartUserService.DeleteCartItemAsync(GetUserId(), orderItemId); if (!result) { throw new Exception("DeleteCartItemAsync failure."); } var svcOrder = await CartUserService.GetCartOrderAsync(GetUserId()); if (svcOrder == null) { AddFeedbackMessage(FeedbackMessageTypes.Informational, "Your shopping cart is empty."); return(RedirectToAction("Index", "Order")); } model = ModelFactory.CreateCartEditModel(svcOrder); ModelState.Clear(); AddFeedbackMessage(FeedbackMessageTypes.Informational, "Order updated. Please review and click Continue to confirm."); return(View("Index", model)); } case Actions.Continue: { var orderUpdated = false; // Assume failure foreach (var item in model.Items) { if (item.Quantity != item.OriginalQuantity) { _ = await CartUserService.UpdateCartItemQuantityAsync(GetUserId(), item.OrderItemId, item.Quantity); orderUpdated = true; } } if (orderUpdated) { var svcOrder = await CartUserService.GetCartOrderAsync(GetUserId()); if (svcOrder == null) { AddFeedbackMessage(FeedbackMessageTypes.Informational, "Your shopping cart is empty."); return(RedirectToAction("Index", "Order")); } model = ModelFactory.CreateCartEditModel(svcOrder); ModelState.Clear(); AddFeedbackMessage(FeedbackMessageTypes.Informational, "Order updated. Please review and click Continue to confirm."); return(View("Index", model)); } else { return(RedirectToAction("Shipping")); } } default: throw new InvalidOperationException(string.Format("Unknown action {0}", actionData.ActionName)); } }