public virtual ViewResult List(string sortType, SortDirection? sortDirection, int? page, int? itemsPerPage) { if (string.IsNullOrEmpty(sortType)) sortType = "name"; var viewModel = new SortedListViewModel<PersonnelRecordListViewModel> { SortDirection = sortDirection ?? SortDirection.Ascending, SortType = sortType, PagingEnabled = true, CurrentPage = page.HasValue ? page.Value : 1, ItemsPerPage = itemsPerPage.HasValue ? itemsPerPage.Value : SortedListViewModel<PersonnelRecordListViewModel>.DefaultItemsPerPage, }; IEnumerable<User> users = userRepository.GetAllActiveUsers().ToList(); var items = Mapper.Map<IEnumerable<User>, IEnumerable<PersonnelRecordListViewModel>>(users); if (viewModel.IsCurrentSortType("name") && viewModel.SortDirection == SortDirection.Ascending) items = items.OrderBy(x => x.FileByName); else if (viewModel.IsCurrentSortType("name")) items = items.OrderByDescending(x => x.FileByName); if (viewModel.IsCurrentSortType("status") && viewModel.SortDirection == SortDirection.Ascending) items = items.OrderBy(x => x.Status); else if (viewModel.IsCurrentSortType("status")) items = items.OrderByDescending(x => x.Status); viewModel.SetItems(items.ToList()); return View(Views.List, viewModel); }
public virtual ViewResult ListAllMessages(MessageType messageType) { var viewModel = new SortedListViewModel <MessageViewModel>(); IEnumerable <MessageViewModel> messages; switch (messageType) { case MessageType.Announcement: var announcements = messagesRepository.GetAllAnnouncements(); messages = Mapper.Map <IEnumerable <Announcement>, IEnumerable <AnnouncementViewModel> >(announcements).Cast <MessageViewModel>(); break; case MessageType.SystemAlert: var systemAlerts = messagesRepository.GetAllSystemAlerts(); messages = Mapper.Map <IEnumerable <SystemAlert>, IEnumerable <SystemAlertViewModel> >(systemAlerts).Cast <MessageViewModel>(); break; default: throw new InvalidOperationException("Invalid Message Type"); } messages = messages.OrderByDescending(x => x.ActiveFromDate); viewModel.SetItems(messages); ViewData["CanEdit"] = DetermineCanEdit(); return(View(Views.ListMessages, viewModel)); }
public virtual ViewResult ListMessages() { var viewModel = new SortedListViewModel<MessageViewModel>(); var allRecentMessages = messagesRepository.GetAllActiveNonUserMessages(); var announcements = allRecentMessages.Where(x => x.MessageType == MessageType.Announcement).Cast<Announcement>(); var systemAlerts = allRecentMessages.Where(x => x.MessageType == MessageType.SystemAlert).Cast<SystemAlert>(); var messages = Mapper.Map<IEnumerable<Announcement>, IEnumerable<AnnouncementViewModel>>(announcements).Cast<MessageViewModel>() .Concat(Mapper.Map<IEnumerable<SystemAlert>, IEnumerable<SystemAlertViewModel>>(systemAlerts).Cast<MessageViewModel>()); messages = messages.OrderByDescending(x => x.ActiveFromDate); viewModel.SetItems(messages); ViewData["CanEdit"] = DetermineCanEdit(); return View(Views.ListMessages, viewModel); }
public static SortedListViewModel ConvertToSortedListViewModel(this SortedList sortedList, string authenticatedUserID) { var result = new SortedListViewModel { BaseList = sortedList.BaseList.ConvertToListViewModel(authenticatedUserID), CreatedDateTime = sortedList.CreatedDateTime, OwnerID = sortedList.OwnerID, ID = sortedList.ID, Items = sortedList.Items.ConvertToSortedListItemsViewModel(), }; return(result); }
public virtual ViewResult ListMessages() { var viewModel = new SortedListViewModel <MessageViewModel>(); var allRecentMessages = messagesRepository.GetAllActiveNonUserMessages(); var announcements = allRecentMessages.Where(x => x.MessageType == MessageType.Announcement).Cast <Announcement>(); var systemAlerts = allRecentMessages.Where(x => x.MessageType == MessageType.SystemAlert).Cast <SystemAlert>(); var messages = Mapper.Map <IEnumerable <Announcement>, IEnumerable <AnnouncementViewModel> >(announcements).Cast <MessageViewModel>() .Concat(Mapper.Map <IEnumerable <SystemAlert>, IEnumerable <SystemAlertViewModel> >(systemAlerts).Cast <MessageViewModel>()); messages = messages.OrderByDescending(x => x.ActiveFromDate); viewModel.SetItems(messages); ViewData["CanEdit"] = DetermineCanEdit(); return(View(Views.ListMessages, viewModel)); }
public virtual ViewResult ListAllMessages(MessageType messageType) { var viewModel = new SortedListViewModel<MessageViewModel>(); IEnumerable<MessageViewModel> messages; switch (messageType) { case MessageType.Announcement: var announcements = messagesRepository.GetAllAnnouncements(); messages = Mapper.Map<IEnumerable<Announcement>, IEnumerable<AnnouncementViewModel>>(announcements).Cast<MessageViewModel>(); break; case MessageType.SystemAlert: var systemAlerts = messagesRepository.GetAllSystemAlerts(); messages = Mapper.Map<IEnumerable<SystemAlert>, IEnumerable<SystemAlertViewModel>>(systemAlerts).Cast<MessageViewModel>(); break; default: throw new InvalidOperationException("Invalid Message Type"); } messages = messages.OrderByDescending(x => x.ActiveFromDate); viewModel.SetItems(messages); ViewData["CanEdit"] = DetermineCanEdit(); return View(Views.ListMessages, viewModel); }
public virtual ViewResult List(string sortType, SortDirection? sortDirection, int? page, int? itemsPerPage, bool? showAll) { if (string.IsNullOrEmpty(sortType)) sortType = "name"; var viewModel = new SortedListViewModel<UserViewModel>() { ShowAll = showAll.HasValue && showAll.Value, SortDirection = sortDirection ?? SortDirection.Ascending, SortType = sortType, PagingEnabled = true, CurrentPage = page.HasValue ? page.Value : 1, ItemsPerPage = itemsPerPage.HasValue ? itemsPerPage.Value : SortedListViewModel<User>.DefaultItemsPerPage, }; IEnumerable<User> users = null; if (viewModel.ShowAll) users = userRepository.GetAllUsers(); else users = userRepository.GetAllActiveUsers(); if (viewModel.IsCurrentSortType("name") && viewModel.SortDirection == SortDirection.Ascending) users = users.OrderBy(x => x.LastName); else if (viewModel.IsCurrentSortType("name")) users = users.OrderByDescending(x => x.LastName); else if (viewModel.IsCurrentSortType("username") && viewModel.SortDirection == SortDirection.Ascending) users = users.OrderBy(x => x.Username); else if (viewModel.IsCurrentSortType("username")) users = users.OrderByDescending(x => x.Username); else if (viewModel.IsCurrentSortType("email") && viewModel.SortDirection == SortDirection.Ascending) users = users.OrderBy(x => x.Email); else if (viewModel.IsCurrentSortType("email")) users = users.OrderByDescending(x => x.Email); else if (viewModel.IsCurrentSortType("status") && viewModel.SortDirection == SortDirection.Ascending) users = users.OrderBy(x => x.Disabled); else if (viewModel.IsCurrentSortType("status")) users = users.OrderByDescending(x => x.Disabled); users = users.ToList(); viewModel.TotalItems = users.Count(); viewModel.SetItems(Mapper.Map<IEnumerable<User>, IEnumerable<UserViewModel>>(users)); return View(Views.List, viewModel); }
public virtual ViewResult List(string sortType, SortDirection?sortDirection, int?page, int?itemsPerPage) { if (string.IsNullOrEmpty(sortType)) { sortType = "name"; } var viewModel = new SortedListViewModel <PersonnelRecordListViewModel> { SortDirection = sortDirection ?? SortDirection.Ascending, SortType = sortType, PagingEnabled = true, CurrentPage = page.HasValue ? page.Value : 1, ItemsPerPage = itemsPerPage.HasValue ? itemsPerPage.Value : SortedListViewModel <PersonnelRecordListViewModel> .DefaultItemsPerPage, }; IEnumerable <User> users = userRepository.GetAllActiveUsers().ToList(); var items = Mapper.Map <IEnumerable <User>, IEnumerable <PersonnelRecordListViewModel> >(users); if (viewModel.IsCurrentSortType("name") && viewModel.SortDirection == SortDirection.Ascending) { items = items.OrderBy(x => x.FileByName); } else if (viewModel.IsCurrentSortType("name")) { items = items.OrderByDescending(x => x.FileByName); } if (viewModel.IsCurrentSortType("status") && viewModel.SortDirection == SortDirection.Ascending) { items = items.OrderBy(x => x.Status); } else if (viewModel.IsCurrentSortType("status")) { items = items.OrderByDescending(x => x.Status); } viewModel.SetItems(items.ToList()); return(View(Views.List, viewModel)); }
public virtual ViewResult List(string sortType, SortDirection?sortDirection, int?page, int?itemsPerPage, bool?showAll) { if (string.IsNullOrEmpty(sortType)) { sortType = "name"; } var viewModel = new SortedListViewModel <UserViewModel>() { ShowAll = showAll.HasValue && showAll.Value, SortDirection = sortDirection ?? SortDirection.Ascending, SortType = sortType, PagingEnabled = true, CurrentPage = page.HasValue ? page.Value : 1, ItemsPerPage = itemsPerPage.HasValue ? itemsPerPage.Value : SortedListViewModel <User> .DefaultItemsPerPage, }; IEnumerable <User> users = null; if (viewModel.ShowAll) { users = userRepository.GetAllUsers(); } else { users = userRepository.GetAllActiveUsers(); } if (viewModel.IsCurrentSortType("name") && viewModel.SortDirection == SortDirection.Ascending) { users = users.OrderBy(x => x.LastName); } else if (viewModel.IsCurrentSortType("name")) { users = users.OrderByDescending(x => x.LastName); } else if (viewModel.IsCurrentSortType("username") && viewModel.SortDirection == SortDirection.Ascending) { users = users.OrderBy(x => x.Username); } else if (viewModel.IsCurrentSortType("username")) { users = users.OrderByDescending(x => x.Username); } else if (viewModel.IsCurrentSortType("email") && viewModel.SortDirection == SortDirection.Ascending) { users = users.OrderBy(x => x.Email); } else if (viewModel.IsCurrentSortType("email")) { users = users.OrderByDescending(x => x.Email); } else if (viewModel.IsCurrentSortType("status") && viewModel.SortDirection == SortDirection.Ascending) { users = users.OrderBy(x => x.Disabled); } else if (viewModel.IsCurrentSortType("status")) { users = users.OrderByDescending(x => x.Disabled); } users = users.ToList(); viewModel.TotalItems = users.Count(); viewModel.SetItems(Mapper.Map <IEnumerable <User>, IEnumerable <UserViewModel> >(users)); return(View(Views.List, viewModel)); }