예제 #1
0
        public ActionResult Create(EditProductItem item)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var productItem = new ModelLayer.Product() { ProductName = item.ProductName, Barcode = item.Barcode};

                    _productRepository.InsertOrUpdate(productItem);
                    _productRepository.SaveChanges();

                    return RedirectToAction("Index");
                }
                catch
                {
                    ViewBag.MessageError = "Data error";
                }
            }
            return View();
        }
예제 #2
0
        public ActionResult Edit(int id)
        {
            var producteItem = _productRepository.GetById(id);
            if (producteItem == null)
            {
                return View("Error");
            }

            var editProductItem = new EditProductItem()
                {
                    Id = producteItem.Id,
                    ProductName = producteItem.ProductName,
                    Barcode = producteItem.Barcode
                };

            if (Request.IsAjaxRequest())
            {
                return PartialView("_EditPartial", editProductItem);
            }
            return View(editProductItem);
        }
예제 #3
0
        public ActionResult Edit(EditProductItem item)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var productItem = _productRepository.GetById(item.Id);

                    productItem.ProductName = item.ProductName;
                    productItem.Barcode = item.Barcode;

                    _productRepository.InsertOrUpdate(productItem);
                    _productRepository.SaveChanges();

                    return RedirectToAction("Index");
                }
                catch
                {
                    ViewBag.MessageError = "Data error";
                }
            }
            return View();
        }