2using System.Collections.Generic;
4using System.Xml.Serialization;
17[XmlType(TypeName =
"plant")]
21 private List<WorkCenter> _workCenters =
new();
63 [XmlElement(
"warehouse")]
70 ArgumentNullException.ThrowIfNull(value);
85 [XmlArray(
"workCenters")]
86 [XmlArrayItem(
"workCenter")]
93 List<WorkCenter> newValue =
94 value ??
new List<WorkCenter>();
97 if (ReferenceEquals(_workCenters, newValue))
102 _workCenters = newValue;
120 ArgumentNullException.ThrowIfNull(workCenter);
123 bool identifierAlreadyUsed =
126 current => current.Id == workCenter.Id);
128 if (identifierAlreadyUsed)
130 throw new InvalidOperationException(
131 $
"A work center with identifier {workCenter.Id} " +
132 $
"already exists in plant {Id}.");
136 _workCenters.Add(workCenter);
153 ArgumentNullException.ThrowIfNull(workCenter);
156 bool removed = _workCenters.Remove(workCenter);
179 return _workCenters.FirstOrDefault(
180 workCenter => workCenter.Id == workCenterId);
int Id
Gets or sets the numerical identifier of the entity.
IdentifiedEntity()
Initializes a new instance of the IdentifiedEntity class.
virtual void OnPropertyChanged([CallerMemberName] string? propertyName=null)
Raises the PropertyChanged event.
string Name
Gets or sets the entity name.
List< WorkCenter > WorkCenters
Gets or sets the work centers belonging to the plant.
void AddWorkCenter(WorkCenter workCenter)
Adds a work center to the plant.
Plant(int id, string name, PlantWarehouse warehouse)
Initializes a plant with an identifier, a name and its associated warehouse.
Plant()
Initializes an empty plant.
bool RemoveWorkCenter(WorkCenter workCenter)
Removes a work center from the plant.
WorkCenter? FindWorkCenter(int workCenterId)
Finds a work center by its identifier.
PlantWarehouse Warehouse
Gets or sets the warehouse attached to the plant.
Represents a warehouse attached to a plant.
Represents a production work center belonging to a plant.