Required fixes were implemented.
This commit is contained in:
parent
81fc42d59b
commit
e41fcdad52
@ -25,7 +25,6 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
public ReportLogic(IDressStorage dressStorage, IMaterialStorage materialStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||
{
|
||||
_dressStorage = dressStorage;
|
||||
_materialStorage = materialStorage;
|
||||
_orderStorage = orderStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
@ -34,7 +33,6 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
|
||||
public List<ReportDressMaterialViewModel> GetDressMaterial()
|
||||
{
|
||||
var components = _materialStorage.GetFullList();
|
||||
var products = _dressStorage.GetFullList();
|
||||
var list = new List<ReportDressMaterialViewModel>();
|
||||
foreach (var product in products)
|
||||
@ -45,14 +43,11 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
Materials = new List<(string Material, int count)>(),
|
||||
TotalAmount = 0
|
||||
};
|
||||
foreach (var material in components)
|
||||
foreach (var material in product.DressComponents)
|
||||
{
|
||||
if (product.DressComponents.ContainsKey(material.ID))
|
||||
{
|
||||
record.Materials.Add(new (material.ComponentName, product.DressComponents[material.ID].Item2));
|
||||
record.TotalAmount +=
|
||||
product.DressComponents[material.ID].Item2;
|
||||
}
|
||||
record.Materials.Add(new (material.Value.Item1.ComponentName, material.Value.Item2));
|
||||
record.TotalAmount += material.Value.Item2;
|
||||
|
||||
}
|
||||
list.Add(record);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace DressAtelierDatabaseImplementation
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Initial Catalog=DressAtelierDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Server=localhost\SQLEXPRESS;Initial Catalog=DressAtelierDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
@ -52,29 +52,21 @@ namespace DressAtelierDatabaseImplementation.Implements
|
||||
}
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Dress).FirstOrDefault(x => x.ID == model.ID)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Dress).FirstOrDefault(x => x.ID == newOrder.ID)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new DressAtelierDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
|
||||
var order = context.Orders.FirstOrDefault(x => x.ID == model.ID);
|
||||
if(order == null)
|
||||
{
|
||||
var order = context.Orders.FirstOrDefault(x => x.ID == model.ID);
|
||||
if(order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Dress).FirstOrDefault(x => x.ID == model.ID)?.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Dress).FirstOrDefault(x => x.ID == model.ID)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
@ -87,7 +79,7 @@ namespace DressAtelierDatabaseImplementation.Implements
|
||||
}
|
||||
context.Orders.Remove(order);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Dress).FirstOrDefault(x => x.ID == model.ID)?.GetViewModel;
|
||||
return order.GetViewModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -53,21 +53,6 @@ namespace DressAtelierDatabaseImplementation.Models
|
||||
|
||||
}
|
||||
|
||||
public static Order Create(OrderViewModel model)
|
||||
{
|
||||
return new Order()
|
||||
{
|
||||
ID = model.ID,
|
||||
DressID = model.DressID,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -83,12 +68,13 @@ namespace DressAtelierDatabaseImplementation.Models
|
||||
{
|
||||
ID = ID,
|
||||
DressID = DressID,
|
||||
DressName = Dress.DressName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
DressName = Dress.DressName
|
||||
DateImplement = DateImplement
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ using DressAtelierBusinessLogic.OfficePackage;
|
||||
using DressAtelierBusinessLogic.OfficePackage.Implements;
|
||||
using DressAtelierContracts.BusinessLogicContracts;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierFileImplement.Implements;
|
||||
using DressAtelierDatabaseImplementation.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
Loading…
Reference in New Issue
Block a user