public FileResult CCGMembers(int?ccgId, bool getAll = false, string query = null, bool allAccess = false, int?memberFilter = (int)MemberFilter.None, int?dataDownloadFileType = (int)ExportDataFileType.Xls) { var fileType = dataDownloadFileType != null ? (ExportDataFileType)dataDownloadFileType : ExportDataFileType.Xls; // Get members collection from db // TODO action result not needed here ActionResult actionResult; var members = _membersService.GetMembersList(ccgId, getAll, query, allAccess, User.Identity.Name, out actionResult).ToList(); // Filter members var filter = memberFilter != null ? (MemberFilter)memberFilter : MemberFilter.None; _membersService.FilterMembers(ref members, filter, unitOfWork.AppUserRepository.FindUserByEmail(User.Identity.Name)); switch (fileType) { case ExportDataFileType.Xls: // Export excel file to user's browser return(_service.ExportCCGMembersAsXls(members)); case ExportDataFileType.Csv: break; } //TODO temporary return(new FileContentResult(new byte[] { }, "")); }
// GET: CcgMembers public ActionResult Index(int?ccgId, int?page = 1, int?itemsPerPage = 10, bool selectAll = false, bool listAll = false, bool getAll = false, string query = null, bool allAccess = false, int?memberFilter = (int)MemberFilter.None) { IList <MultiSelectList> items = new List <MultiSelectList>(); var filter = memberFilter != null ? (MemberFilter)memberFilter : MemberFilter.None; #region Set query string params to pass back to view // Pass params to view for features such as pagination ViewBag.ItemsPerPage = itemsPerPage; ViewBag.Page = page; ViewBag.CCGId = ccgId; ViewBag.GetAll = getAll; ViewBag.AllAccess = allAccess; ViewBag.IsSelectAll = selectAll; ViewBag.MemberFilter = filter; ViewBag.Query = query; #endregion if (ccgId != null) { var ccg = unitOfWork.CCGRepository.Find(g => g.Id == ccgId); ViewBag.CCGName = _ccgService.SetCCGViewName(ccg); } ActionResult actionResult; var members = _service.GetMembersList(ccgId, getAll, query, allAccess, User.Identity.Name, out actionResult).ToList(); // User may not get authorized and redirected if (actionResult != null) { return(actionResult); } // Filter members _service.FilterMembers(ref members, filter, unitOfWork.AppUserRepository.FindUserByEmail(User.Identity.Name)); // Map to view model and return view. var memberList = Mapper.Map <IList <ListMembersViewModel> >(members); // Validate phone and cell numbers; assign empty string if invalid _service.ValidatePhoneNumbers(memberList); // Set img src and member-has-photo flag _service.SetImgSrcAndHasPhotoFlag(memberList); // Set the IsMemberDeacon flag for each member. If user is not member's // deacon, also sets the href links for the phone numbers. _service.SetIsMemberDeaconFlag(memberList, unitOfWork.AppUserRepository.FindUserByEmail(User.Identity.Name)); // List all records in the view on one page if (listAll) { itemsPerPage = memberList.Count(); } // Select all if 'select all' is selected. if (selectAll) { _service.SelectAll(memberList); } // Get CCGs and users for filter menu var ccgs = unitOfWork.CCGRepository.FindAll().ToList(); // Set CCG name with deacon name(s). eg., CCG10 ===> CCG10_Bolden _ccgService.SetCCGViewName(ccgs); // Add 'All CCGs' option to menu ccgs.Insert(0, new CCG { Id = -1, CCGName = "All CCGs" }); ViewBag.CCGs = new SelectList(ccgs, "Id", "CcgName"); // Convert view model list to PagedList for pagination. return(View(memberList.ToPagedList(page ?? 1, itemsPerPage ?? 10))); }