Пример #1
0
        /// <summary>
        /// </summary>
        /// <param name="product"></param>
        /// <returns>true of changes were made</returns>
        public Product Add(Product product)
        {
            var e = _mapper.Map <ProductEntity>(product);

            _dbProducts.Products.Add(e);
            _dbProducts.SaveChanges();
            return(_mapper.Map <Product>(e));
        }
 public bool DeleteProduct(int id)
 {
     using (var db = new EfProducts())
     {
         db.Products.Remove(db.Products.Find(id));
         return db.SaveChanges() >= 1;
     }
 }
Пример #3
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));
     }
 }
        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;
            }
        }
Пример #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);
        }
Пример #6
0
 public void Save()
 {
     context.SaveChanges();
 }