コード例 #1
0
 public bool DeleteProduct(int id)
 {
     using (var db = new EfProducts())
     {
         db.Products.Remove(db.Products.Find(id));
         return db.SaveChanges() >= 1;
     }
 }
コード例 #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));
     }
 }
コード例 #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();
 }
コード例 #4
0
        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 ProductRepository(EfProducts dbProducts)
 {
     _dbProducts = dbProducts;
 }
コード例 #7
0
 public GenericRepository(EfProducts context)
 {
     this.context = context;
     dbSet        = context.Set <TEntity>();
 }