public ActionResult Create(product rec) { try { if (ModelState.IsValid) { ProductTbl ptbl = new ProductTbl(); colorDataDropdown(); var CheckName = entity.ProductTbls.Any(p => p.ProductName == rec.productName); if (CheckName == true) { TempData["already"] = "Product Name is Already Exist in Database.."; return(View()); } ptbl.ProductName = rec.productName; ptbl.Price = rec.Price; ptbl.Quantity = rec.Quantity; ptbl.IsGstApplicable = rec.IsGSTApplicable; ptbl.PurchaseDate = Convert.ToDateTime(rec.Purchase_Date); ptbl.ExpiryDate = Convert.ToDateTime(rec.Expiry_Date); ptbl.Color = rec.ColorID; entity.ProductTbls.Add(ptbl); entity.SaveChanges(); TempData["save"] = "Record Inserted Successfully.."; return(RedirectToAction("Index")); } return(View()); } catch (Exception e) { ModelState.AddModelError("", e.Message); return(View()); } }
// PUT api/Product/5 public IHttpActionResult PutProductTbl(int id, ProductTbl producttbl) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != producttbl.ProductId) { return(BadRequest()); } db.Entry(producttbl).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductTblExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ProductName,Price,Photo")] ProductTbl productTbl) { if (id != productTbl.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productTbl); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductTblExists(productTbl.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(productTbl)); }
public void save(ProductVM vm) { try { ProductTbl entity = new ProductTbl(); var product = _MarbalContext.ProductTbls.Where(x => x.ProductName == vm.ProductName).FirstOrDefault(); if (product != null) { entity.ID = product.ID; var productCat = _MarbalContext.ProductCategoryTbls.Where(x => x.ProductID == product.ID && x.CategoryID == vm.CategoryID).FirstOrDefault(); if (productCat != null) { throw new Exception("Product Already Exists"); } } else { entity.ProductName = vm.ProductName; _MarbalContext.Entry(entity).State = EntityState.Added; } //entity.CategoryTbls.Add(_MarbalContext.CategoryTbls.Find(vm.CategoryID)); ProductCategoryTbl productCategoryTbl = new ProductCategoryTbl(); productCategoryTbl.ProductID = entity.ID; productCategoryTbl.CategoryID = vm.CategoryID; _MarbalContext.Entry(productCategoryTbl).State = EntityState.Added; _MarbalContext.SaveChanges(); } catch (Exception ex) { throw ex; } }
public ActionResult DeleteConfirmed(int id) { ProductTbl productTbl = db.ProductTbls.Find(id); db.ProductTbls.Remove(productTbl); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(Int64 id) { ProductTbl tbl = entity.ProductTbls.Find(id); entity.ProductTbls.Remove(tbl); entity.SaveChanges(); TempData["delete"] = "Record Deleted Successfully..!"; return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ProductId,ProductName,ProductRate")] ProductTbl productTbl) { if (ModelState.IsValid) { db.Entry(productTbl).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productTbl)); }
public ActionResult Edit([Bind(Include = "PId,PName,PRate,BookId")] ProductTbl productTbl) { if (ModelState.IsValid) { db.Entry(productTbl).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BookId = new SelectList(db.BookTables, "BookId", "BookName", productTbl.BookId); return(View(productTbl)); }
public IHttpActionResult GetProductTbl(int id) { ProductTbl producttbl = db.ProductTbls.Find(id); if (producttbl == null) { return(NotFound()); } return(Ok(producttbl)); }
public ActionResult Edit([Bind(Include = "Id,Name,Rate,ModelId")] ProductTbl productTbl) { if (ModelState.IsValid) { db.Entry(productTbl).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ModelId = new SelectList(db.DetailsTbls, "ModelId", "ModelName", productTbl.ModelId); return(View(productTbl)); }
public ActionResult Create([Bind(Include = "ProductId,ProductName,ProductRate")] ProductTbl productTbl) { if (ModelState.IsValid) { db.ProductTbls.Add(productTbl); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productTbl)); }
public async Task <IActionResult> Create([Bind("Id,ProductName,Price,Photo")] ProductTbl productTbl) { if (ModelState.IsValid) { _context.Add(productTbl); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(productTbl)); }
public ActionResult Create([Bind(Include = "Id,Name,Rate,ModelId")] ProductTbl productTbl) { if (ModelState.IsValid) { db.ProductTbls.Add(productTbl); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ModelId = new SelectList(db.DetailsTbls, "ModelId", "ModelName", productTbl.ModelId); return(View(productTbl)); }
public ActionResult Create([Bind(Include = "PId,PName,PRate,BookId")] ProductTbl productTbl) { if (ModelState.IsValid) { db.ProductTbls.Add(productTbl); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BookId = new SelectList(db.BookTables, "BookId", "BookName", productTbl.BookId); return(View(productTbl)); }
public IHttpActionResult PostProductTbl(ProductTbl producttbl) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.ProductTbls.Add(producttbl); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = producttbl.ProductId }, producttbl)); }
public IHttpActionResult DeleteProductTbl(int id) { ProductTbl producttbl = db.ProductTbls.Find(id); if (producttbl == null) { return(NotFound()); } db.ProductTbls.Remove(producttbl); db.SaveChanges(); return(Ok(producttbl)); }
public bool DeleteProduct(int id, int catID) { try { ProductTbl obj = _dbentity.ProductTbls.Where(x => x.ProductID_PK == id && x.CategoryID_FK == catID).FirstOrDefault(); _dbentity.ProductTbls.Remove(obj); _dbentity.SaveChanges(); return(true); } catch (Exception) { throw; } }
// GET: ProductTbls/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductTbl productTbl = db.ProductTbls.Find(id); if (productTbl == null) { return(HttpNotFound()); } return(View(productTbl)); }
// GET: Store/Product/Edit/5 public ActionResult Edit(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductTbl productTbl = db.ProductTbls.Find(id); if (productTbl == null) { return(HttpNotFound()); } ViewBag.CategoryID = new SelectList(db.CategoryTbls, "CategoryID", "CategoryName", productTbl.CategoryID); return(View(productTbl)); }
// GET: ProductTbls/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductTbl productTbl = db.ProductTbls.Find(id); if (productTbl == null) { return(HttpNotFound()); } ViewBag.ModelId = new SelectList(db.DetailsTbls, "ModelId", "ModelName", productTbl.ModelId); return(View(productTbl)); }
public ActionResult Edit(product rec) { ProductTbl data = entity.ProductTbls.Find(rec.ProductID); data.ProductID = rec.ProductID; data.ProductName = rec.productName; data.Price = rec.Price; data.Quantity = rec.Quantity; data.IsGstApplicable = rec.IsGSTApplicable; data.PurchaseDate = Convert.ToDateTime(rec.Purchase_Date); data.ExpiryDate = Convert.ToDateTime(rec.Expiry_Date); entity.Entry(data).State = System.Data.Entity.EntityState.Modified; entity.SaveChanges(); TempData["edit"] = "Record Updated Successfully.."; return(RedirectToAction("Index")); }
public ActionResult Edit(Int64 id) { ProductTbl data = entity.ProductTbls.Find(id); product p = new product(); p.productName = data.ProductName; p.ProductID = data.ProductID; p.Price = data.Price; p.IsGSTApplicable = data.IsGstApplicable; p.Quantity = data.Quantity; p.Purchase_Date = data.PurchaseDate.Value.ToShortDateString(); p.Expiry_Date = data.ExpiryDate.Value.ToShortDateString(); List <product> pr = new List <product>(); pr.Add(new product() { ColorID = 1, ColorName = "Red" }); pr.Add(new product() { ColorID = 2, ColorName = "Black" }); pr.Add(new product() { ColorID = 3, ColorName = "Pink" }); pr.Add(new product() { ColorID = 4, ColorName = "White" }); pr.Add(new product() { ColorID = 5, ColorName = "Purple" }); pr.Add(new product() { ColorID = 6, ColorName = "Black" }); ViewBag.color = new SelectList(pr.ToList(), "ColorID", "ColorName", data.Color); return(View(p)); }
public bool UpdateProduct(ProductModels editObj) { try { ProductTbl dbObj = _dbentity.ProductTbls.Where(x => x.ProductID_PK == editObj.ProductID_PK && x.CategoryID_FK == editObj.CategoryID_FK).FirstOrDefault(); dbObj.ProductName = editObj.ProductName; dbObj.ProductDescription = editObj.ProductDescription; dbObj.ProductQuantity = editObj.ProductQuantity; dbObj.ProductPrice = editObj.ProductPrice; dbObj.Discount = editObj.Discount; dbObj.ExpiryDate = editObj.ExpiryDate; _dbentity.SaveChanges(); return(true); } catch (Exception ex) { throw; } }
public ActionResult Edit([Bind(Include = "ProductID,ProductName,CategoryID,ProductDesc,Price,MfgName,ImagePath")] ProductTbl productTbl, HttpPostedFileBase PhotoFile) { if (ModelState.IsValid) { string path = ""; if (PhotoFile != null) { path = "~/productphotos/" + PhotoFile.FileName; PhotoFile.SaveAs(Server.MapPath(path)); path = path.Substring(1, path.Length - 1); productTbl.ImagePath = path; } db.Entry(productTbl).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.CategoryTbls, "CategoryID", "CategoryName", productTbl.CategoryID); return(View(productTbl)); }
public int CreateProduct(ProductModels obj) { try { var dbData = new ProductTbl(); dbData.CategoryID_FK = obj.CategoryID_FK; dbData.ProductName = obj.ProductName; dbData.ProductDescription = obj.ProductDescription; dbData.ProductQuantity = obj.ProductQuantity; dbData.ProductPrice = obj.ProductPrice; dbData.Discount = obj.Discount; dbData.ExpiryDate = obj.ExpiryDate; _dbentity.ProductTbls.Add(dbData); _dbentity.SaveChanges(); return(dbData.ProductID_PK); } catch (Exception ex) { throw; } }
public ProductModels GetProductByID(int id, int catID) { try { ProductTbl productDtls = _dbentity.ProductTbls.Where(x => x.ProductID_PK == id && x.CategoryID_FK == catID).FirstOrDefault(); ProductModels obj = new ProductModels(); obj.ProductID_PK = productDtls.ProductID_PK; obj.CategoryID_FK = productDtls.CategoryID_FK; obj.ProductName = productDtls.ProductName; obj.ProductDescription = productDtls.ProductDescription; obj.ProductQuantity = productDtls.ProductQuantity; obj.ProductPrice = productDtls.ProductPrice; obj.Discount = productDtls.Discount; obj.ExpiryDate = productDtls.ExpiryDate; return(obj); } catch (Exception ex) { throw; } }
public ActionResult AddToCart(Int64 id = 0) { Int64 userid = Convert.ToInt64(Session["UserID"]); ProductTbl prec = entity.ProductTbls.SingleOrDefault(p => p.ProductID == id); var usercart = entity.CartTbls.Where(p => p.UserID == userid).ToList(); if (usercart != null) { CartTbl prodcart = usercart.SingleOrDefault(p => p.ProductID == id); if (prodcart != null) { prodcart.Qty++; entity.SaveChanges(); } else { CartTbl newcart = new CartTbl(); newcart.Price = prec.Price; newcart.ProductID = id; newcart.Qty = 1; newcart.UserID = userid; entity.CartTbls.Add(newcart); entity.SaveChanges(); } } else { CartTbl newcart = new CartTbl(); newcart.Price = prec.Price; newcart.ProductID = id; newcart.Qty = 1; newcart.UserID = userid; entity.CartTbls.Add(newcart); entity.SaveChanges(); } return(RedirectToAction("GetProducts", "Home", new { id = prec.CategoryID })); }
public ActionResult Details(Int64 id) { ProductTbl tbl = entity.ProductTbls.Find(id); return(View(tbl)); }