public void RemoveAll() { var items = _context.ShoppingList; _context.ShoppingList.RemoveRange(items); _context.SaveChanges(); }
public ActionResult Shipping(ShippingViewModel objship) { DisplayOrderDetailsVM ids = new DisplayOrderDetailsVM(); if (Session["Cart"] != null) { ids = (DisplayOrderDetailsVM)Session["Cart"]; ids.SVM = objship; } using (ShoppingCartEntities objdb = new ShoppingCartEntities()) { tblCustomerDetail objtblcd = new tblCustomerDetail(); tblItemQuantity objtbliq = new tblItemQuantity(); objtblcd.customerName = ids.SVM.CustomerName; objtblcd.customerAddress = ids.SVM.Address; objtblcd.mobile = ids.SVM.Mobile; objdb.tblCustomerDetails.Add(objtblcd); objdb.SaveChanges(); foreach (var i in ids.CDVM) { objtbliq.itemId = i.ProductId; objtbliq.Quantity = i.Quantity; objtbliq.customerId = objtblcd.customerId; objdb.tblItemQuantities.Add(objtbliq); objdb.SaveChanges(); } return(Json(new { msg = "Order Placed", Url = "/Home/HomePage" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Create([Bind(Include = "Id,Name,Price,CategoryId,Details,BrandId")] Product product) { if (ModelState.IsValid) { for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; var filename = Server.MapPath("~") + "\\uploaded\\" + file.FileName; file.SaveAs(filename); product.ProductImages.Add(new ProductImage() { ImageName = file.FileName }); } db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BrandId = new SelectList(db.Brands, "Id", "Name", product.BrandId); ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId); return(View(product)); }
private Cart GetUsersCart() { string username = User.Identity.Name; try { db.Customers.First(c => c.UserName.Equals(username)); } catch (Exception) { db.Customers.Add(new Customer { UserName = username }); db.SaveChanges(); } Cart cart = null; try { cart = db.Carts.First(c => c.CustomerID.Equals(username) && c.Status.Equals("unpaid")); } catch (Exception) { cart = new Cart { Date = DateTime.Now, CustomerID = username, Status = "unpaid" }; db.Carts.Add(cart); db.SaveChanges(); } return(cart); }
protected void btnPlaceOrder_OnClick(object sender, EventArgs e) { decimal amount = 0; Sale sale = Session["Sale"] as Sale; db.Sales.Add(sale); db.SaveChanges(); foreach (var item in ac.CartListDetails) { item.SaleId = sale.Id; var products = db.Products1.Find(item.ProductId); if (products != null) { amount = amount + (products.Product_Price * item.Quantity); } db.SaleDetails.Add(item); db.SaveChanges(); } var savedSale = db.Sales.Find(sale.Id); savedSale.Amount = amount; db.SaveChanges(); ac.CartListDetails.Clear(); Response.Redirect("OrderConfirmation.aspx"); }
public ActionResult Add(string P_num, string P_Style) { if (Session["Member"] == null) { return(RedirectToAction("SignIn", "Sign")); } int p_num = int.Parse(P_num); string MId = Session["Member"].ToString(); var Product = db.Product.Where(m => m.P_num == p_num).FirstOrDefault(); var Cart = db.Cart.Where(m => m.M_num == MId && m.C_num == P_num && m.P_style == P_Style).FirstOrDefault(); if (Cart == null) { Cart CartList = new Cart(); CartList.Amount = 1; CartList.M_num = MId; CartList.P_price = Product.P_Price; CartList.C_num = Product.P_num.ToString(); CartList.P_style = P_Style; CartList.P_name = Product.P_Name; db.Cart.Add(CartList); } else { Cart.Amount += 1; } db.SaveChanges(); return(RedirectToAction("ProductPage", "ProductPage", new { Id = Product.P_num })); }
public void PlaceOrder(Guid UserID, CartVariantItemsDTO cartVariantItemsDTO, Guid addressID) { Guid orderID = Guid.NewGuid(); Guid orderPlacedID = Guid.NewGuid(); DateTime dateTime = DateTime.Now; Order order = new Order { ID = orderID, DeliveryAddressID = addressID, TotalAmount = cartVariantItemsDTO.SubTotal, isCancelled = "N", OrderDate = dateTime, DeliveryDate = dateTime, StatusID = 1 }; shoppingCartEntities.Orders.Add(order); shoppingCartEntities.SaveChanges(); OrderPlaced orderPlaced = new OrderPlaced { ID = orderPlacedID, OrderID = orderID, UserID = UserID }; shoppingCartEntities.OrderPlaceds.Add(orderPlaced); shoppingCartEntities.SaveChanges(); foreach (var cartItem in cartVariantItemsDTO.CartItems) { OrderPlacedVariant orderPlacedVariant = new OrderPlacedVariant { ID = Guid.NewGuid(), OrderPlacedID = orderPlacedID, VariantID = cartItem.Variant.ID, SellingPrice = cartItem.Variant.DiscountedPrice, Quantity = cartItem.Quantity }; shoppingCartEntities.OrderPlacedVariants.Add(orderPlacedVariant); shoppingCartEntities.SaveChanges(); } return; }
public ActionResult Add(Category category) { category.IsDeleted = false; db.Categories.Add(category); db.SaveChanges(); TempData["Message"] = "Category has been added."; return(RedirectToAction("Index")); }
public ActionResult Add(Product product) { product.CategoryId = 11; db.Products.Add(product); db.SaveChanges(); TempData["Message"] = "Product has been added."; return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "PaymenMethodsID,Name")] PaymenMethod paymenmethod) { if (ModelState.IsValid) { db.PaymenMethods.Add(paymenmethod); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(paymenmethod)); }
public ActionResult Create([Bind(Include = "Id,Question,Answer")] FAQ faq) { if (ModelState.IsValid) { db.FAQs.Add(faq); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(faq)); }
public ActionResult Create([Bind(Include = "M_num,M_Name,M_Account,M_Password,M_Tel,M_Gender,M_Address")] Member member) { if (ModelState.IsValid) { db.Member.Add(member); db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Create", "_LayoutAdmin", member)); }
public ActionResult Create([Bind(Include = "PageID,Name,Alias,Content")] Page page) { if (ModelState.IsValid) { db.Pages.Add(page); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(page)); }
/// <summary> /// Add item to cart /// </summary> /// <param name="cartItem">item to be added in cart</param> /// <returns>whether the task was succesful or not</returns> public bool AddCartItem(CartItemModel cartItem, out HttpStatusCode status) { bool success = false; status = HttpStatusCode.OK; try { CartItem newCartItem = new CartItem(); newCartItem.CartId = cartItem.CartId; newCartItem.ItemId = cartItem.ItemId; newCartItem.Quantity = cartItem.Quantity; using (ShoppingCartEntities context = new ShoppingCartEntities()) { //check if item already exists in cart CartItem cartExists = context.CartItems .Include("Item") .Where(c => c.ItemId == newCartItem.ItemId && c.CartId == newCartItem.CartId) .FirstOrDefault(); if (cartExists == null) { //Add new item to car context.CartItems.Add(newCartItem); context.SaveChanges(); success = true; } else { if (cartExists.Quantity + newCartItem.Quantity > cartExists.Item.Quantity) { //HTTP 410 - Not enough quantity in stock status = HttpStatusCode.Gone; } else { //Update quantity of item in cart cartExists.Quantity += newCartItem.Quantity; context.CartItems.Attach(cartExists); context.Entry(cartExists).State = EntityState.Modified; context.SaveChanges(); success = true; } } } } catch (Exception ex) { new Logging().LogProgress(token, Common.CallerIP, ex); } return(success); }
public ActionResult Create([Bind(Include = "NewsID,ImageUrl,Name,CreateDate,Author,Content,Hits")] News news) { if (ModelState.IsValid) { db.News.Add(news); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(news)); }
public ActionResult Create([Bind(Include = "BrandID,ImageUrl,Name")] Brand brand) { if (ModelState.IsValid) { db.Brands.Add(brand); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brand)); }
public ActionResult Create([Bind(Include = "Id,Name")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "CustomerID,Name,Email,Password,Phone,DOB,Adress")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create([Bind(Include = "UserName,Name,Middle_Name,Address,Phone_Number,Date")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create([Bind(Include = "CategoryID,Name,Description,ImageUrl,ParentID,SortOrder,IsPublished")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "O_num,M_num,O_Date,O_Name,O_Phone,O_Address,Status,Price")] Orders orders) { if (ModelState.IsValid) { db.Orders.Add(orders); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.M_num = new SelectList(db.Member, "M_num", "M_Name", orders.M_num); return(View(orders)); }
public ActionResult Create([Bind(Include = "ImageID,ImageUrl,ProductID")] Image image) { if (ModelState.IsValid) { db.Images.Add(image); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductID = new SelectList(db.Products, "ProductsID", "ImageUrl", image.ProductID); return(View(image)); }
public ActionResult Create([Bind(Include = "Id,Name,Price,image,CategoryID")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "Id", "Type", product.CategoryID); return(View(product)); }
public void RemoveCartItems(string sessionID) { IEnumerable <ProductVisit> items = (from pv in context.ProductVisits where pv.sessionID == sessionID select pv); foreach (var i in items) { context.ProductVisits.Remove(i); } context.SaveChanges(); }
public ActionResult Create([Bind(Include = "Id,CustomerID,Date,Status")] Cart cart) { if (ModelState.IsValid) { db.Carts.Add(cart); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerID = new SelectList(db.Customers, "UserName", "Name", cart.CustomerID); return(View(cart)); }
public ActionResult Create([Bind(Include = "OrtherID,CustomerID,DateOrdered,DateRicived,ShippingMethod,PaymentMethod,PaymentType,Status,Amout")] Orther orther) { if (ModelState.IsValid) { db.Orthers.Add(orther); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "Name", orther.CustomerID); ViewBag.PaymentMethod = new SelectList(db.PaymenMethods, "PaymenMethodsID", "Name", orther.PaymentMethod); return(View(orther)); }
public ActionResult Create([Bind(Include = "ProductsID,CategoryID,BrandID,ImageUrl,Name,Description,Price,SalePrice,Detail,DateCreated,SortOrder,IsPublished")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BrandID = new SelectList(db.Brands, "BrandID", "ImageUrl", product.BrandID); ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name", product.CategoryID); return(View(product)); }
public ActionResult Create([Bind(Include = "BrandID,ProductsID,Note")] Band_Product band_product) { if (ModelState.IsValid) { db.Band_Product.Add(band_product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BrandID = new SelectList(db.Brands, "BrandID", "ImageUrl", band_product.BrandID); ViewBag.ProductsID = new SelectList(db.Products, "ProductsID", "ImageUrl", band_product.ProductsID); return(View(band_product)); }
public ActionResult Create([Bind(Include = "Id,ProductId,CartId,Quantity")] CartItem cartitem) { if (ModelState.IsValid) { db.CartItems.Add(cartitem); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CartId = new SelectList(db.Carts, "Id", "CustomerID", cartitem.CartId); ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", cartitem.ProductId); return(View(cartitem)); }
public ActionResult Create([Bind(Include = "OrtherID,ProductID,Name,Price,Quantily")] OrderItem orderitem) { if (ModelState.IsValid) { db.OrderItems.Add(orderitem); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OrtherID = new SelectList(db.Orthers, "OrtherID", "ShippingMethod", orderitem.OrtherID); ViewBag.ProductID = new SelectList(db.Products, "ProductsID", "ImageUrl", orderitem.ProductID); return(View(orderitem)); }