public PartialViewResult Edit(FundingSourcePrimaryKey fundingSourcePrimaryKey)
        {
            var fundingSource = fundingSourcePrimaryKey.EntityObject;
            var viewModel     = new EditViewModel(fundingSource);

            return(ViewEdit(viewModel));
        }
        private PartialViewResult ViewEdit(EditViewModel viewModel)
        {
            var organizationsAsSelectListItems =
                HttpRequestStorage.DatabaseEntities.Organizations.GetActiveOrganizations()
                .ToSelectListWithEmptyFirstRow(x => x.OrganizationID.ToString(CultureInfo.InvariantCulture), x => x.OrganizationName);
            var viewData = new EditViewData(organizationsAsSelectListItems, CurrentFirmaSession);

            return(RazorPartialView <Edit, EditViewData, EditViewModel>(viewData, viewModel));
        }
        public ActionResult Edit(FundingSourcePrimaryKey fundingSourcePrimaryKey, EditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(ViewEdit(viewModel));
            }
            var fundingSource = fundingSourcePrimaryKey.EntityObject;

            viewModel.UpdateModel(fundingSource, CurrentFirmaSession);
            return(new ModalDialogFormJsonResult());
        }
        public PartialViewResult New()
        {
            var viewModel = new EditViewModel
            {
                // If the person is not an admin, we want to default the Funding Source organization to their own Organization
                OrganizationID = new List <Role> {
                    Role.Admin, Role.SitkaAdmin
                }.Any(x => x.RoleID == CurrentPerson.RoleID)
                    ? (int?)null
                    : CurrentPerson.OrganizationID,
                IsActive = true
            };

            return(ViewEdit(viewModel));
        }
        public ActionResult New(EditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(ViewEdit(viewModel));
            }
            var fundingSource = new FundingSource(
                viewModel.OrganizationID ?? ModelObjectHelpers.NotYetAssignedID, // Should never be null due to View Model validation
                string.Empty,
                true);

            viewModel.UpdateModel(fundingSource, CurrentFirmaSession);
            HttpRequestStorage.DatabaseEntities.AllFundingSources.Add(fundingSource);
            HttpRequestStorage.DatabaseEntities.SaveChanges();
            SetMessageForDisplay($"{FieldDefinitionEnum.FundingSource.ToType().GetFieldDefinitionLabel()} {fundingSource.GetDisplayName()} successfully created.");

            return(new ModalDialogFormJsonResult());
        }