public void AddElement(BindingWorkers model) { int maxId = 0; for (int i = 0; i < source.Workers.Count; ++i) { if (source.Workers[i].Id > maxId) { maxId = source.Workers[i].Id; } if (source.Workers[i].WorkerName == model.WorkerName) { throw new Exception("Уже есть сотрудник с таким ФИО"); } } source.Workers.Add(new Worker { Id = maxId + 1, WorkerName = model.WorkerName }); }
public void UpdElement(BindingWorkers model) { int index = -1; for (int i = 0; i < source.Workers.Count; ++i) { if (source.Workers[i].Id == model.Id) { index = i; } if (source.Workers[i].WorkerName == model.WorkerName && source.Workers[i].Id != model.Id) { throw new Exception("Уже есть сотрудник с таким ФИО"); } } if (index == -1) { throw new Exception("Элемент не найден"); } source.Workers[index].WorkerName = model.WorkerName; }