public Professor MapToProfessor(ProfessorsViewModel model) { var professor = new Professor { Id = model.Id, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Country = model.Country, Address1 = model.Address1, Address2 = model.Address2, City = model.City, BirthDay = model.BirthDay, IsActive = model.IsActive }; return(professor); }
public ProfessorsViewModel MapToProfessorModel(Professor professor) { var model = new ProfessorsViewModel { Id = professor.Id, FirstName = professor.FirstName, LastName = professor.LastName, Email = professor.Email, Country = professor.Country, Address1 = professor.Address1, Address2 = professor.Address2, City = professor.City, BirthDay = professor.BirthDay, IsActive = professor.IsActive, }; return(model); }
// GET: Professors public IActionResult Index(string searchString, string sortOrder, bool sortAsc, int page = 1) { var horariosBDContext = _context.Professor.ToList(); if (!String.IsNullOrEmpty(searchString)) { horariosBDContext = horariosBDContext.Where(s => s.Nome.ToLower().Contains(searchString.ToLower()) || s.Email.ToLower().Contains(searchString.ToLower())).ToList(); } switch (sortOrder) { case "Nome": if (sortAsc) { horariosBDContext = horariosBDContext.OrderBy(d => d.Nome).ToList(); } else { horariosBDContext = horariosBDContext.OrderByDescending(d => d.Nome).ToList(); } break; case "Idade": if (sortAsc) { horariosBDContext = horariosBDContext.OrderBy(d => d.Idade).ToList(); } else { horariosBDContext = horariosBDContext.OrderByDescending(d => d.Idade).ToList(); } break; case "Email": if (sortAsc) { horariosBDContext = horariosBDContext.OrderBy(d => d.Email).ToList(); } else { horariosBDContext = horariosBDContext.OrderByDescending(d => d.Email).ToList(); } break; case "Telemovel": if (sortAsc) { horariosBDContext = horariosBDContext.OrderBy(d => d.Telemovel).ToList(); } else { horariosBDContext = horariosBDContext.OrderByDescending(d => d.Telemovel).ToList(); } break; } var contagemItems = horariosBDContext.Count(); var viewModel = new ProfessorsViewModel() { Professors = horariosBDContext.Skip(PagingInfo.ItemsPerPage * (page - 1)).Take(PagingInfo.ItemsPerPage).ToList() }; viewModel.PagingInfo.CurrentPage = page; viewModel.PagingInfo.TotalItems = contagemItems; viewModel.PagingInfo.Ascending = sortAsc; viewModel.PagingInfo.CurrentSort = sortOrder; viewModel.PagingInfo.CurrentFilter = searchString; return(View(viewModel)); }