OrganizationHomeViewModel CreateHomeViewModel(OrganizationHomeViewModel inputModel) { // Organization int id = inputModel.OrganizationId; Organization org = OrganizationService.Get(id); // Access level var isAdministrator = WebSecurityWrapper.IsUserInRole(Common.Constants.RoleAdmin); var isOrgAdmin = HasOrgAdminAccess(id); // Volunteers var volunteers = VolunteerService.GetVolunteersByOrganization(id).OrderBy(p => p.IsOrganizationAdmin).Reverse(); // Resources var resources = AdminService.GetResourceCheckinsForOrganization(id); var resourceTypes = AdminService.GetResourceTypes(); // Commitments var commitments = VolunteerService.GetCommitmentsForOrganization(id, false); // Lookup lists var allDisasters = DisasterService.GetActiveList(); var volunteersSelectList = VolunteerService.GetList().OrderBy(person => person.LastName).Select(person => new SelectListItem() { Value = person.Id.ToString(), Text = $"{person.LastName}, {person.FirstName} - {person.Email}", Selected = (person.Id == inputModel.AddVolunteerId) }); // Disaster info breakdown - get all disasters with any volunteer or resource checkin var disasters = GetDisasterInfos(allDisasters, resources, commitments); // Create var model = new OrganizationHomeViewModel { OrganizationId = id, Organization = org, IsAdministrator = isAdministrator, IsOrgAdmin = isOrgAdmin, Volunteers = volunteers, OrganizationResources = resources, Disasters = disasters, ResourceTypes = resourceTypes, AllDisasters = allDisasters, VolunteersSelectList = volunteersSelectList }; // Resources form fields model.ResourceDisasterId = inputModel.ResourceDisasterId; model.ResourceDescription = inputModel.ResourceDescription; model.ResourceQuantity = inputModel.ResourceQuantity; model.ResourceTypeId = inputModel.ResourceTypeId; model.ResourceStartDate = inputModel.ResourceStartDate; model.ResourceEndDate = inputModel.ResourceEndDate; model.ResourceLocation = inputModel.ResourceLocation; model.RemoveResourceId = inputModel.RemoveResourceId; return(model); }