public PartialViewResult New()
        {
            var viewModel = new Views.Program.EditViewModel {
                IsActive = true
            };

            return(ViewEdit(viewModel, null, null));
        }
        public PartialViewResult NewProgram(OrganizationPrimaryKey organizationPrimaryKey)
        {
            var organization = organizationPrimaryKey.EntityObject;
            var viewModel    = new Views.Program.EditViewModel {
                IsActive = true, OrganizationID = organization.OrganizationID
            };

            return(ViewEdit(viewModel, null, organization));
        }
        private PartialViewResult ViewEdit(Views.Program.EditViewModel viewModel, Person currentPrimaryContactPerson, Organization organization)
        {
            var organizationsAsSelectListItems = HttpRequestStorage.DatabaseEntities.Organizations
                                                 .Where(x => !string.Equals(x.OrganizationName, Organization.OrganizationUnknown))
                                                 .OrderBy(x => x.OrganizationName)
                                                 .ToSelectListWithEmptyFirstRow(x => x.OrganizationID.ToString(CultureInfo.InvariantCulture),
                                                                                x => x.OrganizationName);
            var activePeople = HttpRequestStorage.DatabaseEntities.People.GetActivePeople().Where(x => x.IsFullUser()).ToList();

            if (currentPrimaryContactPerson != null && !activePeople.Contains(currentPrimaryContactPerson))
            {
                activePeople.Add(currentPrimaryContactPerson);
            }
            var people = activePeople.OrderBy(x => x.FullNameLastFirst).ToSelectListWithEmptyFirstRow(x => x.PersonID.ToString(CultureInfo.InvariantCulture),
                                                                                                      x => x.FullNameFirstLastAndOrg);
            bool isSitkaAdmin = new SitkaAdminFeature().HasPermissionByPerson(CurrentPerson);
            var  viewData     = new Views.Program.EditViewData(organizationsAsSelectListItems, people, isSitkaAdmin, organization);

            return(RazorPartialView <Views.Program.Edit, Views.Program.EditViewData, Views.Program.EditViewModel>(viewData, viewModel));
        }
        public ActionResult New(Views.Program.EditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(ViewEdit(viewModel, null, null));
            }

            var organizationID = viewModel.OrganizationID.GetValueOrDefault();

            var organization = HttpRequestStorage.DatabaseEntities.Organizations.Single(x =>
                                                                                        x.OrganizationID == organizationID);

            var program = new Program(organization, true, DateTime.Now, CurrentPerson, false);

            viewModel.UpdateModel(program, CurrentPerson, true);
            HttpRequestStorage.DatabaseEntities.Programs.Add(program);
            HttpRequestStorage.DatabaseEntities.SaveChanges();
            SetMessageForDisplay($"{FieldDefinition.Program.GetFieldDefinitionLabel()} {program.DisplayName} successfully created.");
            return(new ModalDialogFormJsonResult());
        }
        public ActionResult NewProgram(OrganizationPrimaryKey organizationPrimaryKey, Views.Program.EditViewModel viewModel)
        {
            var organization = organizationPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewEdit(viewModel, null, organization));
            }

            var program = new Program(organization, true, DateTime.Now, CurrentPerson, false);

            viewModel.UpdateModel(program, CurrentPerson, true);
            HttpRequestStorage.DatabaseEntities.Programs.Add(program);
            HttpRequestStorage.DatabaseEntities.SaveChanges();
            SetMessageForDisplay($"{FieldDefinition.Program.GetFieldDefinitionLabel()} {program.DisplayName} successfully created.");
            return(new ModalDialogFormJsonResult());
        }