/// <summary>
        /// Updateds the element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public override UPMElement UpdatedElement(UPMElement element)
        {
            UPMInBoxPage oldPage = (UPMInBoxPage)this.TopLevelElement;
            UPMInBoxPage page    = new UPMInBoxPage(StringIdentifier.IdentifierWithStringId("Inbox"))
            {
                UploadFieldGroup     = oldPage.UploadFieldGroup,
                FileNameEditField    = oldPage.FileNameEditField,
                SkipUploadIfPossible = oldPage.SkipUploadIfPossible
            };

            UPInboxFileManager manager = UPInboxFileManager.CurrentInboxFileManager();
            List <UPInboxFile> files   = manager.AllInboxFiles();

            foreach (UPInboxFile inboxFile in files)
            {
                UPMInboxFile upmInboxFile = ModelInboxFileFromInboxFile(inboxFile);
                page.AddChild(upmInboxFile);
            }

            this.TopLevelElement = page;
            this.SortFilesByDate();
            page.Invalid = false;
            this.InformAboutDidChangeTopLevelElement(page, page, null, null);
            return(element);
        }
        /// <summary>
        /// Sorts the name of the files by file.
        /// </summary>
        public void SortFilesByFileName()
        {
            UPMInBoxPage      page        = this.InboxPage;
            List <UPMElement> sortedArray = page.Children.OrderBy(x => ((UPMInboxFile)x).Name).ToList();

            page.RemoveAllChildren();
            foreach (UPMElement element in sortedArray)
            {
                page.AddChild(element);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="UPInBoxPageModelController"/> class.
        /// </summary>
        /// <param name="viewReference">The view reference.</param>
        public UPInBoxPageModelController(ViewReference viewReference)
            : base(viewReference)
        {
            UPMInBoxPage page = new UPMInBoxPage(StringIdentifier.IdentifierWithStringId("Inbox"))
            {
                Invalid = true,
                SkipUploadIfPossible = viewReference.ContextValueIsSet("SkipUploadPageIfPossible")
            };

            this.removeUploadedFileFromInbox = viewReference.ContextValueIsSet("RemoveUploadedFile");
            this.TopLevelElement             = page;
            this.editFieldContexts           = new Dictionary <StringIdentifier, UPEditFieldContext>();
            IConfigurationUnitStore configStore      = ConfigurationUnitStore.DefaultStore;
            FieldControl            editFieldControl = configStore.FieldControlByNameFromGroup("Edit", viewReference.ContextValueForKey("UploadFields"));
            UPMGroup uploadFieldGroup = new UPMGroup(StringIdentifier.IdentifierWithStringId("uploadFieldGroup"));

            if (editFieldControl != null)
            {
                int numberOfFields = editFieldControl.NumberOfFields;
                for (int index = 0; index < numberOfFields; index++)
                {
                    UPConfigFieldControlField field                 = editFieldControl.FieldAtIndex(index);
                    StringIdentifier          fieldIdentifier       = StringIdentifier.IdentifierWithStringId($"Field {field.FieldId} {field.InfoAreaId}");
                    UPEditFieldContext        initialValueEditField = UPEditFieldContext.FieldContextFor(field, fieldIdentifier, null, (List <UPEditFieldContext>)null);
                    this.editFieldContexts[fieldIdentifier] = initialValueEditField;
                    if (field.Function == "Filename")
                    {
                        page.FileNameEditField = initialValueEditField.EditField;
                    }

                    uploadFieldGroup.AddField(initialValueEditField.EditField);
                }
            }

            this.recordIdentification = this.ViewReference.ContextValueForKey("RecordId");
            page.UploadFieldGroup     = uploadFieldGroup; // load directly
            this.UpdatedElement(page);
        }