public ActionResult Edit(int id = 0) { var product = ProductHandler.GetById(id); var proModel = ProductModelMapper.Map(product); return(View(proModel)); }
public ActionResult Index() { var model = new ProductModel(); var proList = ProductHandler.GetList(); foreach (var pro in proList) { var proModel = ProductModelMapper.Map(pro); model.ProductList.Add(proModel); } return(View(model)); }
public ActionResult Index() { var model = new HomeModel(); var products = ProductHandler.GetList(false); foreach (var product in products) { var productModel = ProductModelMapper.Map(product); model.Products.Add(productModel); } return(View(model)); }
public ActionResult Index(int id = 0) { if (id == 0) { return(RedirectToAction("Index", "Home")); } var product = ProductHandler.GetById(id); if (product == null) { return(RedirectToAction("Index", "Home")); } var promodel = ProductModelMapper.Map(product); return(View(promodel)); }
/// <summary> /// Get all products /// </summary> /// <returns>Collection of products</returns> public IEnumerable <ProductModel> GetAll() { // The result var result = new List <ProductModel>(); // Get all products from BL var products = ProductRepository.GetAllProducts(); foreach (var product in products) { // Get product model from product var model = ProductModelMapper.Map(product); // Add the product model to the result result.Add(model); } return(result); }
public ActionResult Edit(ProductModel model, HttpPostedFileBase file) { try { if (file != null && file.ContentLength > 0) { var path = Path.Combine(Server.MapPath("~/Images/Products"), model.ImageUrl); file.SaveAs(path); } var product = ProductModelMapper.Map(model); product.LastModifiedDate = DateTime.Now; ProductHandler.Update(product); } catch (Exception ex) { model.Error = ex.Message; return(View("Edit", model)); } return(RedirectToAction("Index")); }
public ActionResult Add(ProductModel model, HttpPostedFileBase file) { var product = ProductModelMapper.Map(model); try { product.CreationDate = DateTime.Now; ProductHandler.Add(product); product.ImageUrl = product.ProductId + ".png"; if (file != null && file.ContentLength > 0) { var path = Path.Combine(Server.MapPath("~/Images/Products"), product.ImageUrl); file.SaveAs(path); } ProductHandler.Update(product); } catch (Exception ex) { model.Error = ex.Message; return(View("Add", model)); } return(RedirectToAction("Index")); }
public void Put(int id, [FromBody] ProductModel model) { var product = ProductModelMapper.Map(model); ProductRepository.UpdateProduct(id, product); }
public void Post([FromBody] ProductModel model) { var product = ProductModelMapper.Map(model); ProductRepository.AddProduct(product); }