protected IActionResult ValidateParentAndRedirect(IValidatable parent, FormSection section, string actionName)
        {
            parent.Validate();
            var nextActionName = FormDefinition.GetNextPage(section, actionName).ActionName;

            return(parent.IsValid ? RedirectToLastActionForNewSection(section) : RedirectToAction(section, nextActionName));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] FormSection formSection)
        {
            if (id != formSection.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(formSection);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FormSectionExists(formSection.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(formSection));
        }
        public async Task <IActionResult> Edit(int id, [FromForm] FormSection section)
        {
            if (id != section.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(section);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SectionExists(section.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FormId"] = new SelectList(_context.Forms, "Id", "Name", section.FormId);
            return(View(section));
        }
Exemplo n.º 4
0
        public void changeSectionRank(FormSection fs, int dir)
        {
            FormBuilder.ChangeSectionRank(fs, dir);
            QueryString qs = new QueryString(Request.QueryString);

            Response.Redirect(Request.Path + "?" + qs.ToString());
        }
        public void it_should_keep_searching_backwards_until_a_viewable_match_is_found()
        {
            const FormSection validSection     = FormSection.OrganisationDetails;
            const string      startActionName  = "startName";
            const string      noViewActionName = "no";
            const string      lastActionName   = "last";

            config.Fields = new Dictionary <FormSection, FormPageDefinition[]>
            {
                {
                    validSection,
                    new[]
                    {
                        new FormPageDefinition(nameof(ExampleViewModel.Populated), startActionName),
                        new FormPageDefinition(nameof(ExampleViewModel.SubModel), noViewActionName),
                        new FormPageDefinition(nameof(ExampleViewModel.Populated), lastActionName)
                    }
                }
            };

            var parent = new ExampleViewModel {
                CanView = false
            };

            var result = form.GetPreviousPossiblePage(validSection, lastActionName, parent);

            Assert.IsTrue(result.MatchesName(startActionName));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns a redirect action for the first view following the supplied view that can be viewed
        /// based on the state of the parent view model.
        /// </summary>
        /// <typeparam name="T">The type of the parent view model.</typeparam>
        /// <param name="section">The forms section.</param>
        /// <param name="actionName">The name of the action to look for views after.</param>
        /// <param name="model">The parent view model.</param>
        /// <returns>A redirect <see cref="RedirectToActionResult"/> for the next possible view.</returns>
        protected IActionResult RedirectToNextPossibleView <T>(FormSection section, string actionName, T model)
            where T : IValidatable
        {
            var nextPage = FormDefinition.GetNextPossiblePage(section, actionName, model);

            return(RedirectToAction(section, nextPage.ActionName));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Handles the Click event of the lbLeft control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void lbLeft_Click(object sender, EventArgs e)
        {
            string param = Request.Params.Get("__EVENTARGUMENT");
            Guid   uid   = Guid.Empty;

            try
            {
                uid = new Guid(param);
            }
            catch
            {
                return;
            }

            FormController fController = new FormController(FormDocumentData);
            FormSection    itemSection = fController.GetSectionByUid(uid);

            if (itemSection != null)
            {
                fController.MoveSectionLeft(uid);
            }
            else
            {
                FormItem item = fController.GetSTLItemByUid(uid);
                if (item != null)
                {
                    fController.MoveFormItemLeft(uid);
                }
            }

            BindRendererInner();
        }
        public IActionResult RemoveConviction(UnspentConvictionViewModel model, FormSection section, int id)
        {
            LicenceApplicationPostDataHandler.Delete <Conviction>(id);

            var lastLoaded = Session.GetLoadedPage();

            return(RedirectToAction(section, lastLoaded));
        }
        protected IActionResult ValidateParentAndRedirectBack(IValidatable parent, FormSection section, int nextPageId, FormSection?parentSection = null)
        {
            parent.Validate();

            return(nextPageId > 0
                ? (parent.IsValid ? RedirectToLastAction(parentSection ?? section) : RedirectBackToAction(section, nextPageId))
                : RedirectToLastAction(section));
        }
Exemplo n.º 10
0
        private void addFieldButton_Click(object sender, EventArgs e)
        {
            FormSection fs = FormBuilder.GetFormSection(int.Parse(newFieldSectionList.SelectedValue));
            Field       f  = FormBuilder.AddFieldToSection(fs, int.Parse(newFieldTypeList.SelectedValue), newFieldTitle.Text);

            newFieldTitle.Text = "";
            LoadForm();
        }
        public IActionResult RemoveRestraintOrder(RestraintOrderViewModel model, FormSection section, int id)
        {
            LicenceApplicationPostDataHandler.Delete <RestraintOrder>(id);

            var lastLoaded = Session.GetLoadedPage();

            return(RedirectToAction(section, lastLoaded));
        }
Exemplo n.º 12
0
        public void DeleteSection(FormSection fs)
        {
            QueryString qs = new QueryString(Request.QueryString);

            qs.Set("formSectionID", fs.FormSectionID.ToString());
            qs.Set("action", "delete");
            qs.Remove("fieldID");
            Response.Redirect(Request.Path + "?" + qs.ToString());
        }
Exemplo n.º 13
0
        protected ActionResult RedirectToPreviousPossibleView <T>(int id, FormSection section, T model) where T : IValidatable
        {
            while (!FormDefinition.CanViewPage(section, id, model))
            {
                id--;
            }

            return(RedirectBackToAction(section, id));
        }
        protected IActionResult ValidateParentAndRedirectBack(IValidatable parent, FormSection section, string actionName, FormSection?parentSection = null)
        {
            parent.Validate();
            var prevPage = FormDefinition.GetPreviousPage(section, actionName);

            return(parent.IsValid
                ? RedirectToLastActionForNewSection(parentSection ?? section)
                : RedirectBackToAction(section, prevPage.ActionName));
        }
 protected SectionViewModelBase(
     FormSection formSection,
     RecordEntryViewModelBase recordForm
     )
     : base(recordForm.FormController.ApplicationController)
 {
     FormSection = formSection;
     RecordForm  = recordForm;
 }
Exemplo n.º 16
0
        protected ActionResult RedirectToNextPossibleView <T>(int id, FormSection section, T model) where T : IValidatable
        {
            while (!formDefinition.CanViewNextModel(section, id, model))
            {
                id++;
            }

            return(RedirectToAction(section, id));
        }
Exemplo n.º 17
0
        private FormPageDefinition GetPageDefinition(FormSection section, int id)
        {
            var index = id - 1;

            if (!fieldConfiguration.Fields.ContainsKey(section) || index >= fieldConfiguration.Fields[section].Length)
            {
                return(null);
            }
            return(fieldConfiguration.Fields[section][index]);
        }
        protected IActionResult CheckParentValidityAndRedirectBack(FormSection section, int submittedPageId, FormSection?parentSection = null)
        {
            var licenceId  = Session.GetCurrentLicenceId();
            var nextPageId = submittedPageId - 1;
            var parent     = FindParentSection(section, licenceId);

            return(parent == null && nextPageId > 0
                ? RedirectBackToAction(section, nextPageId)
                : ValidateParentAndRedirectBack(parent, section, nextPageId, parentSection));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Return a view for the requested action name. If this view can't be viewed, it will seek backwards
        /// through the pages until one that can be viewed is found. If no view can be found then the last view
        /// will be returned.
        /// </summary>
        /// <typeparam name="T">The type of the parent view model.</typeparam>
        /// <param name="section">The form section.</param>
        /// <param name="actionName">The name of the action to get the view for.</param>
        /// <param name="model">The parent view model.</param>
        /// <returns>A <see cref="ViewResult"/> for the current view or a <see cref="RedirectToActionResult"/> for the next possible view.</returns>
        protected IActionResult GetPreviousView <T>(FormSection section, string actionName, T model)
        {
            if (!FormDefinition.CanViewPage(section, actionName, model))
            {
                return(RedirectToPreviousPossibleView(section, actionName, model));
            }

            var viewModel = FormDefinition.GetViewModel(section, actionName, model);

            return(View(actionName, viewModel));
        }
Exemplo n.º 20
0
        /// <summary>
        /// Return a view for the requested action name. If this view can't be viewed, it will seek forwards
        /// through the pages until one that can be viewed is found. If no view can be found then the last view
        /// will be returned.
        /// </summary>
        /// <typeparam name="T">The type of the parent view model.</typeparam>
        /// <param name="section">The form section.</param>
        /// <param name="actionName">The name of the action to get the view for.</param>
        /// <param name="model">The parent view model.</param>
        /// <returns>A <see cref="ViewResult"/> for the current view or a <see cref="RedirectToActionResult"/> for the next possible view.</returns>
        protected IActionResult GetNextView <T>(FormSection section, string actionName, T model) where T : IValidatable
        {
            if (!FormDefinition.CanViewPage(section, actionName, model))
            {
                return(RedirectToNextPossibleView(section, actionName, model));
            }

            var viewModel = FormDefinition.GetViewModel(section, actionName, model);

            return(View(actionName, viewModel));
        }
Exemplo n.º 21
0
        public object GetViewModel <TParent>(FormSection section, string actionName, TParent parent)
        {
            var page = GetPageDefinition(section, actionName);

            if (page == null || parent == null)
            {
                return(null);
            }

            return(page.GetViewModelExpressionForPage(parent));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] FormSection formSection)
        {
            if (ModelState.IsValid)
            {
                _context.Add(formSection);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(formSection));
        }
Exemplo n.º 23
0
        protected ActionResult GetPreviousView <T>(int id, FormSection section, T model) where T : IValidatable
        {
            if (!FormDefinition.CanViewPage(section, id, model))
            {
                return(RedirectToPreviousPossibleView(id, section, model));
            }

            var viewPath  = GetViewPath(section, id);
            var viewModel = FormDefinition.GetViewModel(section, id, model);

            return(View(viewPath, viewModel));
        }
Exemplo n.º 24
0
        private void addSectionButton_Click(object sender, EventArgs e)
        {
            FormSection fs = FormBuilder.AddSection(currentForm, sectionTitle.Text, sectionDescription.Text);

            sectionTitle.Text       = "";
            sectionDescription.Text = "";
            fillSectionList();
            LoadForm();
            QueryString qs = new QueryString(Request.QueryString);

            Response.Redirect(Request.Path + "?" + qs.ToString());
        }
Exemplo n.º 25
0
        public bool CanViewPage <TParent>(FormSection section, int id, TParent parent)
        {
            var page = GetPageDefinition(section, id);

            if (page.OverrideViewCondition)
            {
                return(true);
            }

            var model = GetViewModel(page, parent) as ICanView <TParent>;

            return(model == null || model.CanView(parent));
        }
Exemplo n.º 26
0
        public bool CanViewPage <TParent>(FormSection section, string actionName, TParent parent)
        {
            var page = GetPageDefinition(section, actionName);

            if (page.OverrideViewCondition)
            {
                return(true);
            }

            var model = page.GetViewModelExpressionForPage(parent) as ICanView <TParent>;

            return(model == null || model.CanView(parent));
        }
        private IValidatable FindParentSection(FormSection section, int licenceId)
        {
            IValidatable parent;

            switch (section)
            {
            case FormSection.OrganisationDetails:
                parent = LicenceApplicationViewModelBuilder.Build <OrganisationDetailsViewModel>(licenceId) ??
                         new OrganisationDetailsViewModel();
                break;

            case FormSection.PrincipalAuthority:
                parent = LicenceApplicationViewModelBuilder
                         .Build <PrincipalAuthorityViewModel, PrincipalAuthority>(
                    licenceId,
                    l => l.PrincipalAuthorities.SingleOrDefault(p => p.Id == Session.GetCurrentPaId()));
                break;

            case FormSection.AlternativeBusinessRepresentative:
                parent = LicenceApplicationViewModelBuilder
                         .Build <AlternativeBusinessRepresentativeViewModel, AlternativeBusinessRepresentative>(
                    licenceId,
                    l => l.AlternativeBusinessRepresentatives.SingleOrDefault(a =>
                                                                              a.Id == Session.GetCurrentAbrId()));
                break;

            case FormSection.DirectorOrPartner:
                parent =
                    LicenceApplicationViewModelBuilder.Build <DirectorOrPartnerViewModel, DirectorOrPartner>(
                        licenceId,
                        l => l.DirectorOrPartners.FirstOrDefault(d => d.Id == Session.GetCurrentDopId()));
                break;

            case FormSection.NamedIndividual:
                parent = LicenceApplicationViewModelBuilder.Build <NamedIndividualViewModel, NamedIndividual>(
                    licenceId,
                    l => l.NamedIndividuals.FirstOrDefault(n => n.Id == Session.GetCurrentNamedIndividualId()));
                break;

            case FormSection.Organisation:
                parent = LicenceApplicationViewModelBuilder.Build <OrganisationViewModel>(licenceId)
                         ?? new OrganisationViewModel();
                break;

            default:
                // Somehow we've saved a model without creating a parent
                parent = null;
                break;
            }
            return(parent);
        }
        protected IActionResult CheckParentValidityAndRedirectBack(FormSection section, string actionName, FormSection?parentSection = null)
        {
            var licenceId = Session.GetCurrentLicenceId();
            var parent    = FindParentSection(section, licenceId);

            if (parent != null)
            {
                return(ValidateParentAndRedirectBack(parent, section, actionName, parentSection));
            }

            var previousPage = FormDefinition.GetPreviousPage(section, actionName);

            return(RedirectBackToAction(section, previousPage.ActionName));
        }
Exemplo n.º 29
0
        public FormPageDefinition GetNextPage(FormSection section, string actionName)
        {
            // Get the index of the page that matches this action name
            for (var i = 0; i < GetSectionLength(section); i++)
            {
                if (fieldConfiguration[section][i].MatchesName(actionName))
                {
                    // return the next page in the sequence
                    return(fieldConfiguration[section][i + 1]);
                }
            }

            // if in doubt, return the final (summary) screen
            return(GetLastPage(section));
        }
Exemplo n.º 30
0
        public FormPageDefinition GetPreviousPage(FormSection section, string actionName)
        {
            // Counting back from the end, find the page that matches this action name
            for (var i = GetSectionLength(section) - 1; i > 0; i--)
            {
                if (fieldConfiguration[section][i].MatchesName(actionName))
                {
                    // return the page before the match
                    return(fieldConfiguration[section][i - 1]);
                }
            }

            // if in doubt, return the final (summary) screen
            return(GetLastPage(section));
        }
Exemplo n.º 31
0
        private void CreateDocument()
        {
            FormTable tL = new FormTable();
            tL.Columns = "50%;*";
            tL.Width = "100%";
            tL.CellPadding = 5;

            FormRow row1 = new FormRow();
            FormCell cell11 = new FormCell();
            cell11.ColSpan = 2;
            cell11.Name = "cell_11";
            row1.Cells.Add(cell11);
            tL.Rows.Add(row1);

            FormRow row2 = new FormRow();
            FormCell cell21 = new FormCell();
            FormCell cell22 = new FormCell();
            cell21.ColSpan = 1;
            cell22.ColSpan = 1;
            cell21.Name = "cell_21";
            cell22.Name = "cell_22";
            row2.Cells.Add(cell21);
            row2.Cells.Add(cell22);
            tL.Rows.Add(row2);

            FormRow row3 = new FormRow();
            FormCell cell31 = new FormCell();
            cell31.ColSpan = 2;
            cell31.Name = "cell_31";
            row3.Cells.Add(cell31);
            tL.Rows.Add(row3);

            FormSection sec1 = new FormSection();
            sec1.BorderType = 1;
            sec1.ItemIndex = 1;
            sec1.ShowLabel = true;
            sec1.Uid = "dd6acdd98240403984e561399d33d9a9";
            sec1.Labels.Add(new FormLabel("Sec1", Thread.CurrentThread.CurrentUICulture.Name));
            cell11.Sections.Add(sec1);

            FormSection sec2 = new FormSection();
            sec2.BorderType = 0;
            sec2.ItemIndex = 1;
            sec2.ShowLabel = true;
            sec2.Uid = "886cb9a3aae34e68ac8ef234d0ce8ce2";
            sec2.Labels.Add(new FormLabel("Sec2", Thread.CurrentThread.CurrentUICulture.Name));
            cell21.Sections.Add(sec2);

            FormSection sec3 = new FormSection();
            sec3.BorderType = 0;
            sec3.ItemIndex = 1;
            sec3.ShowLabel = true;
            sec3.Uid = "bb6acbb98240403784e561397b33d7a7";
            sec3.Labels.Add(new FormLabel("Sec3", Thread.CurrentThread.CurrentUICulture.Name));
            cell22.Sections.Add(sec3);

            FormSection sec4 = new FormSection();
            sec4.BorderType = 0;
            sec4.ItemIndex = 1;
            sec4.ShowLabel = true;
            sec4.Uid = Guid.NewGuid().ToString("N");
            sec4.Labels.Add(new FormLabel("Sec4", Thread.CurrentThread.CurrentUICulture.Name));
            cell31.Sections.Add(sec4);

            FormControl ctrl1 = new FormControl(FormController.SmartTableLayoutType);
            ctrl1.Columns = "50%;*";
            ctrl1.Width = "100%";
            ctrl1.CellPadding = 5;

            FormItem item1 = new FormItem();
            item1.LabelWidth = "120px";
            item1.ShowLabel = true;
            item1.Labels.Add(new FormLabel("test label1:", Thread.CurrentThread.CurrentUICulture.Name));
            item1.Uid = "9b3c4642e59b405faa2a1f38559a06cc";
            item1.RowIndex = 1;
            item1.CellIndex = 1;
            item1.RowSpan = 1;
            item1.ColSpan = 2;
            FormControl item1c = new FormControl(FormController.MetaPrimitiveControlType);
            item1c.Uid = Guid.NewGuid().ToString("N");
            item1c.Source = "Title";
            item1.Control = item1c;
            ctrl1.Items.Add(item1);

            FormItem item2 = new FormItem();
            item2.LabelWidth = "120px";
            item2.ShowLabel = true;
            item2.Labels.Add(new FormLabel("test label2:", Thread.CurrentThread.CurrentUICulture.Name));
            item2.Uid = "cafa725a31b74ad6a069e3b6446d89c0";
            item2.RowIndex = 2;
            item2.CellIndex = 1;
            item2.RowSpan = 1;
            item2.ColSpan = 1;
            FormControl item2c = new FormControl(FormController.MetaPrimitiveControlType);
            item2c.Uid = Guid.NewGuid().ToString("N");
            item2c.Source = "Priority";
            item2.Control = item2c;
            ctrl1.Items.Add(item2);

            FormItem item3 = new FormItem();
            item3.LabelWidth = "120px";
            item3.ShowLabel = true;
            item3.Labels.Add(new FormLabel("test label3:", Thread.CurrentThread.CurrentUICulture.Name));
            item3.Uid = "8d36be893c3f4cf1b5295be6853eb246";
            item3.RowIndex = 3;
            item3.CellIndex = 1;
            item3.RowSpan = 1;
            item3.ColSpan = 1;
            FormControl item3c = new FormControl(FormController.MetaPrimitiveControlType);
            item3c.Uid = Guid.NewGuid().ToString("N");
            item3c.Source = "Created";
            item3.Control = item3c;
            ctrl1.Items.Add(item3);

            FormItem item4 = new FormItem();
            item4.LabelWidth = "120px";
            item4.ShowLabel = true;
            item4.Labels.Add(new FormLabel("test label4:", Thread.CurrentThread.CurrentUICulture.Name));
            item4.Uid = "a5d87024cbf849cea5d273d77a292e6f";
            item4.RowIndex = 2;
            item4.CellIndex = 2;
            item4.RowSpan = 2;
            item4.ColSpan = 1;
            FormControl item4c = new FormControl(FormController.MetaPrimitiveControlType);
            item4c.Uid = Guid.NewGuid().ToString("N");
            item4c.Source = "Description";
            item4.Control = item4c;
            ctrl1.Items.Add(item4);

            sec1.Control = ctrl1;

            //FormDocument fd = new FormDocument();
            FormDocument fd = FormDocument.Load("Task", "[MC_BaseForm]");
            fd.MetaClassName = "Task";
            fd.Name = "[MC_BaseForm]";
            fd.FormTable = tL;
            fd.Save();
        }