ура работает!
This commit is contained in:
parent
4786396747
commit
a10bd7a5ad
@ -4,6 +4,8 @@ using StorehouseContracts.SearchModels;
|
||||
using StorehouseContracts.StoragesContracts;
|
||||
using StorehouseContracts.ViewModels;
|
||||
using StorehouseDatabaseImplement.Models;
|
||||
using StorehouseDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace StorehouseDatabaseImplement.Implements
|
||||
{
|
||||
@ -41,12 +43,18 @@ namespace StorehouseDatabaseImplement.Implements
|
||||
|
||||
public SaleViewModel? Insert(SaleBindingModel model)
|
||||
{
|
||||
using var context = new StorehouseDatabase();
|
||||
var product = context.Products.FirstOrDefault(p => p.Id == model.ProductId);
|
||||
if (product == null || model.SaleNum > product.ProductNum)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var newSale = Sale.Create(model);
|
||||
if (newSale == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new StorehouseDatabase();
|
||||
product.ProductNum -= model.SaleNum;
|
||||
context.Sales.Add(newSale);
|
||||
context.SaveChanges();
|
||||
return context.Sales.Include(x => x.Product).Include(x => x.Client).FirstOrDefault(x => x.Id == newSale.Id)?.GetViewModel;
|
||||
|
@ -41,12 +41,18 @@ namespace StorehouseDatabaseImplement.Implements
|
||||
|
||||
public SupplyViewModel? Insert(SupplyBindingModel model)
|
||||
{
|
||||
using var context = new StorehouseDatabase();
|
||||
var product = context.Products.FirstOrDefault(p => p.Id == model.ProductId);
|
||||
if (product == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var newSupply = Supply.Create(model);
|
||||
if (newSupply == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new StorehouseDatabase();
|
||||
product.ProductNum += model.SupplyNum;
|
||||
context.Supplys.Add(newSupply);
|
||||
context.SaveChanges();
|
||||
return context.Supplys.Include(x => x.Product).Include(x => x.Provider).FirstOrDefault(x => x.Id == newSupply.Id)?.GetViewModel;
|
||||
|
@ -11,7 +11,7 @@ using StorehouseDatabaseImplement;
|
||||
namespace StorehouseDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(StorehouseDatabase))]
|
||||
[Migration("20240515061146_FirstMigration")]
|
||||
[Migration("20240515071016_FirstMigration")]
|
||||
partial class FirstMigration
|
||||
{
|
||||
/// <inheritdoc />
|
Loading…
Reference in New Issue
Block a user