commiting stock controller

This commit is contained in:
Aneliya Konarcheva
2021-03-18 18:13:46 +02:00
parent dbfbed4b5d
commit b5a035249e
4 changed files with 123 additions and 63 deletions

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Business.Business.Sales
{
interface IStockController<T>
{
ICollection<T> GetAll();
T GetById(int id);
T GetByName(string name);
void AddProduct(T product);
void LoadProductByName(T product);
void LoadProductById(int id);
void Sale(int id);
void Sale(string name);
}
}

View File

@@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;
using Models;
using Models.Models;
namespace Business.Business.Sales
{
public class AddStock
{
private LuminousContext productContext;
public void AddProduct(Product product)
{
using (productContext = new LuminousContext())
{
productContext.Product.Add(product);
productContext.SaveChanges();
}
}
public void AddStocks(Stock stock)
{
using (productContext = new LuminousContext())
{
productContext.Stock.Add(stock);
productContext.SaveChanges();
}
}
}
}

View File

@@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Models;
namespace Business.Business.Sales
{
public class Sales
{
private LuminousContext productContext;
public void Sale(int id)
{
using (productContext = new LuminousContext())
{
var product = productContext.Product.Find(id);
if (product != null)
{
productContext.Product.Remove(product);
productContext.SaveChanges();
}
}
}
}
}

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.EntityFrameworkCore;
using Models;
using Models.Models;
namespace Business.Business.Sales
{
public class StockController : IStockController<Product>
{
private LuminousContext context;
public ICollection<Product> GetAll()
{
using (context = new LuminousContext())
{
return context.Product.ToList();
}
}
public Product GetById(int id)
{
using (context = new LuminousContext())
{
return context.Product.Find(id);
}
}
public void AddProduct(Product product)
{
using (context = new LuminousContext())
{
context.Product.Add(product);
context.SaveChanges();
}
}
public void LoadProductById(int id)
{
using (context = new LuminousContext())
{
var item = context.Product.Find(id);
if (item != null)
{
context.Entry(item).CurrentValues.SetValues(id);
context.SaveChanges();
}
}
}
public void LoadProductByName(Product product)
{
using (context = new LuminousContext())
{
var item = context.Product.Find(product.Id);
if (item !=null)
{
context.Entry(item).CurrentValues.SetValues(product);
context.SaveChanges();
}
}
}
public void Sale(int id)
{
using (context = new LuminousContext())
{
var product = context.Product.Find(id);
if (product != null)
{
context.Product.Remove(product);
context.SaveChanges();
}
}
}
public void Sale(string name)
{
using (context = new LuminousContext())
{
var product = context.Product.Find(name);
if (product !=null)
{
context.Product.Remove(product);
context.SaveChanges();
}
}
}
public Product GetByName(string name)
{
throw new NotImplementedException();
}
}
}