public ActionResult DeleteProduct(int shopID) { Shop found = ORM.Shops.Find(shopID); ORM.Shops.Remove(found); ORM.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,ProductName,Price,ProductCode,AddedDate,AvailableQuantity,ProductReview,ImagePath")] TopProduct topproduct) { if (ModelState.IsValid) { db.TopProducts.Add(topproduct); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(topproduct)); }
public ActionResult Create([Bind(Include = "DetailsID,AvailableQuantity,AddedDate,ProductReview,ProductID,CategoryID,LatestID,ImagePath")] DetailsProduct detailsproduct) { if (ModelState.IsValid) { db.DetailsProducts.Add(detailsproduct); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "CatId", "CategoryName", detailsproduct.CategoryID); ViewBag.LatestID = new SelectList(db.LatestProducts, "Id", "ProductName", detailsproduct.LatestID); ViewBag.ProductID = new SelectList(db.TopProducts, "Id", "ProductName", detailsproduct.ProductID); return(View(detailsproduct)); }
public ActionResult SaveNewItem(Item newItem) { //Checks if all required info is entered if (ModelState.IsValid) { //Adds the product and saves to DB ORM.Items.Add(newItem); ORM.SaveChanges(); //Returning to action to display updated list return(RedirectToAction("DisplayShop")); } else { ViewBag.ErrorMessage = "Something did not go right."; return(RedirectToAction("DisplayShop")); } }
public ActionResult Create([Bind(Include = "CatId,CategoryName,ProductName,Price,ProductCode,AddedDate,AvailableQuantity,ProductReview,ImagePath")] Category category) { string fileName = Path.GetFileNameWithoutExtension(category.ImageFile.FileName); string extension = Path.GetExtension(category.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; category.ImagePath = "~/Image/" + fileName; fileName = Path.Combine(Server.MapPath("~/Image/"), fileName); category.ImageFile.SaveAs(fileName); if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } ModelState.Clear(); return(View()); }
public ActionResult SaveChanges(Item updateItem) { Item originalItem = ORM.Items.Find(updateItem.Id); if (originalItem != null && ModelState.IsValid) { originalItem.Name = updateItem.Name; originalItem.Description = updateItem.Description; originalItem.Quantity = updateItem.Quantity; originalItem.Price = updateItem.Price; ORM.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.ErrorMessage = "Something did not go right. Try again."; return(RedirectToAction("UpdateItem", updateItem.Id)); } }
private void btnRegister_Click(object sender, EventArgs e) { string fullname = txtFullname.Text; string username = txtUsername.Text; string password = txtPassword.Text; string conPassword = txtConPassword.Text; string[] array = { fullname, username, password, conPassword }; if (Utilities.IsEmpty(array, string.Empty)) { Worker selectedWorker = _context.Workers.FirstOrDefault(w => w.Username == username); if (selectedWorker == null) { if (password == conPassword) { lblError.Visible = false; Worker worker = new Worker(); worker.Fullname = fullname; worker.Username = username; worker.Password = password.HashCode(); _context.Workers.Add(worker); _context.SaveChanges(); ClearAllField(); MessageBox.Show($"User {username} registreted successfully!", "success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { lblError.Text = "Password or Confirm Password is not the same!"; lblError.Visible = true; } } else { lblError.Text = "Username already exist!"; lblError.Visible = true; } } else { lblError.Text = "Please fill all field!"; lblError.Visible = true; } }
private void btnSell_Click(object sender, EventArgs e) { Order order = new Order(); order.Purchase_Date = DateTime.Now; order.WorkerId = _activeWorker.Id; order.ProductId = selectedProduct.Id; order.Amount = (int)nmCount.Value; order.Price = selectedProduct.Product_Price * nmCount.Value; _context.Orders.Add(order); selectedProduct.Quantity -= (int)nmCount.Value; MessageBox.Show($"Product: {selectedProduct.Product_Name} sold successfully", "success", MessageBoxButtons.OK, MessageBoxIcon.Information); _context.SaveChanges(); ComponentVisible(); FillProductDataGridView(); cmbCategory.Items.Clear(); cmbMarka.Items.Clear(); cmbProduct.Items.Clear(); FillCategoryComboBox(); FillMarkaComboBox(); }
public void SaveChanges() { _entities.SaveChanges(); }