示例#1
0
        public static NodeModel Convert(Node node)
        {
            NodeModel model = new NodeModel();

            model.Id             = node.Id;
            model.ScientificName = node.ScientificName;
            model.TaxonRank      = node.Rank;
            if (!String.IsNullOrEmpty(node.Name))
            {
                model.Name = node.Name;
            }

            if (!String.IsNullOrEmpty(node.Description))
            {
                model.Description = node.Description;
            }

            model.Type = GetType(node);

            if (!node.Medias.Any())
            {
                model.ImagePath = "/Images/Empty.png";
            }
            else
            {
                model.ImagePath = node.Medias.Last().ImagePath;
            }

            model.Parent = node.Parent != null?SimpleNodeViewModel.Convert(node.Parent) : new SimpleNodeViewModel();

            model.Childrens = ModelHelper.GetChildren(node.Id);

            return(model);
        }
示例#2
0
        public static AnimalModel Convert(Animal animal)
        {
            AnimalModel model = new AnimalModel();

            model.Id = animal.Id;

            #region subject

            if (!String.IsNullOrEmpty(animal.Name))
            {
                model.Name = animal.Name;
            }

            if (!String.IsNullOrEmpty(animal.Rank.ToString()))
            {
                model.TaxonRank = animal.Rank;
            }

            if (!String.IsNullOrEmpty(animal.Description))
            {
                model.Description = animal.Description;
            }

            model.Type = GetType(animal);

            if (animal.Medias.Count() == 0)
            {
                model.ImagePath = "/Images/Empty.png";
            }
            else
            {
                model.ImagePath = animal.Medias.Last().ImagePath;
            }

            if (model.LifeCycles != null)
            {
                model.LifeCycles = TimePeriodsToLifeCycles(animal.TimePeriods);
            }

            #endregion subject

            model.ScientificName = animal.ScientificName;

            #region loadParentModels

            if (animal.Parent != null)
            {
                model.Parent = SimpleNodeViewModel.Convert(animal.Parent);
            }

            #endregion loadParentModels

            //load children
            model.Childrens = ModelHelper.GetChildren(animal.Id);

            return(model);
        }
示例#3
0
        public static SimpleNodeViewModel Convert(Node node)
        {
            SimpleNodeViewModel model = new SimpleNodeViewModel();

            model.Id             = node.Id;
            model.Name           = node.Name;
            model.ScientificName = node.ScientificName;
            model.Description    = node.Description;
            model.TaxonRank      = node.Rank;

            model.Type = ModelHelper.GetType(node);

            if (node.Parent != null)
            {
                model.Parent = Convert(node.Parent);
            }

            return(model);
        }
示例#4
0
        public static PlantModel Convert(Plant plant)
        {
            PlantModel model = new PlantModel();

            model.Id = plant.Id;

            #region subject

            if (!String.IsNullOrEmpty(plant.Name))
            {
                model.Name = plant.Name;
            }

            if (!String.IsNullOrEmpty(plant.Rank.ToString()))
            {
                model.TaxonRank = plant.Rank;
            }

            if (!String.IsNullOrEmpty(plant.Description))
            {
                model.Description = plant.Description;
            }

            model.Type        = GetType(plant);
            model.SowingDepth = plant.SowingDepth;

            if (plant.Medias.Count() == 0)
            {
                model.ImagePath = "/Images/Empty.png";
            }
            else
            {
                model.ImagePath = plant.Medias.Last().ImagePath;
            }

            #endregion subject

            model.ScientificName = plant.ScientificName;
            model.Width          = plant.Width;
            model.Height         = plant.Height;
            model.NutrientClaim  = plant.NutrientClaim;
            model.RootDepth      = plant.RootDepth;
            model.LocationType   = plant.LocationType;

            #region Dates

            if (model.LifeCycles != null)
            {
                model.LifeCycles = TimePeriodsToLifeCycles(plant.TimePeriods);
            }

            #endregion Dates

            #region loadParentModels

            if (plant.Parent != null)
            {
                model.Parent = SimpleNodeViewModel.Convert(plant.Parent);
            }

            #endregion loadParentModels

            #region load pre/after cultures

            if (plant.PreCultures.Count > 0)
            {
                foreach (var p in plant.PreCultures)
                {
                    model.PreCultures.Add(new CultureModel(p.Id, p.Name, SubjectType.Plant));
                }
            }
            else
            {
                model.PreCultures.Add(new CultureModel());
            }

            if (plant.AfterCultures.Count > 0)
            {
                foreach (var p in plant.AfterCultures)
                {
                    model.AfterCultures.Add(new CultureModel(p.Id, p.Name, SubjectType.Plant));
                }
            }
            else
            {
                model.AfterCultures.Add(new CultureModel());
            }

            #endregion load pre/after cultures

            //load children
            model.Childrens = ModelHelper.GetChildren(plant.Id);


            return(model);
        }