public ActionResult List(string prefix) { //var model = _db.Where(c => prefix == null || c.FirstName.ToLower().StartsWith(prefix.ToLower())).ToList(); var contacts = _db.Where(c => prefix == null || c.FirstName.ToLower().StartsWith(prefix.ToLower())).ToList(); var letters = _db.Select(c=> c.FirstName.Substring(0, 1).ToUpper()).Distinct().OrderBy(letter => letter).ToList(); var model = new ContactViewModel { SelectedLetters = letters, Contacts = contacts }; return View(model); }
public ActionResult List(string prefix) { var _db = new ContactBUS().GetContacts(); var contacts = _db.Where(c => prefix == null || c.FirstName.ToLower().StartsWith(prefix.ToLower())).ToList(); var letters = _db.Select(c => c.FirstName.Substring(0, 1).ToUpper()).Distinct().OrderBy(letter => letter).ToList(); var model = new ContactViewModel { SelectedLetters = letters, Contacts = contacts, SelectedLetter = prefix != null ? prefix.ToUpper() : String.Empty }; //var model = new List<Contact>(); //foreach(var contact in _db) // if(prefix == null || contact.FirstName.ToLower().StartsWith(prefix.ToLower())) // model.Add(contact); return View(model); }
public ActionResult List(int id, string prefix) { //if (prefix == null) //{ // prefix = 'A'.ToString(); //} var _db = new ContactBUS().GetContacts(); var contacts = _db.Where(c => prefix == null || c.FirstName.ToLower().StartsWith(prefix.ToLower())).ToList(); var letters = _db.Select(c => c.FirstName.Substring(0, 1).ToUpper()).Distinct().OrderBy(letter => letter).ToList(); var model = new ContactViewModel { Contacts = contacts, SelectedLetters = letters, SelectedLetter = prefix != null ? prefix.ToUpper() : String.Empty, lastId = id }; return View(model); }