Пример #1
0
        public ITaxonName SaveTaxonNameDetailsChanges(TaxonNameDetailsViewModel model, int taxonId, ITaxonRevision taxonRevision)
        {
            ITaxon     taxon     = CoreData.TaxonManager.GetTaxon(_user, taxonId);
            ITaxonName taxonName = taxon.GetTaxonNameByVersion(_user, Int32.Parse(model.Version));

            taxonName.Name      = model.Name;
            taxonName.Author    = model.Author;
            taxonName.Category  = CoreData.TaxonManager.GetTaxonNameCategory(_user, model.SelectedCategoryId);
            taxonName.Status    = CoreData.TaxonManager.GetTaxonNameStatus(_user, model.SelectedTaxonNameStatusId);
            taxonName.NameUsage = CoreData.TaxonManager.GetTaxonNameUsage(_user, model.SelectedTaxonNameUsageId);
            //taxonName.IsRecommended = model.IsRecommended;
            taxonName.Description = model.Comment;
            taxonName.Taxon       = CoreData.TaxonManager.GetTaxon(_user, model.TaxonId);
            taxonName.IsOkForSpeciesObservation = !model.IsNotOkForObsSystem;
            taxonName.IsOriginalName            = model.IsOriginal;

            // at least one scientific name must be recommended
            if (taxonName.Category.Id == (Int32)TaxonNameCategoryId.ScientificName && taxonName.IsRecommended == false)
            {
                var  scientificNames  = taxon.GetTaxonNames(_user).Where(name => name.Category.Id == (Int32)TaxonNameCategoryId.ScientificName).ToList();
                bool isAnyRecommended = scientificNames.Any(scientificName => scientificName.IsRecommended);
                if (!isAnyRecommended)
                {
                    taxonName.IsRecommended = true;
                }
            }

            using (ITransaction transaction = _user.StartTransaction())
            {
                CoreData.TaxonManager.UpdateTaxonName(_user, taxonRevision, taxonName);

                transaction.Commit();
            }
            return(taxonName);
        }
Пример #2
0
        public TaxonNameDetailsViewModel GetTaxonNameDetailsViewModel(ITaxon taxon, string nameId)
        {
            ITaxonName taxonName = taxon.GetTaxonNameByVersion(_user, Int32.Parse(nameId));
            var        model     = TaxonNameDetailsViewModel.Create(_user, taxonName);

            InitTaxonNameDetails(model, taxon);
            return(model);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="taxon"></param>
        /// <returns></returns>
        public TaxonNameDetailsViewModel GetTaxonNameDetailsViewModel(ITaxon taxon)
        {
            var model = new TaxonNameDetailsViewModel();

            model.TaxonId = taxon.Id;
            InitTaxonNameDetails(model, taxon);
            return(model);
        }
Пример #4
0
        public void InitTaxonNameDetails(TaxonNameDetailsViewModel model, ITaxon taxon)
        {
            model.CategoryList = new List <TaxonDropDownModelHelper>();
            TaxonNameCategoryList nameList = CoreData.TaxonManager.GetTaxonNameCategories(_user);

            foreach (TaxonNameCategory nameCategory in nameList)
            {
                model.CategoryList.Add(new TaxonDropDownModelHelper(nameCategory.Id, nameCategory.Name));
            }
            model.TaxonNameStatusList = new List <TaxonDropDownModelHelper>();
            TaxonNameStatusList nameStatusList = CoreData.TaxonManager.GetTaxonNameStatuses(_user);

            foreach (ITaxonNameStatus nameStatus in nameStatusList.OrderBy(t => t.SortOrder()))
            {
                model.TaxonNameStatusList.Add(new TaxonDropDownModelHelper(nameStatus.Id, nameStatus.Name));
            }
            model.TaxonNameUsageList = new List <TaxonDropDownModelHelper>();
            TaxonNameUsageList nameUsageList = CoreData.TaxonManager.GetTaxonNameUsages(_user);

            foreach (ITaxonNameUsage nameUsage in nameUsageList)
            {
                model.TaxonNameUsageList.Add(new TaxonDropDownModelHelper(nameUsage.Id, nameUsage.Name));
            }
            model.ExistingNames = new List <TaxonNameDetailsViewModel>();
            TaxonNameList taxonNames = taxon.GetTaxonNames(_user);

            for (int i = 0; i < taxonNames.Count; i++)
            {
                ITaxonName taxonName = taxonNames[i];
                model.ExistingNames.Add(TaxonNameDetailsViewModel.Create(_user, taxonName));
            }
            model.ExistingNames = (from name in model.ExistingNames orderby name.CategoryName select name).ToList();
            for (int i = 0; i < model.ExistingNames.Count; i++)
            {
                if (model.ExistingNames[i].Id == model.Id)
                {
                    model.ExistingNamesCurrentIndex = i;
                    break;
                }
            }

            // Check name category if Scentific and recommended it is not possible to change status.
            // Unselcet as recommended first and the it is possible to change name usage
            if (model.IsRecommended && (model.SelectedCategoryId == (Int32)TaxonNameCategoryId.ScientificName))
            {
                model.IsPossibleToChangeUsage = false;
            }
            else
            {
                model.IsPossibleToChangeUsage = true;
            }
        }
Пример #5
0
        public ITaxonName AddTaxonName(TaxonNameDetailsViewModel model, int taxonId, ITaxonRevision taxonRevision)
        {
            ITaxon taxon = CoreData.TaxonManager.GetTaxon(_user, taxonId);

            var taxonName = new ArtDatabanken.Data.TaxonName();

            taxonName.DataContext = new DataContext(_user);
            taxonName.Name        = model.Name;
            taxonName.Author      = model.Author;
            taxonName.Category    = CoreData.TaxonManager.GetTaxonNameCategory(_user, model.SelectedCategoryId);
            taxonName.Status      = CoreData.TaxonManager.GetTaxonNameStatus(CoreData.UserManager.GetCurrentUser(), model.SelectedTaxonNameStatusId);
            taxonName.NameUsage   = CoreData.TaxonManager.GetTaxonNameUsage(CoreData.UserManager.GetCurrentUser(), model.SelectedTaxonNameUsageId);
            // Todo Not set in GUI only Changed in list
            taxonName.IsRecommended = model.IsRecommended;
            taxonName.Description   = model.Comment;
            // taxonName.Taxon = CoreData.TaxonManager.GetTaxon(_user, model.TaxonId);
            taxonName.IsOkForSpeciesObservation = !model.IsNotOkForObsSystem;
            taxonName.IsOriginalName            = model.IsOriginal;
            taxonName.Taxon = taxon;

            CoreData.TaxonManager.CreateTaxonName(_user, taxonRevision, taxonName);
            //CoreData.TaxonManager.AddTaxonName(_user, taxon, revision, taxonName);
            return(taxonName);
        }
        public static TaxonNameDetailsViewModel Create(IUserContext userContext, ITaxonName taxonName)
        {
            var model = new TaxonNameDetailsViewModel();

            model.TaxonId = taxonName.Taxon.Id;
            if (taxonName.Id == 0)
            {
                model.Id = taxonName.Version;
            }
            else
            {
                model.Id = taxonName.Id;
            }
            model.Name                      = taxonName.Name;
            model.Comment                   = taxonName.Description;
            model.Author                    = taxonName.Author;
            model.SelectedCategoryId        = taxonName.Category.Id;
            model.SelectedTaxonNameStatusId = taxonName.Status.Id;
            model.SelectedTaxonNameUsageId  = taxonName.NameUsage.Id;
            model.NameStatusText            = taxonName.Status.Name;
            model.NameUsageText             = taxonName.NameUsage.Name;
            model.IsRecommended             = taxonName.IsRecommended;
            model.IsNotOkForObsSystem       = !taxonName.IsOkForSpeciesObservation;
            model.Version                   = taxonName.Version.ToString();
            model.IsOriginal                = taxonName.IsOriginalName;
            model.CategoryName              = taxonName.Category.Name;
            model.LastUpdated               = taxonName.ModifiedDate;

            //// Set "modified by user". CoreData.UserManager.GetUser is a slow operation, so we store each entry in a dictionary.
            //IUser modifiedByUser;
            //if (dicLoadedUsers == null)
            //{
            //    dicLoadedUsers = new Dictionary<int, IUser>();
            //}
            //if (!dicLoadedUsers.ContainsKey(taxonName.ModifiedBy))
            //{
            //    modifiedByUser = CoreData.UserManager.GetUser(CoreData.UserManager.GetCurrentUser(), taxonName.ModifiedBy);
            //    dicLoadedUsers.Add(taxonName.ModifiedBy, modifiedByUser);
            //}
            //else
            //{
            //    modifiedByUser = dicLoadedUsers[taxonName.ModifiedBy];
            //}
            model.UpdatedBy = taxonName.ModifiedByPerson;

            if (taxonName.Guid.IsNotNull())
            {
                model.TaxonNameGuid = taxonName.Guid;
            }

            model.TaxonNameReferencesList = new List <int>();
            model.NoOfTaxonNameReferences = 0;
            if (taxonName.GetReferences(userContext).IsNotEmpty())
            {
                foreach (ReferenceRelation referenceRelation in taxonName.GetReferences(userContext))
                {
                    model.NoOfTaxonNameReferences++;
                }
            }

            return(model);
        }