예제 #1
0
 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);
 }
예제 #2
0
 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");
 }
예제 #3
0
 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");
 }
예제 #4
0
 public ActionResult Add()
 {
     var u = new ProductModel();
     return View(u);
 }
예제 #5
0
 public static ProductModel Map(Product product)
 {
     var model = new ProductModel();
     if (product != null)
     {
         model.ProductId = product.ProductId;
         model.ProductName = product.ProductName;
         model.EanCode = product.EanCode;
         model.ImageUrl = product.ImageUrl;
         model.Length = product.Length;
         model.Width = product.Width;
         model.Height = product.Height;
         model.Description = product.Description;
         model.Price = product.Price;
         model.IsOutOfStock = product.IsOutOfStock;
         model.CreationDate = product.CreationDate;
         model.LastModifiedDate = product.LastModifiedDate;
     }
     return model;
 }
예제 #6
0
 public static Product Map(ProductModel model)
 {
     var product = new Product();
     if (model != null)
     {
         product.ProductId = model.ProductId;
         product.ProductName = model.ProductName;
         product.EanCode = model.EanCode;
         product.ImageUrl = model.ImageUrl;
         product.Length = model.Length;
         product.Width = model.Width;
         product.Height = model.Height;
         product.Description = model.Description;
         product.Price = model.Price;
         product.IsOutOfStock = model.IsOutOfStock;
         product.CreationDate = model.CreationDate;
         product.LastModifiedDate = model.LastModifiedDate;
     }
     return product;
 }