예제 #1
0
        public async Task <bool> SaveProduct(ProductModel productModel)
        {
            using (MarvelDCStoreDBContext db = new MarvelDCStoreDBContext())
            {
                Product product = db.Product.Where(x => x.ProductID == productModel.ProductID).FirstOrDefault();

                if (product == null)
                {
                    product = new Product()
                    {
                        ProductName  = productModel.ProductName,
                        ItemQuantity = productModel.ItemQuantity,
                        UnitPrice    = productModel.UnitPrice
                    };

                    db.Product.Add(product);
                }
                else
                {
                    product.ProductName  = productModel.ProductName;
                    product.ItemQuantity = productModel.ItemQuantity;
                    product.UnitPrice    = productModel.UnitPrice;
                }

                return(await db.SaveChangesAsync() >= 1);
            }
        }
예제 #2
0
        public async Task <bool> DeleteProduct(int productId)
        {
            using (MarvelDCStoreDBContext db = new MarvelDCStoreDBContext())
            {
                Product product = db.Product.Where(x => x.ProductID == productId).FirstOrDefault();

                if (product != null)
                {
                    db.Product.Remove(product);
                }

                return(await db.SaveChangesAsync() >= 1);
            }
        }
예제 #3
0
 public async Task <List <ProductModel> > GetProducts()
 {
     using (MarvelDCStoreDBContext db = new MarvelDCStoreDBContext())
     {
         return(await(from a in db.Product.AsNoTracking()
                      select new ProductModel
         {
             ProductID = a.ProductID,
             ProductName = a.ProductName,
             ItemQuantity = a.ItemQuantity,
             UnitPrice = a.UnitPrice
         }).ToListAsync());
     }
 }
예제 #4
0
 public async Task <ProductModel> GetProductData(int productId)
 {
     using (MarvelDCStoreDBContext db = new MarvelDCStoreDBContext())
     {
         return(await(from a in db.Product.AsNoTracking()
                      where a.ProductID.Equals(productId)
                      select new ProductModel
         {
             ProductID = a.ProductID,
             ProductName = a.ProductName,
             ItemQuantity = a.ItemQuantity,
             UnitPrice = a.UnitPrice
         }).FirstOrDefaultAsync());
     }
 }