public bool Save(MySqlDataManipulator manipulator, int companyId) { List <KeywordGroupEntry> toUpload = new List <KeywordGroupEntry>(); foreach (KeywordGroup group in ContainedGroups) { toUpload.Add(new KeywordGroupEntry(group.SelectedKeywords.ToString())); } List <KeywordGroupEntry> previous; previous = manipulator.GetCompanyComplaintGroups(companyId); bool res = manipulator.DeleteCompanyComplaintGroups(companyId); if (!res) { return(false); } res = manipulator.AddCompanyComplaintGroups(companyId, toUpload); if (!res) { res = manipulator.AddCompanyComplaintGroups(companyId, previous); if (!res) { throw new Exception("Company " + companyId + " keyword clusterer failed to add previous" + " groups back after deletion. This is really bad."); } return(false); } return(true); }