Ejemplo n.º 1
0
        public bool Update(Product product)
        {
            //Product productDbVersion =  productRepository.Find(product.Id);

            //if (productDbVersion != null)
            //{
            //    //productDbVersion.Category =
            //    //    categoryRepository.GetAllCategories().Where(x => x.Id == product.CategoryId).FirstOrDefault();
            //    using (TransactionScope transaction = new TransactionScope())
            //    {
            //        productDbVersion.Category.Name = "KHurram U" + DateTime.Now.Minute;
            //        productDbVersion.Name = product.Name;

            //        //Thread.Sleep(20*1000);
            //        productRepository.SaveChanges();
            //        throw new Exception();

            //        transaction.Complete();

            //    }
            //}

            if (ValidateProduct(product))
            {
                productRepository.Update(product);
                productRepository.SaveChanges();
                return true;
            }

            return false;
        }
Ejemplo n.º 2
0
 public bool AddProduct(Product product)
 {
     if(ValidateProduct(product))
     {
         productRepository.Add(product);
         productRepository.SaveChanges();
         return true;
     }
     return false;
 }
Ejemplo n.º 3
0
        public void DeleteProduct(Product product)
        {
            Product productDbVersion = FindProduct(product.Id);
            if (productDbVersion == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Product with Id {0} not found!", product.Id));
            }

            productRepository.Delete(productDbVersion);
            productRepository.SaveChanges();
        }
Ejemplo n.º 4
0
 /// <summary>
 ///  Create web model from entity
 /// </summary>
 public static Models.Product CreateFrom(this MainDomain.Product source)
 {
     return(new Models.Product
     {
         Id = source.Id,
         Name = source.Name,
         CategoryId = source.CategoryId,
         Description = source.Description,
         Price = source.Price,
         Category = source.Category.CreateFrom()
     });
 }
Ejemplo n.º 5
0
 private bool ValidateProduct(Product product)
 {
     Product productDbVersion = productRepository.GetProductByName(product.Name, product.Id);
     return productDbVersion == null;
 }