57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
|
using demo_trade.Data.RemoteData.Entity;
|
|||
|
using Microsoft.EntityFrameworkCore;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace demo_trade.Data.Repository
|
|||
|
{
|
|||
|
public class SQLProductRepository : IProductRepository
|
|||
|
{
|
|||
|
private TradeContext _tradeContext;
|
|||
|
|
|||
|
public SQLProductRepository() {
|
|||
|
_tradeContext = new TradeContext();
|
|||
|
}
|
|||
|
public void Dispose()
|
|||
|
{
|
|||
|
GC.SuppressFinalize(this);
|
|||
|
}
|
|||
|
|
|||
|
public Product? GetProductByArticleNumber(string articleNumber)
|
|||
|
{
|
|||
|
return _tradeContext.Products.Where(it => articleNumber == it.Productarticlenumber).FirstOrDefault();
|
|||
|
}
|
|||
|
|
|||
|
public List<Product> GetProducts()
|
|||
|
{
|
|||
|
|
|||
|
return _tradeContext.Products.Include(manfucture => manfucture.Manufacturer).Select(it => it).ToList();
|
|||
|
}
|
|||
|
|
|||
|
public bool RemoveProductByArticleNumber(string articleNumber)
|
|||
|
{
|
|||
|
Product? product = GetProductByArticleNumber(articleNumber);
|
|||
|
if (product != null)
|
|||
|
{
|
|||
|
_tradeContext.Products.Remove(product);
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public void Save()
|
|||
|
{
|
|||
|
_tradeContext.SaveChanges();
|
|||
|
}
|
|||
|
|
|||
|
public Product? UpdateProductByArticleNumber(Product product)
|
|||
|
{
|
|||
|
_tradeContext.Entry(product).State = EntityState.Modified;
|
|||
|
return product;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|