private bool TryRemoveUncheckedProjects() { foreach (var projectItem in ProjectListBox.Items) { if (ProjectListBox.CheckedItems.Contains(projectItem)) { continue; } if (!RelationProjectEmployeeRepo.IsEmployeeOnProject(OldOib, projectItem.ToString().GetProjectName()) ) { continue; } if (RelationProjectEmployeeRepo.TryRemove( RelationProjectEmployeeRepo.GetRelation(OldOib, projectItem.ToString().GetProjectName()))) { continue; } var lastEmployeeError = new ErrorForm($"{NameTextBox.Text} could not be removed from project {projectItem.ToString().GetProjectName()}\n" + "He is the last employee on that project"); lastEmployeeError.ShowDialog(); return(false); } return(true); }
private static void TryDelete(Employee toRemove) { var errorCount = 0; foreach (var project in RelationProjectEmployeeRepo.GetProjectsByEmployee(toRemove.Oib)) { if (RelationProjectEmployeeRepo.TryRemove( RelationProjectEmployeeRepo.GetRelation(toRemove.Oib, project.Name))) { continue; } errorCount++; var lastEmployeeOnProjectError = new ErrorForm($"Employee {toRemove.Name} {toRemove.LastName} could not be deleted!\nHe is the last employee on one or more projects!"); lastEmployeeOnProjectError.ShowDialog(); break; } if (errorCount == 0) { EmployeeRepo.Remove(toRemove); } }