/// <summary>
        /// Get view for stopEditing
        /// </summary>
        /// <param name="revisionInfos"></param>
        /// <param name="loggedInUser"></param>
        /// <param name="model"></param>
        /// <param name="userRevisions"></param>
        public RevisionCommonInfoViewModel GetStopEditingViewModel(
            List <RevisionInfoItemModelHelper> revisionInfos,
            IUserContext loggedInUser,
            RevisionCommonInfoViewModel model,
            TaxonRevisionList userRevisions,
            bool submit)
        {
            foreach (ITaxonRevision userRevision in userRevisions)
            {
                ITaxon revisionTaxon = userRevision.RootTaxon;
                RevisionInfoItemModelHelper infoItem = new RevisionInfoItemModelHelper();
                infoItem.FormName = "commonInfoForm";
                RevisionModelManager modelManager = new RevisionModelManager();
                infoItem = modelManager.GetRevisionInformation(loggedInUser, revisionTaxon, userRevision, infoItem);
                infoItem.ShowRevisionEditingButton   = true;
                infoItem.EnableRevisionEditingButton = false;
                infoItem.ShowRevisionInformation     = false;

                // Check if user has role for this revision
                if (loggedInUser.CurrentRole.IsNotNull() && loggedInUser.CurrentRole.Identifier.IsNotNull() &&
                    loggedInUser.CurrentRole.Identifier.Contains(userRevision.Guid))
                {
                    infoItem.EnableRevisionEditingButton = true;
                    infoItem.ShowRevisionInformation     = true;
                    infoItem.RevisionEditingButtonText   = Resources.DyntaxaResource.RevisionStopEditingButtonText;
                    infoItem.RevisionEditingButtonText   = Resources.DyntaxaResource.RevisionStopEditingButtonText;
                    infoItem.RevisionId           = userRevision.Id.ToString();
                    infoItem.TaxonId              = userRevision.RootTaxon.Id.ToString();
                    infoItem.RevisionWaitingLabel = " " + Resources.DyntaxaResource.RevisionStopMainHeaderText
                                                    + " " + Resources.DyntaxaResource.SharedRevisionText + " " + Resources.DyntaxaResource.SharedRevisionIdLabel + ": "
                                                    + userRevision.Id.ToString();
                    infoItem.EditingAction     = "StopEditing";
                    infoItem.EditingController = "Revision";
                    revisionInfos.Add(infoItem);
                }
            }
            // Check that ther is any data and if nothing has been set set the first to be expanded if ther is only one revision.
            var items = revisionInfos.Where(r => r.ShowRevisionInformation);

            if (!items.Any() && revisionInfos.IsNotNull() && revisionInfos.Count == 1)
            {
                revisionInfos.FirstOrDefault().ShowRevisionInformation = true;
            }

            model.EditingAction                   = "StopEditing";
            model.EditingController               = "Revision";
            model.RevisionInfoItems               = revisionInfos;
            model.RevisionEditingHeaderText       = Resources.DyntaxaResource.RevisionStopMainHeaderText;
            model.RevisionEditingActionHeaderText = Resources.DyntaxaResource.RevisionStopEditingActionHeaderText;

            model.DialogTextPopUpText  = Resources.DyntaxaResource.SharedRevisionNoValidRevisionErrorText;
            model.DialogTitlePopUpText = Resources.DyntaxaResource.RevisionStopMainHeaderText;
            model.Submit = submit;
            return(model);
        }
        /// <summary>
        /// Get view for startEditing
        /// </summary>
        /// <param name="revisions"></param>
        /// <param name="loggedInUser"></param>
        /// <param name="dyntaxaApplicationUserContext"></param>
        /// <param name="model"></param>
        /// <param name="submit"></param>
        /// <param name="roles"></param>
        /// <returns></returns>
        public RevisionCommonInfoViewModel GetStartEditingViewModel(
            TaxonRevisionList revisions,
            IUserContext loggedInUser,
            IUserContext dyntaxaApplicationUserContext,
            RevisionCommonInfoViewModel model,
            bool submit,
            RoleList roles)
        {
            IList <RevisionInfoItemModelHelper> revisionInfos = new List <RevisionInfoItemModelHelper>();
            //Check if current role is set to any of the avaliable revisions
            bool alreadyEditor = false;

            if (loggedInUser.CurrentRole.IsNotNull())
            {
                foreach (ITaxonRevision revision in revisions)
                {
                    if (loggedInUser.CurrentRole.IsNotNull() && loggedInUser.CurrentRole.Identifier.Contains(revision.Guid))
                    {
                        alreadyEditor = true;
                        break;
                    }
                }
            }

            // Get revisions for this user
            TaxonRevisionList userRevisions = new TaxonRevisionList();

            foreach (ITaxonRevision revision in revisions)
            {
                // Check if user has role to edit the revision
                foreach (IRole role in roles)
                {
                    if (role.Identifier.IsNotNull())
                    {
                        if (role.Identifier.Contains(revision.Guid))
                        {
                            userRevisions.Add(revision);
                            break;
                        }
                    }
                }
            }
            // bool revsionExpanded = false;
            foreach (ITaxonRevision userRevision in userRevisions)
            {
                ITaxon revisionTaxon = userRevision.RootTaxon;
                // First we check which revisions that is enabels for this user
                RevisionInfoItemModelHelper infoItem     = new RevisionInfoItemModelHelper();
                RevisionModelManager        modelManager = new RevisionModelManager();
                infoItem.EnableRevisionEditingButton    = false;
                infoItem.SelectedRevisionForEditingText = string.Empty;
                // Do not enable any buttons if editor is already working on a revision
                if (!alreadyEditor)
                {
                    // Check if user has role to edit the revision
                    foreach (IRole role in roles)
                    {
                        if (role.Identifier.IsNotNull())
                        {
                            if (role.Identifier.Contains(userRevision.Guid))
                            {
                                infoItem.EnableRevisionEditingButton = true;
                                //if (!revsionExpanded)
                                //{
                                //    infoItem.ShowRevisionInformation = true;
                                //    revsionExpanded = true;
                                //}
                                infoItem.ShowRevisionInformation = false;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (loggedInUser.CurrentRole.IsNotNull() &&
                        loggedInUser.CurrentRole.Identifier.Contains(userRevision.Id.ToString()))
                    {
                        infoItem.SelectedRevisionForEditingText = Resources.DyntaxaResource.RevisionStartRevisionForEditingText;
                        // infoItem.ShowRevisionInformation = true;
                    }
                }

                infoItem = modelManager.GetRevisionInformation(loggedInUser, revisionTaxon, userRevision, infoItem);
                infoItem.ShowRevisionEditingButton = true;

                infoItem.RevisionEditingButtonText = Resources.DyntaxaResource.RevisionStartEditingButtonText;
                infoItem.RevisionEditingButtonText = Resources.DyntaxaResource.RevisionStartEditingButtonText;
                infoItem.RevisionId           = userRevision.Id.ToString();
                infoItem.TaxonId              = userRevision.RootTaxon.Id.ToString();
                infoItem.RevisionWaitingLabel = " " + Resources.DyntaxaResource.RevisionStartMainHeaderText
                                                + " " + Resources.DyntaxaResource.SharedRevisionText + " " + Resources.DyntaxaResource.SharedRevisionIdLabel + ": "
                                                + userRevision.Id.ToString();
                infoItem.EditingAction     = "StartEditing";
                infoItem.EditingController = "Revision";
                revisionInfos.Add(infoItem);
            }

            // Check that there is any data and if nothing has been set set the first to be expanded if there is only one revision.
            if (revisionInfos.IsNotNull() && revisionInfos.Count == 1)
            {
                revisionInfos.FirstOrDefault().ShowRevisionInformation = true;
            }

            model.EditingAction                   = "StartEditing";
            model.EditingController               = "Revision";
            model.RevisionInfoItems               = revisionInfos;
            model.RevisionEditingHeaderText       = Resources.DyntaxaResource.RevisionStartMainHeaderText;
            model.RevisionEditingActionHeaderText = Resources.DyntaxaResource.RevisionStartEditingActionHeaderText;

            model.DialogTextPopUpText  = Resources.DyntaxaResource.SharedRevisionNoValidRevisionErrorText;
            model.DialogTitlePopUpText = Resources.DyntaxaResource.RevisionStartMainHeaderText;
            model.Submit = submit;
            return(model);
        }
        /// <summary>
        /// Returns information extracted from revision
        /// </summary>
        /// <param name="loggedInUser"></param>
        /// <param name="revisionTaxon"></param>
        /// <param name="taxonRevision"></param>
        /// <param name="infoItem"></param>
        /// <returns></returns>
        public RevisionInfoItemModelHelper GetRevisionInformation(IUserContext loggedInUser, ITaxon revisionTaxon, ITaxonRevision taxonRevision, RevisionInfoItemModelHelper infoItem)
        {
            infoItem.ExpectedStartDate      = taxonRevision.ExpectedStartDate.ToShortDateString();
            infoItem.ExpectedPublishingDate = taxonRevision.ExpectedEndDate.ToShortDateString();
            infoItem.RevisionDescription    = taxonRevision.Description;
            infoItem.RevisionId             = taxonRevision.Id.ToString();
            infoItem.TaxonId = revisionTaxon.Id.ToString();
            int state = taxonRevision.State.Id;

            if (state == (int)TaxonRevisionStateId.Created)
            {
                infoItem.RevisionStatus = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusCreatedText;
            }
            else if (state == (int)TaxonRevisionStateId.Ongoing)
            {
                infoItem.RevisionStatus = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusOngoingText;
            }
            else if (state == (int)TaxonRevisionStateId.Closed)
            {
                infoItem.RevisionStatus = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusClosedText;
            }
            if (revisionTaxon.ScientificName.IsNotEmpty())
            {
                infoItem.ScientificName = revisionTaxon.ScientificName;
            }
            if (revisionTaxon.CommonName.IsNotEmpty())
            {
                infoItem.CommonName = revisionTaxon.CommonName;
            }
            infoItem.TaxonCategory = revisionTaxon.Category.Name;
            return(infoItem);
        }