コード例 #1
0
        public ActionResult Add(ProductDto newProduct)
        {
            try
            {
                _productService.Insert(newProduct);

                return RedirectToAction("List", new { Id = EnumHelper.EnumTextToInt(newProduct.ProductCategory.ProductType, typeof(Enums.ProductType)) });
            }
            catch
            {
                ViewBag.FormMode = "Add";
                ViewBag.ProductCategoryList = new SelectList(_productService.FetchProductCategories(EnumHelper.EnumTextToInt(newProduct.ProductCategory.ProductType, typeof(Enums.ProductType))), "Id", "Name");
                ViewBag.ProductTypeFilter = EnumHelper.ProductTypeToEnum(newProduct.ProductCategory.ProductType);
                return View("Edit");
            }
        }
コード例 #2
0
        public void Update(ProductDto editedItem)
        {
            //Begin DB transaction
            _productDb.BeginTransaction();

            try
            {
                //Get record
                _productDb.Update(Mapper.Map<ProductDto, ProductDomain>(editedItem));
                _productDb.CompleteTransaction();
                Logger.Info(String.Format("Product #{0} Updated Successfully", editedItem.Id));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                _productDb.AbortTransaction();
                throw;
            }
        }
コード例 #3
0
        public ActionResult Edit(int id, ProductDto editedProduct)
        {
            try
            {
                _productService.Update(editedProduct);

                return RedirectToAction("List", new { Id = EnumHelper.EnumTextToInt(editedProduct.ProductCategory.ProductType, typeof(Enums.ProductType)) });
            }
            catch
            {
                ViewBag.FormMode = "Edit";
                ViewBag.ProductCategoryList = new SelectList(_productService.FetchProductCategories(EnumHelper.EnumTextToInt(editedProduct.ProductCategory.ProductType, typeof(Enums.ProductType))), "Id", "Name");
                ViewBag.ProductTypeFilter = EnumHelper.ProductTypeToEnum(editedProduct.ProductCategory.ProductType);
                return View();
            }
        }
コード例 #4
0
        public void Insert(ProductDto newRecord)
        {
            //Begin DB transaction
            _productDb.BeginTransaction();

            try
            {
                //Insert record
                _productDb.Insert(Mapper.Map<ProductDto, ProductDomain>(newRecord));
                _productDb.CompleteTransaction();

                Logger.Info(String.Format("Product '{0}' Inserted Successfully", newRecord.Name));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                _productDb.AbortTransaction();
                throw;
            }
        }