public ActionResult Add(string id)
        {
            try
            {
                var product = new Product
                {
                    Name = id,
                    CreatedBy = "adamstephensen",
                    LastModifiedBy = "adamstephensen",
                };

                _productRepository.Add(product);
                _unitOfWork.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException deve)
            {
                IEnumerable<DbValidationError> errors = deve.EntityValidationErrors.SelectMany(c => c.ValidationErrors);
                
                var message = string.Join(",",errors.Select(c => c.ErrorMessage));

                return Content(message);
            }
            catch (Exception ex)
            {
                return Content(ex.ToString());
            }

            return RedirectToAction("Index");
        }
Пример #2
0
        public ActionResult Create()
        {
            using (_unitOfWork)
            {
                var order = new Order{};
                _orderRepository.Add(order);

                var product = new Product();
                _productRepository.Add(product);

                _unitOfWork.SaveChanges();
            }
            return Content("it worked");
        }
        public ActionResult Add(string id)
        {
            try
            {
                var product = new Product
                {
                    Name = id,
                    CreatedBy = "adamstephensen",
                    LastModifiedBy = "adamstephensen",
                };

                _productService.Add(product);
                
            }
            catch (Exception ex)
            {
                return Content(ex.Message);
            }

            return RedirectToAction("Index");
        }
Пример #4
0
 public Product Update(Product product)
 {
     _productRepository.Update(product);
     _unitOfWork.SaveChanges();
     return product;
 }
Пример #5
0
 public Product Add(Product product)
 {
     _productRepository.Add(product);
     _unitOfWork.SaveChanges();
     return product;
 }