public ActionResult Checkout(Purchase purchase) { List <CartItem> cartItems = db.CartItems.Where(x => x.CartId == 1).ToList(); purchase.PurchasePrice = cartItems.Sum(x => x.CartItemPrice); purchase.Date = DateTime.Now; if (cartItems.Count == 0) { ModelState.AddModelError("", "У вас должны быть товары для покупки"); } if (ModelState.IsValid) { db.Purchases.Add(purchase); db.SaveChanges(); for (int i = 0; i < cartItems.Count; i++) { db.PurchaseDetails.Add(new PurchaseDetails { ProductId = cartItems[i].ProductId, PurchaseId = purchase.PurchaseId }); db.SaveChanges(); db.CartItems.Remove(cartItems[i]); db.SaveChanges(); } return(RedirectToAction("Complete")); } return(View(purchase)); }
public void AddItem(string itemName, int itemAmount, double itemPrice) { var newItem = new Product() { Name = itemName, Amount = itemAmount, Value = itemPrice }; shopDB.products.Add(newItem); shopDB.SaveChanges(); }
//[ValidateAntiForgeryToken] public JsonResult Create([Bind(Include = "Id,Name,Adress")] Shop shop) { if (ModelState.IsValid) { db.Shops.Add(shop); db.SaveChanges(); return(Json(true)); } return(Json(false)); }
public ActionResult Create([Bind(Include = "ID,UserName,Password,GroupID,Name,Address,Email,Phone,ProvinceID,DistrictID,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Status,roleID,img")] User user) { if (ModelState.IsValid) { db.User.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Edit([Bind(Include = "ID,Name,MetaTitle,ParentID,DisplayOrder,SeoTitle,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescriptions,Status,ShowOnHome,Language")] Category category) { SetViewBag(category.ID); if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
//[ValidateAntiForgeryToken] public JsonResult Create([Bind(Include = "Id,Name,Specification,Price,ShopId")] Item item) { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); return(Json(true)); } ViewBag.ShopId = new SelectList(db.Shops, "Id", "Name", item.ShopId); return(Json(false)); }
public ActionResult Create([Bind(Include = "ID,Name,MetaTitle,ParentID,DisplayOrder,SeoTitle,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescriptions,Status,ShowOnHome")] ProductCategory productCategory) { if (ModelState.IsValid) { SetViewBag(productCategory.ParentID); db.ProductCategory.Add(productCategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productCategory)); }
public ActionResult CreateModel(Menu Model) { try { db.Menu.Add(Model); db.SaveChanges(); } catch (Exception ex) { throw; } return(RedirectToAction("Index")); }
public bool?ChangeStatus(long id) { try { var user = db.User.Find(id); user.Status = !user.Status; db.SaveChanges(); return(user.Status); } catch (Exception ex) { } return(null); }
private void button1_Click(object sender, EventArgs e) { string productName = txtProduct.Text; string price = txtPrice.Text; string Amount = txtAmount.Text; string Category = cmbCategory.Text; string Size = cmbSize.Text; string Desc = rcDescription.Text; string[] emp = { productName, price, Amount, Category, Size, }; if (mainExtensions.IsEmpty(emp, string.Empty)) { int CatId = db.Categories.First(ct => ct.Name == Category).Id; int SizeId = db.ProductSizes.First(ct => ct.Size == Size).Id; db.Products.Add(new Product() { ProductName = productName, Price = Convert.ToDouble(price), Amount = Convert.ToInt32(Amount), CategoryId = CatId, SizeId = SizeId, }); db.SaveChanges(); MessageBox.Show("Product create successfully", "success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { } NewProduct np = new NewProduct(); np.ShowDialog(); }
public ActionResult EditPut(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ShopDB db = new ShopDB(); var productToUpdate = db.Products.Find(id); if (TryUpdateModel(productToUpdate, "", new string[] { "ProductName", "ProductPrice", "ProductDescription", "ProductImg", "CategoryId" })) { try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception dex) { db.Logs.Add(new Log { LogDesc = dex.ToString() }); } } return(View(productToUpdate)); }
// GET: Admin/Orders/Payments/5 public ActionResult Payments(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Order order = db.Order.Find(id); if (order == null) { return(HttpNotFound()); } order.Ship = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "ID,Name,Code,MetaTitle,Description,Image,MoreImages,Price,PromotionPrice,IncludedVAT,Quantity,CategoryID,Detail,Warranty,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescriptions,Status,TopHot,ViewCount")] Product product, HttpPostedFileBase file) { if (file != null) { file.SaveAs(HttpContext.Server.MapPath("~/assets/Admin/images/") + file.FileName); product.Image = "/assets/Admin/images/" + file.FileName; } SetViewBag(product.CategoryID); if (ModelState.IsValid) { db.Product.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create(Product product, HttpPostedFileBase image1, HttpPostedFileBase image2) { if (ModelState.IsValid) { if (image1 != null) { product.Image = new byte[image1.ContentLength]; image1.InputStream.Read(product.Image, 0, image1.ContentLength); } if (image2 != null) { product.ImageSmall = new byte[image2.ContentLength]; image2.InputStream.Read(product.ImageSmall, 0, image2.ContentLength); } _db.Product.Add(product); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public long InsertFeedBack(Feedback fb) { try { db.Feedback.Add(fb); db.SaveChanges(); return(fb.ID); } catch (Exception ex) { } return(-1); }
public bool update(long id, int Quantity) { try { var results = db.Product.Find(id); results.Quantity = results.Quantity - Quantity; db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool Delete(long ID) { try { var obj = db.Menu.Where(x => x.ID == ID).FirstOrDefault(); db.Menu.Remove(obj); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public ActionResult Create(Images img, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { file.SaveAs(HttpContext.Server.MapPath("~/assets/Admin/images/") + file.FileName); img.Name = file.FileName; } db.Images.Add(img); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(img)); }
//private void ClearRegisterInput() //{ // txtFullname.Text = ""; // txtEmail.Text = ""; // txtPassword.Text = ""; // txtConfirmPassword.Text = ""; // txtPhone.Text = ""; //} private void BtnRegister_Click(object sender, EventArgs e) { string fullname = txtFullname.Text; string email = txtEmail.Text; string password = txtPassword.Text; string phone = txtPhone.Text; string confirmPassword = txtConfirmPassword.Text; if (fullname != "" && email != "" && password != "" && phone != "" && confirmPassword != "") { if (password == confirmPassword) { if (password.Length >= 5) { db.Clients.Add(new Client { Email = email, Password = password.HashMe(), Phone = phone, Fullname = fullname }); db.SaveChanges(); MessageBox.Show(fullname + " was successfully created", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); Login lg = new Login(); this.Close(); lg.ShowDialog(); } else { lblError.Text = "Password length should be greater than 5"; lblError.Visible = true; } } else { lblError.Text = "Password and Confirm Password must be same!"; lblError.Visible = true; } } else { lblError.Text = "Please all the Fill!"; lblError.Visible = true; } }
private void Button1_Click(object sender, EventArgs e) { string productname = cmbProduct.Text; string categoryname = cmbCategory.Text; Product selectProduct = _db.Products.FirstOrDefault(pr => pr.Name == productname); double price = (double)selectProduct.Price * (double)nmCount.Value; _db.Orders.Add(new Order { ClientId = activeClient.Id, ProductId = selectProduct.Id, PurchaseDate = DateTime.Now, Amount = (int)nmCount.Value, Price = price }); _db.SaveChanges(); MessageBox.Show(productname + " " + nmCount.Value + " ədəd aldınız!", "Orders", MessageBoxButtons.OK, MessageBoxIcon.Information); ProductGridBuyView(); }
public long Insert(Order order) { db.Order.Add(order); db.SaveChanges(); return(order.ID); }
public void AddOrUpdate(Category element) { db.Category.AddOrUpdate(element); db.SaveChanges(); }
public void AddOrUpdate(Manufacturer element) { db.Manufacturer.AddOrUpdate(element); db.SaveChanges(); }
public void AddOrUpdate(Good element) { db.Good.AddOrUpdate(element); db.SaveChanges(); }
public void DeleteCartItem(CartItem item) { db.CartItems.Remove(item); db.SaveChanges(); }
public void AddProduct(Product product) { db.Products.Add(product); db.SaveChanges(); }