public ActionResult AddProductQuantity(ProductVModel model) { ViewBag.PageTitle = "Product MANAGEMENT"; //db.tbl_products_quantity_update_history Dictionary <string, string> PanelTitles = new Dictionary <string, string>(); PanelTitles["AddProductQuantity"] = "Add Product Quantity"; ViewBag.PanelTitles = PanelTitles; using (KDMDB db = new KDMDB()) { using (var transaction = db.Database.BeginTransaction()) { try { tbl_products_master productExist = new tbl_products_master(); productExist = db.tbl_products_master.FirstOrDefault(x => x.Code == model.Code); productExist.Quantity = model.InStock + model.Quantity; db.Entry(productExist).State = EntityState.Modified; tbl_products_history pHistory = new tbl_products_history(); pHistory.ProductID = productExist.ProductID; pHistory.ProductName = productExist.ProductName; pHistory.Category = productExist.Category; pHistory.Type = productExist.Type; pHistory.Code = productExist.Code; pHistory.MRP = productExist.MRP; pHistory.Unit = productExist.Unit; pHistory.DistributorPrice = (decimal)productExist.DP; pHistory.StokishPrice = (decimal)productExist.SP; pHistory.Vat = (decimal)productExist.Vat; pHistory.WalletPrice = productExist.WP; pHistory.PurchasePrice = productExist.PP; pHistory.RB = productExist.RB; pHistory.BP = productExist.BP; pHistory.Quantity = productExist.Quantity; pHistory.ProductDetails = productExist.ProductDetails; pHistory.CreateBy = productExist.CreateBy; pHistory.CreateDate = productExist.CreateDate; pHistory.Action = "Qty Update"; db.tbl_products_history.Add(pHistory); db.SaveChanges(); transaction.Commit(); ModelState.Clear(); ViewBag.SuccessMessage = "Product Quantity Added Successfully."; return(View()); } catch { transaction.Rollback(); ViewBag.ErrorMessage = "Product Quantity Added Failed."; return(View(model)); } } } }
public ActionResult GetProductDetails(string ProductCode) { tbl_products_master product = new tbl_products_master(); product.Code = ProductCode; product = db.tbl_products_master.Where(x => x.Code == ProductCode).FirstOrDefault(); return(Json(product, JsonRequestBehavior.AllowGet)); }
public ActionResult AddProduct(ProductVModel model) { ViewBag.PageTitle = "PRODUCT MANAGEMENT"; Dictionary <string, string> PanelTitles = new Dictionary <string, string>(); PanelTitles["AddProduct"] = "Add Product"; ViewBag.PanelTitles = PanelTitles; var codeExist = db.tbl_products_master.FirstOrDefault(x => x.Code.Replace(" ", "") == model.Code.Replace(" ", "")); if (!ModelState.IsValid) { ViewBag.ErrorMessage = "Product Added Failed."; return(View(model)); } else if (codeExist != null) { ViewBag.ErrorMessage = "Product Code Already Exist."; return(View(model)); } else { using (KDMDB db = new KDMDB()) { using (var transaction = db.Database.BeginTransaction()) { try { var lastProduct = db.tbl_products_master.ToList(); tbl_products_master product = new tbl_products_master(); product.ProductID = lastProduct.Max(x => x.ProductID) + 1; product.ProductName = model.ProductName; product.Category = model.Category; product.Type = model.Type; product.Code = model.Code; product.MRP = model.MRP; product.Unit = model.Unit; product.DP = model.DistributorPrice; product.SP = model.StokishPrice; product.Vat = model.Vat; product.WP = model.WalletPrice; product.PP = model.PurchasePrice; product.RB = model.RB; product.BP = model.BP; product.Quantity = model.Quantity; product.ProductDetails = model.ProductDetails; product.CreateDate = DateTime.Now; product.CreateBy = User.Identity.Name; product.ModificationDate = DateTime.Now; //Need to Confirm From niaz vai product.ModifiedBy = User.Identity.Name; //Need to Confirm from niaz vai db.tbl_products_master.Add(product); tbl_products_history pHistory = new tbl_products_history(); pHistory.ProductID = lastProduct.Max(x => x.ProductID) + 1; pHistory.ProductName = model.ProductName; pHistory.Category = model.Category; pHistory.Type = model.Type; pHistory.Code = model.Code; pHistory.MRP = model.MRP; pHistory.Unit = model.Unit; pHistory.DistributorPrice = model.DistributorPrice; pHistory.StokishPrice = model.StokishPrice; pHistory.Vat = model.Vat; pHistory.WalletPrice = model.WalletPrice; pHistory.PurchasePrice = model.PurchasePrice; pHistory.RB = model.RB; pHistory.BP = model.BP; pHistory.Quantity = model.Quantity; pHistory.ProductDetails = model.ProductDetails; pHistory.CreateBy = User.Identity.Name; pHistory.CreateDate = DateTime.Now; pHistory.Action = "Insert"; db.tbl_products_history.Add(pHistory); db.SaveChanges(); transaction.Commit(); ModelState.Clear(); ViewBag.SuccessMessage = "Product Added Successfully."; return(View()); } catch { transaction.Rollback(); ViewBag.ErrorMessage = "Product Added Failed."; return(View(model)); } } } } }
public ActionResult ProductEdit(ProductVModel model) { ViewBag.PageTitle = "Product MANAGEMENT"; Dictionary <string, string> PanelTitles = new Dictionary <string, string>(); PanelTitles["ProductEdit"] = "Product Edit"; ViewBag.PanelTitles = PanelTitles; if (!ModelState.IsValid) { ViewBag.ErrorMessage = "Product Updated Failed."; return(View(model)); } else { using (KDMDB db = new KDMDB()) { using (var transaction = db.Database.BeginTransaction()) { try { tbl_products_master product = new tbl_products_master(); product = db.tbl_products_master.FirstOrDefault(x => x.ProductID == model.ProductID); product.ProductName = model.ProductName; product.Category = model.Category; product.Type = model.Type; product.Code = model.Code; product.MRP = model.MRP; product.Unit = model.Unit; product.DP = model.DistributorPrice; product.SP = model.StokishPrice; product.Vat = model.Vat; product.WP = model.WalletPrice; product.PP = model.PurchasePrice; product.RB = model.RB; product.BP = model.BP; product.Quantity = model.Quantity; product.ProductDetails = model.ProductDetails; product.CreateDate = model.CreateDate; product.CreateBy = model.CreateBy; product.ModificationDate = DateTime.Now; product.ModifiedBy = User.Identity.Name; db.Entry(product).State = EntityState.Modified; tbl_products_history pHistory = new tbl_products_history(); pHistory.ProductID = product.ProductID; pHistory.ProductName = model.ProductName; pHistory.Category = model.Category; pHistory.Type = model.Type; pHistory.Code = model.Code; pHistory.MRP = model.MRP; pHistory.Unit = model.Unit; pHistory.DistributorPrice = model.DistributorPrice; pHistory.StokishPrice = model.StokishPrice; pHistory.Vat = model.Vat; pHistory.WalletPrice = model.WalletPrice; pHistory.PurchasePrice = model.PurchasePrice; pHistory.RB = model.RB; pHistory.BP = model.BP; pHistory.Quantity = model.Quantity; pHistory.ProductDetails = model.ProductDetails; pHistory.CreateBy = User.Identity.Name; pHistory.CreateDate = DateTime.Now; pHistory.Action = "Update"; db.tbl_products_history.Add(pHistory); db.SaveChanges(); transaction.Commit(); ModelState.Clear(); ViewBag.SuccessMessage = "Product Updated Successfully."; return(View(model)); } catch { transaction.Rollback(); ViewBag.ErrorMessage = "Product Updated Failed."; return(View(model)); } } } } }