Доработка логики и форм
This commit is contained in:
parent
3923eacebd
commit
313cd7b2c1
@ -43,6 +43,14 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("AddCarInShop element not found");
|
||||
return false;
|
||||
}
|
||||
var quantityCars = 0;
|
||||
foreach (var ShopCar in element.Cars)
|
||||
quantityCars += ShopCar.Value.Item2;
|
||||
if((quantityCars + quantity) > element.Fullness)
|
||||
{
|
||||
throw new ArgumentException("Превышена максимальная вместимость", nameof(quantity));
|
||||
}
|
||||
|
||||
|
||||
_logger.LogInformation("AddCarInShop find. Id:{Id}", element.Id);
|
||||
|
||||
@ -63,11 +71,56 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
Adress = element.Adress,
|
||||
ShopName = element.ShopName,
|
||||
DateOpen = element.DateOpen,
|
||||
Fullness = element.Fullness,
|
||||
Cars = element.Cars
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddCar(ICarModel car, int quantity)
|
||||
{
|
||||
if (CheckShops(quantity))
|
||||
{
|
||||
foreach(var shop in ReadList(null))
|
||||
{
|
||||
if(quantity==0) return true;
|
||||
int OccupiedPlaces = 0;
|
||||
foreach(var ShopCar in shop.Cars)
|
||||
{
|
||||
OccupiedPlaces += ShopCar.Value.Item2;
|
||||
}
|
||||
int EmptyPlaces = shop.Fullness - OccupiedPlaces;
|
||||
if(EmptyPlaces > 0)
|
||||
{
|
||||
EmptyPlaces = EmptyPlaces > quantity ? quantity : EmptyPlaces;
|
||||
AddCar(new CarShopSearchModel { Id = shop.Id}, car, EmptyPlaces);
|
||||
quantity -= EmptyPlaces;
|
||||
if (quantity == 0) return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CheckShops( int quantity)
|
||||
{
|
||||
foreach(var shop in ReadList(null))
|
||||
{
|
||||
int OccupiedPlaces = 0;
|
||||
foreach(var car in shop.Cars)
|
||||
{
|
||||
OccupiedPlaces += car.Value.Item2;
|
||||
}
|
||||
int EmptyPlaces = shop.Fullness - OccupiedPlaces;
|
||||
quantity -= EmptyPlaces;
|
||||
}
|
||||
if(quantity <= 0)
|
||||
return true;
|
||||
else return false;
|
||||
|
||||
}
|
||||
|
||||
public bool Create(CarShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
@ -18,10 +18,14 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
public OrderLogic(ILogger<ComponentLogic> logger, IOrderStorage orderStorage)
|
||||
private readonly ICarShopLogic _carShopLogic;
|
||||
private readonly ICarStorage _carStorage;
|
||||
public OrderLogic(ILogger<ComponentLogic> logger, IOrderStorage orderStorage, ICarShopLogic carShopLogic, ICarStorage carStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_carShopLogic = carShopLogic;
|
||||
_carStorage = carStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
@ -58,7 +62,16 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
model.Status = newStatus;
|
||||
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
if (!_carShopLogic.AddCar(_carStorage.GetElement(new CarSearchModel { Id = model.CarId }), model.Count))
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Small places in shops");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
|
@ -18,5 +18,7 @@ namespace AutomobilePlantContracts.BusinessLogicsContracts
|
||||
bool Update(CarShopBindingModel model);
|
||||
bool Delete(CarShopBindingModel model);
|
||||
bool AddCar(CarShopSearchModel model, ICarModel car, int quantity);
|
||||
bool CheckShops(int quantity);
|
||||
bool AddCar(ICarModel car, int quantity);
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ namespace AutomobilePlantContracts.StoragesContracts
|
||||
{
|
||||
List<CarShopViewModel> GetFullList();
|
||||
List<CarShopViewModel> GetFilteredList(CarShopSearchModel model);
|
||||
bool CheckShop (CarShopSearchModel model);
|
||||
bool TrySell (CarShopSearchModel model, ICarModel car);
|
||||
bool TrySell ( ICarModel car, int quantity);
|
||||
CarShopViewModel? GetElement(CarShopSearchModel model);
|
||||
CarShopViewModel? Insert(CarShopBindingModel model);
|
||||
CarShopViewModel? Update(CarShopBindingModel model);
|
||||
|
@ -119,12 +119,8 @@ namespace AutomobilePlantListImplement.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool CheckShop(CarShopSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool TrySell(CarShopSearchModel model, ICarModel car)
|
||||
public bool TrySell(ICarModel car, int quantity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
19
AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
generated
19
AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
generated
@ -40,6 +40,7 @@
|
||||
this.IssuedOrderButton = new System.Windows.Forms.Button();
|
||||
this.UpdateListButton = new System.Windows.Forms.Button();
|
||||
this.AddShopCarButton = new System.Windows.Forms.Button();
|
||||
this.Sellbutton = new System.Windows.Forms.Button();
|
||||
this.MenuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -69,21 +70,21 @@
|
||||
// ИзделияToolStripMenuItem
|
||||
//
|
||||
this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
|
||||
this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||
this.ИзделияToolStripMenuItem.Text = "Изделия";
|
||||
this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
|
||||
//
|
||||
// КомпонентыToolStripMenuItem
|
||||
//
|
||||
this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
|
||||
this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||
this.КомпонентыToolStripMenuItem.Text = "Компоненты";
|
||||
this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
|
||||
//
|
||||
// магазиныToolStripMenuItem
|
||||
//
|
||||
this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||
this.магазиныToolStripMenuItem.Text = "Магазины";
|
||||
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
|
||||
//
|
||||
@ -163,11 +164,22 @@
|
||||
this.AddShopCarButton.UseVisualStyleBackColor = true;
|
||||
this.AddShopCarButton.Click += new System.EventHandler(this.AddShopCarButton_Click);
|
||||
//
|
||||
// Sellbutton
|
||||
//
|
||||
this.Sellbutton.Location = new System.Drawing.Point(832, 507);
|
||||
this.Sellbutton.Name = "Sellbutton";
|
||||
this.Sellbutton.Size = new System.Drawing.Size(143, 56);
|
||||
this.Sellbutton.TabIndex = 8;
|
||||
this.Sellbutton.Text = "Продать";
|
||||
this.Sellbutton.UseVisualStyleBackColor = true;
|
||||
this.Sellbutton.Click += new System.EventHandler(this.Sellbutton_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(989, 600);
|
||||
this.Controls.Add(this.Sellbutton);
|
||||
this.Controls.Add(this.AddShopCarButton);
|
||||
this.Controls.Add(this.UpdateListButton);
|
||||
this.Controls.Add(this.IssuedOrderButton);
|
||||
@ -203,5 +215,6 @@
|
||||
private Button UpdateListButton;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private Button AddShopCarButton;
|
||||
private Button Sellbutton;
|
||||
}
|
||||
}
|
@ -217,5 +217,16 @@ namespace AutomobilePlant
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void Sellbutton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
|
||||
|
||||
if (service is FormShopSell form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ namespace AutomobilePlant
|
||||
|
||||
_carComponents = view.Cars ?? new
|
||||
Dictionary<int, (ICarModel, int)>();
|
||||
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ namespace AutomobilePlant
|
||||
|
||||
var resultOperation = _shopLogic.AddCar(
|
||||
model: new() { Id = (int)ShopNameComboBox.SelectedValue },
|
||||
car: car,
|
||||
car: car,
|
||||
quantity: Convert.ToInt32(CountTextBox.Text)
|
||||
);
|
||||
|
||||
|
@ -46,6 +46,7 @@ namespace AutomobilePlant
|
||||
ShopNameTextBox.Text = view.ShopName;
|
||||
AdressTextBox.Text = view.Adress;
|
||||
DateOpenPicker.Value = view.DateOpen;
|
||||
FullnessnumericUpDown.Value = view.Fullness;
|
||||
_cars = view.Cars ?? new
|
||||
Dictionary<int, (ICarModel, int)>();
|
||||
LoadData();
|
||||
|
118
AutomobilePlant/AutomobilePlant/FormShopSell.Designer.cs
generated
Normal file
118
AutomobilePlant/AutomobilePlant/FormShopSell.Designer.cs
generated
Normal file
@ -0,0 +1,118 @@
|
||||
namespace AutomobilePlant
|
||||
{
|
||||
partial class FormShopSell
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.Carlabel = new System.Windows.Forms.Label();
|
||||
this.Countlabel = new System.Windows.Forms.Label();
|
||||
this.CarComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.CountnumericUpDown = new System.Windows.Forms.NumericUpDown();
|
||||
this.Sellbutton = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.CountnumericUpDown)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// Carlabel
|
||||
//
|
||||
this.Carlabel.AutoSize = true;
|
||||
this.Carlabel.Location = new System.Drawing.Point(42, 41);
|
||||
this.Carlabel.Name = "Carlabel";
|
||||
this.Carlabel.Size = new System.Drawing.Size(68, 20);
|
||||
this.Carlabel.TabIndex = 0;
|
||||
this.Carlabel.Text = "Машина";
|
||||
//
|
||||
// Countlabel
|
||||
//
|
||||
this.Countlabel.AutoSize = true;
|
||||
this.Countlabel.Location = new System.Drawing.Point(42, 101);
|
||||
this.Countlabel.Name = "Countlabel";
|
||||
this.Countlabel.Size = new System.Drawing.Size(90, 20);
|
||||
this.Countlabel.TabIndex = 1;
|
||||
this.Countlabel.Text = "Количество";
|
||||
//
|
||||
// CarComboBox
|
||||
//
|
||||
this.CarComboBox.FormattingEnabled = true;
|
||||
this.CarComboBox.Location = new System.Drawing.Point(161, 38);
|
||||
this.CarComboBox.Name = "CarComboBox";
|
||||
this.CarComboBox.Size = new System.Drawing.Size(151, 28);
|
||||
this.CarComboBox.TabIndex = 2;
|
||||
//
|
||||
// CountnumericUpDown
|
||||
//
|
||||
this.CountnumericUpDown.Location = new System.Drawing.Point(175, 99);
|
||||
this.CountnumericUpDown.Minimum = new decimal(new int[] {
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.CountnumericUpDown.Name = "CountnumericUpDown";
|
||||
this.CountnumericUpDown.Size = new System.Drawing.Size(137, 27);
|
||||
this.CountnumericUpDown.TabIndex = 3;
|
||||
this.CountnumericUpDown.Value = new decimal(new int[] {
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// Sellbutton
|
||||
//
|
||||
this.Sellbutton.Location = new System.Drawing.Point(123, 160);
|
||||
this.Sellbutton.Name = "Sellbutton";
|
||||
this.Sellbutton.Size = new System.Drawing.Size(94, 66);
|
||||
this.Sellbutton.TabIndex = 4;
|
||||
this.Sellbutton.Text = "Продать";
|
||||
this.Sellbutton.UseVisualStyleBackColor = true;
|
||||
this.Sellbutton.Click += new System.EventHandler(this.Sellbutton_Click);
|
||||
//
|
||||
// FormShopSell
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(362, 238);
|
||||
this.Controls.Add(this.Sellbutton);
|
||||
this.Controls.Add(this.CountnumericUpDown);
|
||||
this.Controls.Add(this.CarComboBox);
|
||||
this.Controls.Add(this.Countlabel);
|
||||
this.Controls.Add(this.Carlabel);
|
||||
this.Name = "FormShopSell";
|
||||
this.Text = "FormShopSell";
|
||||
((System.ComponentModel.ISupportInitialize)(this.CountnumericUpDown)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label Carlabel;
|
||||
private Label Countlabel;
|
||||
private ComboBox CarComboBox;
|
||||
private NumericUpDown CountnumericUpDown;
|
||||
private Button Sellbutton;
|
||||
}
|
||||
}
|
50
AutomobilePlant/AutomobilePlant/FormShopSell.cs
Normal file
50
AutomobilePlant/AutomobilePlant/FormShopSell.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||
using AutomobilePlantContracts.SearchModel;
|
||||
using AutomobilePlantContracts.StoragesContracts;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AutomobilePlant
|
||||
{
|
||||
public partial class FormShopSell : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICarLogic _carLogic;
|
||||
private readonly List<CarViewModel>? _listCars;
|
||||
private readonly ICarShopStorage _carShopStorage;
|
||||
public FormShopSell(ILogger<FormShopAdd> logger, ICarLogic carLogic, ICarShopStorage carShopStorage)
|
||||
{
|
||||
InitializeComponent();
|
||||
_carLogic = carLogic;
|
||||
_logger = logger;
|
||||
_carShopStorage = carShopStorage;
|
||||
_listCars = carLogic.ReadList(null);
|
||||
if (_listCars != null)
|
||||
{
|
||||
CarComboBox.DisplayMember = "CarName";
|
||||
CarComboBox.ValueMember = "Id";
|
||||
CarComboBox.DataSource = _listCars;
|
||||
CarComboBox.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void Sellbutton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var car = _carLogic.ReadElement(new CarSearchModel { Id = (int)CarComboBox.SelectedValue });
|
||||
var Faith = _carShopStorage.TrySell(car, (int)CountnumericUpDown.Value);
|
||||
if (Faith)
|
||||
MessageBox.Show("Продажа прошла успешно");
|
||||
else
|
||||
MessageBox.Show("Продажа прошла неудачно");
|
||||
}
|
||||
}
|
||||
}
|
60
AutomobilePlant/AutomobilePlant/FormShopSell.resx
Normal file
60
AutomobilePlant/AutomobilePlant/FormShopSell.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -56,6 +56,7 @@ namespace AutomobilePlant
|
||||
services.AddTransient<FormShopCar>();
|
||||
services.AddTransient<FormShopAdd>();
|
||||
services.AddTransient<FormShopCreate>();
|
||||
services.AddTransient<FormShopSell>();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using AutomobilePlantContracts.SearchModel;
|
||||
using AutomobilePlantContracts.StoragesContracts;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using AutomomilePlantFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -19,6 +20,9 @@ namespace AutomomilePlantFileImplement.Implements
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public CarShopViewModel? Delete(CarShopBindingModel model)
|
||||
{
|
||||
var element = source.CarShops.FirstOrDefault(x => x.Id ==
|
||||
@ -80,6 +84,47 @@ namespace AutomomilePlantFileImplement.Implements
|
||||
return newCarShop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool TrySell(ICarModel car, int quantity)
|
||||
{
|
||||
List<CarShopViewModel> carShops = new List<CarShopViewModel>();
|
||||
int fakeQuantity = quantity;
|
||||
foreach (var shop in GetFullList())
|
||||
{
|
||||
if (shop.Cars.ContainsKey(car.Id) )
|
||||
{
|
||||
carShops.Add(shop);
|
||||
fakeQuantity -= shop.Cars[car.Id].Item2;
|
||||
if(fakeQuantity < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fakeQuantity > 0)
|
||||
return false;
|
||||
foreach(var shop in carShops)
|
||||
{
|
||||
if(quantity-shop.Cars[car.Id].Item2 < 0)
|
||||
{
|
||||
shop.Cars[car.Id] = (shop.Cars[car.Id].Item1, shop.Cars[car.Id].Item2 - quantity);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
quantity -= shop.Cars[car.Id].Item2;
|
||||
shop.Cars.Remove(car.Id);
|
||||
}
|
||||
Update(new CarShopBindingModel
|
||||
{
|
||||
ShopName = shop.ShopName,
|
||||
Adress = shop.Adress,
|
||||
DateOpen = shop.DateOpen,
|
||||
Fullness = shop.Fullness,
|
||||
Id = shop.Id,
|
||||
Cars = shop.Cars
|
||||
});
|
||||
}
|
||||
; return true;
|
||||
}
|
||||
|
||||
public CarShopViewModel? Update(CarShopBindingModel model)
|
||||
{
|
||||
var shop = source.CarShops.FirstOrDefault(x => x.Id ==
|
||||
|
@ -85,6 +85,7 @@ namespace AutomomilePlantFileImplement.Models
|
||||
}
|
||||
ShopName = model.ShopName;
|
||||
Adress = model.Adress;
|
||||
Fullness = model.Fullness;
|
||||
ShopCars = model.Cars.ToDictionary(x => x.Key, x =>
|
||||
x.Value.Item2);
|
||||
_cars = null;
|
||||
|
Loading…
Reference in New Issue
Block a user