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;
        }
        public ActionResult DemoteFromAdmin(OrganizationHomeViewModel model)
        {
            ModelState.RemoveErrorsExcept("OrganizationId,DemoteFromAdminPersonId");
            if (!ModelState.IsValid)
                return View("Home", CreateHomeViewModel(model));

            try
            {
                ConfirmAdminAccess(model.OrganizationId);
                VolunteerService.DemoteVolunteerFromOrganizationAdmin(model.OrganizationId, model.DemoteFromAdminPersonId);

                return Redirect("Home/" + model.OrganizationId);
            }
            catch (ArgumentException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return View("Home", CreateHomeViewModel(model.OrganizationId));
        }
        public ActionResult RemoveResource(OrganizationHomeViewModel model)
        {
            ModelState.RemoveErrorsExcept(nameof(OrganizationHomeViewModel.RemoveResourceId));
            if (!ModelState.IsValid)
                return View("Home", CreateHomeViewModel(model));

            try
            {
                // Check access
                ConfirmAccess(model.OrganizationId);

                // Check the resource ID
                var resources = AdminService.GetResourceCheckinsForOrganization(model.OrganizationId);
                var resource = resources.FirstOrDefault(r => r.ResourceId == model.RemoveResourceId);
                if (resource == null)
                {
                    throw new ArgumentException("The specified resource does not belong to this Organization.");
                }

                // Ok
                DisasterService.RemoveResourceById(resource.ResourceId);

                return Redirect("Home/" + model.OrganizationId);
            }
            catch (ArgumentException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return View("Home", CreateHomeViewModel(model.OrganizationId));
        }
        public ActionResult RemoveVolunteer(OrganizationHomeViewModel model)
        {
            ModelState.RemoveErrorsExcept("OrganizationId,RemoveVolunteerId");
            if (!ModelState.IsValid)
                return View("Home", CreateHomeViewModel(model));

            try
            {
                ConfirmAdminAccess(model.OrganizationId);
                VolunteerService.RemoveVolunteerFromOrganization(model.OrganizationId, model.RemoveVolunteerId);

                return Redirect("Home/" + model.OrganizationId);
            }
            catch (InvalidOperationException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return View("Home", CreateHomeViewModel(model.OrganizationId));
        }
        public ActionResult CheckinResource(OrganizationHomeViewModel model)
        {
            if (!ModelState.IsValid)
                return View("Home", CreateHomeViewModel(model));

            try
            {
                // Check access
                var person = GetCurrentVolunteer();
                ConfirmAccess(model.OrganizationId);

                // Ok
                model.Organization = OrganizationService.Get(model.OrganizationId);
                DisasterService.AddResourceCheckIn(model.Organization, person, model.ResourceDisasterId, model.ResourceDescription,
                    model.ResourceQuantity, model.ResourceTypeId, model.ResourceStartDate, model.ResourceEndDate, model.ResourceLocation);

                return Redirect("Home/" + model.OrganizationId);
            }
            catch (ArgumentException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return View("Home", CreateHomeViewModel(model));
        }