изменения названий
This commit is contained in:
parent
fec3e7d1ef
commit
8761484beb
@ -48,7 +48,7 @@ namespace ShipyardView
|
||||
textBoxAddress.Text = view.Address.ToString();
|
||||
dateTimePickerDateOpen.Text = view.DateOpen.ToString();
|
||||
numericUpDownCapacity.Value=view.Capacity;
|
||||
_shopShips = view.Ships ?? new Dictionary<int, (IShipModel, int)>();
|
||||
_shopShips = view.ShopShips ?? new Dictionary<int, (IShipModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
@ -112,7 +112,7 @@ namespace ShipyardView
|
||||
Address = textBoxAddress.Text,
|
||||
DateOpen = DateTime.Parse(dateTimePickerDateOpen.Text),
|
||||
Capacity = (int)numericUpDownCapacity.Value,
|
||||
Ships = _shopShips
|
||||
ShopShips = _shopShips
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
if (!operationResult)
|
||||
|
@ -37,7 +37,7 @@ namespace ShipyardView
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["Ships"].Visible = false;
|
||||
dataGridView.Columns["ShopShips"].Visible = false;
|
||||
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Загрузка магазинов");
|
||||
|
@ -126,19 +126,19 @@ namespace ShipyardBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("AddShip element not found");
|
||||
return false;
|
||||
}
|
||||
if (element.Capacity - element.Ships.FirstOrDefault(x => x.Key == ship.Id).Value.Item2 < count)
|
||||
if (element.Capacity - element.ShopShips.FirstOrDefault(x => x.Key == ship.Id).Value.Item2 < count)
|
||||
{
|
||||
throw new ArgumentNullException("В магазине не хватает места", nameof(count));
|
||||
}
|
||||
if (element.Ships.TryGetValue(ship.Id, out var pair))
|
||||
if (element.ShopShips.TryGetValue(ship.Id, out var pair))
|
||||
{
|
||||
element.Ships[ship.Id] = (ship, count + pair.Item2);
|
||||
element.ShopShips[ship.Id] = (ship, count + pair.Item2);
|
||||
_logger.LogInformation("AddShip. Added {count} {ship} to '{ShopName}' shop",
|
||||
count, ship.ShipName, element.ShopName);
|
||||
}
|
||||
else
|
||||
{
|
||||
element.Ships[ship.Id] = (ship, count);
|
||||
element.ShopShips[ship.Id] = (ship, count);
|
||||
_logger.LogInformation("AddShip. Added {count} new ship {ship} to '{ShopName}' shop",
|
||||
count, ship.ShipName, element.ShopName);
|
||||
}
|
||||
@ -149,7 +149,7 @@ namespace ShipyardBusinessLogic.BusinessLogics
|
||||
ShopName = element.ShopName,
|
||||
DateOpen = element.DateOpen,
|
||||
Capacity = element.Capacity,
|
||||
Ships = element.Ships
|
||||
ShopShips = element.ShopShips
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@ -166,7 +166,7 @@ namespace ShipyardBusinessLogic.BusinessLogics
|
||||
_logger.LogInformation("AddShips. ShopName:{ShopName}. Id:{Id}", model.ShipName, model.Id);
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
int freeQuantity = shop.Capacity - shop.Ships.Select(x => x.Value.Item2).Sum();
|
||||
int freeQuantity = shop.Capacity - shop.ShopShips.Select(x => x.Value.Item2).Sum();
|
||||
if (freeQuantity <= 0)
|
||||
{
|
||||
continue;
|
||||
|
@ -13,7 +13,7 @@ namespace ShipyardContracts.BindingModels
|
||||
public string Address { get; set; } = string.Empty;
|
||||
public DateTime DateOpen { get; set; } = DateTime.Now;
|
||||
public int Capacity { get; set; }
|
||||
public Dictionary<int, (IShipModel, int)> Ships { get; set; } = new();
|
||||
public Dictionary<int, (IShipModel, int)> ShopShips { get; set; } = new();
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace ShipyardContracts.ViewModels
|
||||
public DateTime DateOpen { get; set; } = DateTime.Now;
|
||||
[DisplayName("Вместимость магазина")]
|
||||
public int Capacity { get; set; }
|
||||
public Dictionary<int, (IShipModel, int)> Ships { get; set; } = new();
|
||||
public Dictionary<int, (IShipModel, int)> ShopShips { get; set; } = new();
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,6 @@ namespace ShipyardDataModels.Models
|
||||
string Address { get; }
|
||||
DateTime DateOpen { get; }
|
||||
public int Capacity { get; }
|
||||
Dictionary<int, (IShipModel, int)> Ships { get; }
|
||||
Dictionary<int, (IShipModel, int)> ShopShips { get; }
|
||||
}
|
||||
}
|
||||
|
@ -86,23 +86,23 @@ namespace ShipyardFileImplement.Implements
|
||||
}
|
||||
public bool SellShips(IShipModel model, int count)
|
||||
{
|
||||
int availableQuantity = source.Shops.Select(x => x.Ships.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum();
|
||||
int availableQuantity = source.Shops.Select(x => x.ShopShips.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum();
|
||||
if (availableQuantity < count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var shops = source.Shops.Where(x => x.Ships.ContainsKey(model.Id));
|
||||
var shops = source.Shops.Where(x => x.ShopShips.ContainsKey(model.Id));
|
||||
foreach (var shop in shops)
|
||||
{
|
||||
int countInCurrentShop = shop.Ships[model.Id].Item2;
|
||||
int countInCurrentShop = shop.ShopShips[model.Id].Item2;
|
||||
if (countInCurrentShop <= count)
|
||||
{
|
||||
shop.Ships[model.Id] = (shop.Ships[model.Id].Item1, 0);
|
||||
shop.ShopShips[model.Id] = (shop.ShopShips[model.Id].Item1, 0);
|
||||
count -= countInCurrentShop;
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.Ships[model.Id] = (shop.Ships[model.Id].Item1, countInCurrentShop - count);
|
||||
shop.ShopShips[model.Id] = (shop.ShopShips[model.Id].Item1, countInCurrentShop - count);
|
||||
count = 0;
|
||||
}
|
||||
Update(new ShopBindingModel
|
||||
@ -111,7 +111,7 @@ namespace ShipyardFileImplement.Implements
|
||||
ShopName = shop.ShopName,
|
||||
Address = shop.Address,
|
||||
DateOpen = shop.DateOpen,
|
||||
Ships = shop.Ships,
|
||||
ShopShips = shop.ShopShips,
|
||||
Capacity = shop.Capacity
|
||||
});
|
||||
if (count == 0)
|
||||
|
@ -19,7 +19,7 @@ namespace ShipyardFileImplement.Models
|
||||
public int Capacity { get; private set; }
|
||||
public Dictionary<int, int> ShipsCount = new();
|
||||
public Dictionary<int, (IShipModel, int)>? _ships = null;
|
||||
public Dictionary<int, (IShipModel, int)> Ships
|
||||
public Dictionary<int, (IShipModel, int)> ShopShips
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -48,7 +48,7 @@ namespace ShipyardFileImplement.Models
|
||||
Address = model.Address,
|
||||
DateOpen = model.DateOpen,
|
||||
Capacity = model.Capacity,
|
||||
ShipsCount = model.Ships.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
ShipsCount = model.ShopShips.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Shop? Create(XElement element)
|
||||
@ -80,7 +80,7 @@ namespace ShipyardFileImplement.Models
|
||||
Address = model.Address;
|
||||
DateOpen = model.DateOpen;
|
||||
Capacity = model.Capacity;
|
||||
ShipsCount = model.Ships.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
ShipsCount = model.ShopShips.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_ships = null;
|
||||
|
||||
}
|
||||
@ -91,7 +91,7 @@ namespace ShipyardFileImplement.Models
|
||||
Address = Address,
|
||||
DateOpen = DateOpen,
|
||||
Capacity = Capacity,
|
||||
Ships = Ships
|
||||
ShopShips = ShopShips
|
||||
};
|
||||
public XElement GetXElement => new("Shop",
|
||||
new XAttribute("Id", Id),
|
||||
|
@ -18,7 +18,7 @@ namespace ShipyardListImplement.Models
|
||||
public DateTime DateOpen { get; set; }
|
||||
public int Capacity { get; private set; }
|
||||
public int Id { get; set; }
|
||||
public Dictionary<int, (IShipModel, int)> Ships { get; private set; } = new Dictionary<int, (IShipModel, int)>();
|
||||
public Dictionary<int, (IShipModel, int)> ShopShips { get; private set; } = new Dictionary<int, (IShipModel, int)>();
|
||||
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
@ -32,7 +32,7 @@ namespace ShipyardListImplement.Models
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
DateOpen = model.DateOpen,
|
||||
Ships = model.Ships
|
||||
ShopShips = model.ShopShips
|
||||
};
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ namespace ShipyardListImplement.Models
|
||||
ShopName = model.ShopName;
|
||||
Address = model.Address;
|
||||
DateOpen = model.DateOpen;
|
||||
Ships = model.Ships;
|
||||
ShopShips = model.ShopShips;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
@ -54,7 +54,7 @@ namespace ShipyardListImplement.Models
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
DateOpen = DateOpen,
|
||||
Ships = Ships
|
||||
ShopShips = ShopShips
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user