This commit is contained in:
Danil Markov 2023-04-21 13:51:31 +04:00
parent 9b28d6a5f9
commit 2419d6a9f7
6 changed files with 26 additions and 26 deletions

View File

@ -52,7 +52,7 @@ namespace LawFirmBusinessLogic.BusinessLogics
{
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model);
CheckModel(model, false);
if (_orderStorage.Update(model) == null)
{
model.Status--;

View File

@ -13,19 +13,19 @@ namespace LawFirmDatabaseImplement.Models
public string DocumentName { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
private Dictionary<int, (IBlankModel, int)>? _productBlanks = null;
private Dictionary<int, (IBlankModel, int)>? _documentBlanks = null;
[NotMapped]
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
{
get
{
if (_productBlanks == null)
if (_documentBlanks == null)
{
_productBlanks = Blanks
_documentBlanks = Blanks
.ToDictionary(recPC => recPC.BlankId, recPC =>
(recPC.Blank as IBlankModel, recPC.Count));
}
return _productBlanks;
return _documentBlanks;
}
}
[ForeignKey("DocumentId")]
@ -61,15 +61,15 @@ namespace LawFirmDatabaseImplement.Models
public void UpdateBlanks(LawFirmDatabase context,
DocumentBindingModel model)
{
var productBlanks = context.DocumentBlanks.Where(rec =>
var documentBlanks = context.DocumentBlanks.Where(rec =>
rec.DocumentId == model.Id).ToList();
if (productBlanks != null && productBlanks.Count > 0)
if (documentBlanks != null && documentBlanks.Count > 0)
{ // удалили те, которых нет в модели
context.DocumentBlanks.RemoveRange(productBlanks.Where(rec
context.DocumentBlanks.RemoveRange(documentBlanks.Where(rec
=> !model.DocumentBlanks.ContainsKey(rec.BlankId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateBlank in productBlanks)
foreach (var updateBlank in documentBlanks)
{
updateBlank.Count =
model.DocumentBlanks[updateBlank.BlankId].Item2;
@ -77,18 +77,18 @@ namespace LawFirmDatabaseImplement.Models
}
context.SaveChanges();
}
var product = context.Documents.First(x => x.Id == Id);
var document = context.Documents.First(x => x.Id == Id);
foreach (var pc in model.DocumentBlanks)
{
context.DocumentBlanks.Add(new DocumentBlank
{
Document = product,
Document = document,
Blank = context.Blanks.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_productBlanks = null;
_documentBlanks = null;
}
}

View File

@ -50,14 +50,14 @@ namespace LawFirmFileImplement.Implements
}
public DocumentViewModel? Update(DocumentBindingModel model)
{
var ship = source.Documents.FirstOrDefault(x => x.Id == model.Id);
if (ship == null)
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
if (document == null)
{
return null;
}
ship.Update(model);
document.Update(model);
source.SaveDocuments();
return ship.GetViewModel;
return document.GetViewModel;
}
public DocumentViewModel? Delete(DocumentBindingModel model)
{

View File

@ -38,10 +38,10 @@ namespace LawFirmFileImplement.Implements
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var ship = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId);
if (ship != null)
var document = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId);
if (document != null)
{
viewModel.DocumentName = ship.DocumentName;
viewModel.DocumentName = document.DocumentName;
}
return viewModel;
}

View File

@ -11,20 +11,20 @@ namespace LawFirmFileImplement.Models
public string DocumentName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Blanks { get; private set; } = new();
private Dictionary<int, (IBlankModel, int)>? _productBlanks =
private Dictionary<int, (IBlankModel, int)>? _documentBlanks =
null;
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
{
get
{
if (_productBlanks == null)
if (_documentBlanks == null)
{
var source = DataFileSingleton.GetInstance();
_productBlanks = Blanks.ToDictionary(x => x.Key, y =>
_documentBlanks = Blanks.ToDictionary(x => x.Key, y =>
((source.Blanks.FirstOrDefault(z => z.Id == y.Key) as IBlankModel)!,
y.Value));
}
return _productBlanks;
return _documentBlanks;
}
}
public static Document? Create(DocumentBindingModel model)
@ -70,7 +70,7 @@ namespace LawFirmFileImplement.Models
Price = model.Price;
Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x =>
x.Value.Item2);
_productBlanks = null;
_documentBlanks = null;
}
public DocumentViewModel GetViewModel => new()
{

View File

@ -45,12 +45,12 @@ namespace LawFirmView
try
{
int id = Convert.ToInt32(comboBoxDocument.SelectedValue);
var product = _logicD.ReadElement(new DocumentSearchModel
var document = _logicD.ReadElement(new DocumentSearchModel
{
Id = id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
textBoxSum.Text = Math.Round(count * (document?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)