Exemple #1
0
 public async Task <bool> DeleteProduct(int productId)
 {
     using (DeveloperTestDBContext db = new DeveloperTestDBContext())
     {
         DataAccessLayer.EntityModels.Products product =
             db.Products.Where(x => x.ProductId == productId).FirstOrDefault();
         if (product != null)
         {
             db.Products.Remove(product);
         }
         return(await db.SaveChangesAsync() >= 1);
     }
 }
Exemple #2
0
        public async Task <bool> SaveProduct(ProductModel productModel)
        {
            using (DeveloperTestDBContext db = new DeveloperTestDBContext())
            {
                DataAccessLayer.EntityModels.Products product = db.Products.Where
                                                                    (x => x.ProductId == productModel.ProductId).FirstOrDefault();
                if (product == null)
                {
                    product = new Products()
                    {
                        Name  = productModel.Name,
                        Price = productModel.Price,
                    };
                    db.Products.Add(product);
                }
                else
                {
                    product.Name  = productModel.Name;
                    product.Price = productModel.Price;
                }

                return(await db.SaveChangesAsync() >= 1);
            }
        }