public List <List <Contact> > GetContactsByBoth(string fnCommaLN) { var amountRestrict = Convert.ToInt32(ConfigurationManager.AppSettings["amountrestrict"]); // валидацию бы.. List <List <Contact> > toReturn = new List <List <Contact> >(); int indexOfChar = fnCommaLN.IndexOf(","); var lastname = fnCommaLN.Remove(0, indexOfChar + 1); var firstname = fnCommaLN.Remove(indexOfChar); var foundByFirstName = GetContactsByFirstName(firstname); var foundByLastName = GetContactsByLastName(lastname); for (var i = 0; i < foundByFirstName.Count; i++) { for (var j = 0; j < foundByLastName.Count; j++) { bool isSamePerson = foundByFirstName[i].ID == foundByLastName[j].ID; if (isSamePerson) { foundByFirstName.Remove(foundByFirstName[i]); break; } } } foundByFirstName = BubbleSorter.BubbleSorterLN(foundByFirstName); foundByFirstName = ListContactSlicer.Slice(foundByFirstName, amountRestrict - 1); foundByLastName = BubbleSorter.BubbleSorterFN(foundByLastName); foundByLastName = ListContactSlicer.Slice(foundByLastName, amountRestrict - 1); toReturn.Add(foundByFirstName); toReturn.Add(foundByLastName); return(toReturn); }
public List <Contact> GetContactsByLastName(string lastname) { var connectString = ConfigurationManager.AppSettings["connectString"]; var amountRestrict = Convert.ToInt32(ConfigurationManager.AppSettings["amountrestrict"]); IMylogger log = new Log4netUsing(); var test = new ContactDBWorker(connectString, log); var toReturn = test.GetContactsByLastName(lastname); toReturn = BubbleSorter.BubbleSorterFN(toReturn); toReturn = ListContactSlicer.Slice(toReturn, amountRestrict); return(toReturn); }
public List <Contact> GetContactsByFirstName(string firstname)// чтобы вернуть еще и значение amountRestrict, нужно создать класс GetContactsResponse и добавить туда два поля: List<Contact> и int amountRestrict { var connectString = ConfigurationManager.AppSettings["connectString"]; var amountRestrict = Convert.ToInt32(ConfigurationManager.AppSettings["amountrestrict"]); IMylogger log = new Log4netUsing(); var test = new ContactDBWorker(connectString, log); // ДЛЯ КАЖДОГО МЕТОДА СЕРВИСА TRY CATCH var toReturn = test.GetContactsByFirstName(firstname); toReturn = BubbleSorter.BubbleSorterLN(toReturn); toReturn = ListContactSlicer.Slice(toReturn, amountRestrict); return(toReturn); }