public ActionResult ImportHistory() { ViewBag.BrandSelectOptions = DropDownListOption.GetBrandOptions(); ViewBag.CategorySelectOptions = DropDownListOption.GetCategoryOptions(); ViewBag.SupplierSelectOptions = DropDownListOption.GetSupplierOptions(); return(View()); }
public ActionResult Edit(EditProduct model) { try { if (ModelState.IsValid) { var product = db.Products.Where(p => p.ProductId == model.ProductId).FirstOrDefault(); if (product != null) { decimal price = 0; decimal discount = 0; if (Decimal.TryParse(model.Price.Replace(",", ""), out price) && Decimal.TryParse(model.Discount.Replace(",", ""), out discount)) { product.ProductName = model.ProductName; product.ProductNameUnsign = StringExtensions.convertToUnSign(model.ProductName).ToLower(); product.Description = model.Description; product.DescriptionUnsign = StringExtensions.convertToUnSign(model.Description).ToLower(); product.BrandId = model.BrandId; product.CategoryId = model.CategoryId; product.SKU = model.SKU; product.QuantityPerUnit = model.QuantityPerUnit; product.Price = price; product.Discount = discount; product.LastUpdate = DateTime.Now; product.LastUpdateUser = GetLogonUserName(); db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Giá sản phẩm không hợp lệ!"); } } else { ModelState.AddModelError("", "Không tìm thấy sản phẩm!!!"); } } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); // Write error log var log = new Log(); log.LogDate = DateTime.Now; log.Action = "Product - Edit()"; log.Tags = "Error"; log.Message = ex.ToString(); db.Logs.Add(log); } finally { model.BrandSelectOptions = DropDownListOption.GetBrandOptions(model.BrandId ?? 0); model.CategorySelectOptions = DropDownListOption.GetCategoryOptions(model.CategoryId ?? 0); } return(View(model)); }
public ActionResult Add() { var model = new AddProduct(); try { model.Price = "0"; model.Discount = "0"; model.BrandSelectOptions = DropDownListOption.GetBrandOptions(); model.CategorySelectOptions = DropDownListOption.GetCategoryOptions(); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); // Write error log var log = new Log(); log.LogDate = DateTime.Now; log.Action = "Product - Add()"; log.Tags = "Error"; log.Message = ex.ToString(); db.Logs.Add(log); } return(View(model)); }
public ActionResult Edit(int id) { var model = new EditProduct(); try { var product = db.Products.Where(p => p.ProductId == id).FirstOrDefault(); if (product != null) { model.ProductId = product.ProductId; model.ProductName = product.ProductName; model.Description = product.Description; model.BrandId = product.BrandId; model.CategoryId = product.CategoryId; model.SKU = product.SKU; model.QuantityPerUnit = product.QuantityPerUnit; model.Price = product.Price.ToString("#,##0"); model.Discount = product.Discount.ToString("#,##0"); return(View(model)); } else { ModelState.AddModelError("", "Không tìm thấy sản phẩm!!!"); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); // Write error log var log = new Log(); log.LogDate = DateTime.Now; log.Action = "Product - Edit()"; log.Tags = "Error"; log.Message = ex.ToString(); db.Logs.Add(log); } finally { model.BrandSelectOptions = DropDownListOption.GetBrandOptions(model.BrandId ?? 0); model.CategorySelectOptions = DropDownListOption.GetCategoryOptions(model.CategoryId ?? 0); } return(View(model)); }
public ActionResult Index() { ViewBag.BrandSelectOptions = DropDownListOption.GetBrandOptions(); ViewBag.CategorySelectOptions = DropDownListOption.GetCategoryOptions(); return(View()); }