public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
예제 #2
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);
        }