public bool DeleteProduct(int id)
 {
     using (var db = new EfProducts())
     {
         db.Products.Remove(db.Products.Find(id));
         return db.SaveChanges() >= 1;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Product DeleteProduct(int id)
 {
     using (var db = new EfProducts())
     {
         var e = db.Products.Find(id);
         db.Products.Remove(e);
         db.SaveChanges();
         return(_mapper.Map <Product>(e));
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// </summary>
 /// <param name="dbProducts"></param>
 public ProductRepository(EfProducts dbProducts)
 {
     _dbProducts = dbProducts;
     // Configure AutoMapper
     _config = new MapperConfiguration(cfg =>
     {
         cfg.CreateMap <Product, ProductEntity>().ReverseMap();
     });
     _config.AssertConfigurationIsValid();
     _mapper = _config.CreateMapper();
 }
        public bool Update(Product product)
        {
            var id = product.ProductId;

            using (var db = new EfProducts())
            {
                var fromDb = db.Products.Find(id);

                fromDb.IntroductionDate = product.IntroductionDate;
                fromDb.Price = product.Price;
                fromDb.ProductId = id;
                fromDb.ProductName = product.ProductName;
                fromDb.Url = product.Url;
                fromDb.Summary = product.Summary;

                return db.SaveChanges() >= 1;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public Product Update(Product product)
        {
            var id = product.ProductId;

            using (var db = new EfProducts())
            {
                var e = db.Products.Find(id);

                if (e != null)
                {
                    e.IntroductionDate = product.IntroductionDate;
                    e.Price            = product.Price;
                    e.ProductName      = product.ProductName;
                    e.Url     = product.Url;
                    e.Summary = product.Summary;

                    db.Entry(e).State = EntityState.Modified;
                    db.SaveChanges();

                    return(_mapper.Map <Product>(e));
                }
            }
            return(null);
        }
 public ProductRepository(EfProducts dbProducts)
 {
     _dbProducts = dbProducts;
 }
 public GenericRepository(EfProducts context)
 {
     this.context = context;
     dbSet        = context.Set <TEntity>();
 }