public void AddElement(KitchenBindingModel model) { int maxId = 0; for (int i = 0; i < source.Kitchens.Count; ++i) { if (source.Kitchens[i].Id > maxId) { maxId = source.Kitchens[i].Id; } if (source.Kitchens[i].KitchenName == model.KitchenName) { throw new Exception("Уже есть склад с таким названием"); } } source.Kitchens.Add(new Kitchen { Id = maxId + 1, KitchenName = model.KitchenName }); }
public void UpdElement(KitchenBindingModel model) { int index = -1; for (int i = 0; i < source.Kitchens.Count; ++i) { if (source.Kitchens[i].Id == model.Id) { index = i; } if (source.Kitchens[i].KitchenName == model.KitchenName && source.Kitchens[i].Id != model.Id) { throw new Exception("Уже есть склад с таким названием"); } } if (index == -1) { throw new Exception("Элемент не найден"); } source.Kitchens[index].KitchenName = model.KitchenName; }