SHARE
TWEET

Untitled

a guest Aug 25th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Microsoft.EntityFrameworkCore;
  2. using ProductService.DBContext;
  3. using ProductService.Models;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. namespace ProductService.Repository
  8. {
  9.     public class ProductRepository : IProductRepository
  10.     {
  11.         private readonly IProductContext _dbContext;
  12.  
  13.         public ProductRepository(/*IProductContext productContext*/)
  14.         {
  15.             //    _dbContext = productContext;
  16.         }
  17.  
  18.         public void DeleteProduct(int productId)
  19.         {
  20.             var product = _dbContext.Products.Find(productId);
  21.             _dbContext.Products.Remove(product);
  22.             SaveChanges();
  23.         }
  24.  
  25.         public Product GetProductByID(int productId)
  26.         {
  27.             return _dbContext.Products.Find(productId);
  28.         }
  29.  
  30.         public IEnumerable<Product> GetProducts()
  31.         {
  32.             return _dbContext.Products.AsEnumerable();
  33.         }
  34.  
  35.         public void InsertProduct(Product product)
  36.         {
  37.             _dbContext.Products.Add(product);
  38.             SaveChanges();
  39.         }
  40.  
  41.         public void UpdateProductsAmount(ProductDetails productDetails)
  42.         {
  43.             Product product = GetProductByID(productDetails.ProductId);
  44.             product.Amount += productDetails.ProductAmount;
  45.             SaveChanges();
  46.         }
  47.  
  48.         public void SaveChanges()
  49.         {
  50.             _dbContext.SaveChanges();
  51.         }
  52.     }
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top