class product

This commit is contained in:
Aneliya Konarcheva
2021-03-07 10:04:51 +02:00
parent 54e64cbb87
commit 39e9737476
3 changed files with 46 additions and 2 deletions

View File

@@ -1,12 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuminousSales.Data;
using LuminousSales.Data.Model;
namespace LuminousSales.Business
{
public class ProductBusiness
{
private ProductContext productContext;
public List<Product> GetAll()
{
using (productContext = new ProductContext())
{
return productContext.Products.ToList();
}
}
public Product Get(int id)
{
using (productContext = new ProductContext())
{
return productContext.Products.Find(id);
}
}
public void Add(Product product)
{
using (productContext = new ProductContext())
{
productContext.Products.Add(product);
productContext.SaveChanges();
}
}
public void Update(Product product)
{
}
}
}

View File

@@ -6,5 +6,9 @@ namespace LuminousSales.Data.Model
{
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public int AmountInStock { get; set; }
}
}

View File

@@ -1,10 +1,17 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Text;
using LuminousSales.Data.Model;
namespace LuminousSales.Data
{
public class ProductContext
public class ProductContext : DbContext
{
public ProductContext():base("name = ProductContext")
{
}
public DbSet<Product> Products { get; set; }
}
}