Example #1
0
        // GET api/<controller>/5
        public SubjectModel Get(int id)
        {
            SubjectManager manager = new SubjectManager();
            var            subject = manager.Get(id);

            return(SubjectModel.Convert(subject));
        }
Example #2
0
        public ActionResult AddRandomPlant(long id)
        {
            PatchManager   patchManager   = new PatchManager();
            Patch          patch          = patchManager.Get(id);
            SubjectManager subjectManager = new SubjectManager();

            List <long> ids = subjectManager.GetAll <Plant>().Select(pa => pa.Id).ToList();


            Random random    = new Random();
            int    randomInt = random.Next(1, ids.Count - 1);

            long plantId = ids.ElementAt(randomInt);

            Plant p = subjectManager.Get(plantId) as Plant;

            Placement placement = new Placement();

            placement.Plant = p;
            placement.Patch = patch;

            patch.PatchElements.Add(placement);

            patchManager.Update(patch);

            PlacementModel model = PatchModelHelper.ConvertTo(placement);

            return(PartialView("Placement", model));
        }
Example #3
0
        public ActionResult Details(long id, string type)
        {
            SubjectManager sm = new SubjectManager();

            Subject s = sm.Get(id);

            //load by loading the page and store it in a session!!!!

            switch (type)
            {
            case "Plant":
            {
                Plant plant = sm.GetAll <Plant>().Where(p => p.Id.Equals(id)).FirstOrDefault();

                PlantModel Model = PlantModel.Convert(plant);
                //load interactions
                Model.Interactions = SubjectModel.ConverInteractionModels(sm.GetAllDependingInteractions(plant, true).ToList());

                return(View("PlantDetails", Model));
            }

            case "Animal":
            {
                Animal animal = sm.GetAll <Animal>().Where(a => a.Id.Equals(id)).FirstOrDefault();

                AnimalModel Model = AnimalModel.Convert(animal);
                Model.Interactions = SubjectModel.ConverInteractionModels(sm.GetAllDependingInteractions(animal, true).ToList());

                return(View("AnimalDetails", Model));
            }

            case "Taxon":
            {
                Taxon     taxon = sm.GetAll <Taxon>().Where(a => a.Id.Equals(id)).FirstOrDefault();
                NodeModel Model = NodeModel.Convert(taxon);

                return(View("TaxonDetails", Model));
            }

            case "Effect":
            {
                Effect effect = sm.GetAll <Effect>().Where(e => e.Id.Equals(id)).FirstOrDefault();

                return(View("EffectDetails"));
            }

            case "Unknow":
            {
                SubjectModel Model = SubjectModel.Convert(s);

                return(View("SubjectDetails", Model));
            }

            default: { break; }
            }

            return(RedirectToAction("Search", "Search"));;
        }
Example #4
0
        public JsonResult GetEventsForGantt(long id)
        {
            SubjectManager subjectmanager = new SubjectManager();

            //ToDo replace getAll with get plant by id
            var subject = subjectmanager.Get(id);
            var events  = new List <object>();

            if (subject != null)
            {
                events.AddRange(GantHelper.GetAllEventsFromSubject(subject));
            }

            return(Json(events.ToArray(), JsonRequestBehavior.AllowGet));
        }
Example #5
0
        public ActionResult SaveImage(long id)
        {
            try
            {
                foreach (string file in Request.Files)
                {
                    var fileContent = Request.Files[file];
                    if (fileContent != null && fileContent.ContentLength > 0)
                    {
                        // get a stream
                        var stream = fileContent.InputStream;
                        // and optionally write the file to disk
                        var fileName = Path.GetFileName(fileContent.FileName);

                        if (fileName.Equals("Empty.png"))
                        {
                            return(Json("no image selected", JsonRequestBehavior.AllowGet));
                        }

                        var path = Path.Combine(Server.MapPath("~/Images"), fileName);
                        using (var fileStream = System.IO.File.Create(path))
                        {
                            stream.CopyTo(fileStream);

                            SubjectManager subjectManager = new SubjectManager();
                            Subject        s = subjectManager.Get(id);

                            Media media = new Media();
                            media.ImagePath = "/Images/" + fileName;

                            s.Medias.Add(media);

                            subjectManager.Update(s);
                        }
                    }
                }
            }
            catch (Exception)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Upload failed", JsonRequestBehavior.AllowGet));
            }

            return(Json("File uploaded successfully", JsonRequestBehavior.AllowGet));
        }
Example #6
0
        private void testTimperiods()
        {
            SubjectManager subjectManager = new SubjectManager();

            Subject subject = new Subject();

            subject.Name        = "ALTER FETTE SCHEIßE 3";
            subject.Description = "ES FUNKT 3";
            subjectManager.Create(subject);

            Sowing start = new Sowing();

            start.AssignedTo = subject;
            start.StartArea  = TimePeriodArea.Anfang;
            start.StartMonth = TimePeriodMonth.Januar;
            start.EndArea    = TimePeriodArea.Anfang;
            start.EndMonth   = TimePeriodMonth.Februar;
            start.Start      = true;


            Harvest ende = new Harvest();

            ende.AssignedTo = subject;
            ende.StartArea  = TimePeriodArea.Mitte;
            ende.StartMonth = TimePeriodMonth.März;
            ende.EndArea    = TimePeriodArea.Ende;
            ende.EndMonth   = TimePeriodMonth.Juli;
            ende.Start      = false;


            //ende = subjectManager.Create(ende);
            start.Next = ende;

            //start = subjectManager.Create(start);

            subject.TimePeriods.Add(start);
            subject.TimePeriods.Add(ende);

            subjectManager.Update(subject);


            var s = subjectManager.Get(subject.Id);
        }
Example #7
0
        public IActionResult Add(SubjectModel model)
        {
            if (ModelState.IsValid)
            {
                var sub = SubjectManager.Get(model.Name);

                if (sub != null)
                {
                    ModelState.AddModelError("err", "Subject already exists in List!");
                }

                else
                {
                    SubjectManager.Create(model.Name);
                    return(RedirectToAction(nameof(Index)));
                }
            }

            return(View(model));
        }
Example #8
0
        public ActionResult SaveTaxon(NodeModel taxonModel)
        {
            SubjectManager     subjectManager     = new SubjectManager();
            InteractionManager interactionManager = new InteractionManager();

            //ToDo Store Image in folder : project/images/
            //add a media to plant

            Taxon taxon = new Taxon();

            if (taxonModel.Id > 0)
            {
                var x = subjectManager.Get(taxonModel.Id).Self;
                taxon = x as Taxon;
            }

            taxon.Name           = taxonModel.Name;
            taxon.ScientificName = taxonModel.ScientificName;
            taxon.Rank           = taxonModel.TaxonRank;
            //TODO Generate the Parent based on the ScientificName
            // a a a = SubSpecies, a a = Species, a = Genus
            // a a var. a is also a species

            /* - based on the scientficname create or set the parents
             * - use maybe some webservices to create missing one
             *
             */

            //Todo Select the type based on the scientific name
            //animal.Rank = Utility.GetTaxonRank(animal.ScientificName);

            if (!taxon.Medias.Where(m => m.ImagePath.Equals(taxonModel.ImagePath)).Any())
            {
                taxon.Medias.Add(new Media()
                {
                    ImagePath = taxonModel.ImagePath,
                    MIMEType  = MimeMapping.GetMimeMapping(taxonModel.ImagePath)
                });
            }


            if (taxon.Id == 0)
            {
                taxon = subjectManager.CreateTaxon(taxon);
            }
            else
            {
                subjectManager.Update(taxon);
            }

            //set parent
            if (taxonModel.Parent != null && taxonModel.Parent.Id > 0)
            {
                var parent = subjectManager.GetAll <Node>().Where(n => n.Id.Equals(taxonModel.Parent.Id)).FirstOrDefault();
                taxon.Parent = parent;
            }
            else // delete taxon from plant
            {
                taxon.Parent = null;
            }

            subjectManager.Update(taxon);



            return(Json(taxon.Id, JsonRequestBehavior.AllowGet));
        }
Example #9
0
        public ActionResult SaveAnimal(AnimalModel animalModel)
        {
            try
            {
                SubjectManager     subjectManager     = new SubjectManager();
                InteractionManager interactionManager = new InteractionManager();

                Animal animal = new Animal();
                if (animalModel.Id > 0)
                {
                    var x = subjectManager.Get(animalModel.Id).Self;
                    animal = x as Animal;
                }

                animal.Name           = animalModel.Name;
                animal.ScientificName = animalModel.ScientificName;
                animal.Rank           = animalModel.TaxonRank;
                animal.Description    = animalModel.Description;
                //TODO Generate the Parent based on the ScientificName
                // a a a = SubSpecies, a a = Species, a = Genus
                // a a var. a is also a species

                /* - based on the scientficname create or set the parents
                 * - use maybe some webservices to create missing one
                 *
                 */

                //Todo Select the type based on the scientific name
                //animal.Rank = Utility.GetTaxonRank(animal.ScientificName);

                if (!animalModel.ImagePath.Equals("/Images/Empty.png") && !animal.Medias.Where(m => m.ImagePath.Equals(animalModel.ImagePath)).Any())
                {
                    animal.Medias.Add(new Media()
                    {
                        ImagePath = animalModel.ImagePath,
                        MIMEType  = MimeMapping.GetMimeMapping(animalModel.ImagePath)
                    });
                }

                //lifecycles
                animal.TimePeriods = new List <TimePeriod>();
                foreach (var lifeCylce in animalModel.LifeCycles)
                {
                    lifeCylce.Reverse();
                    TimePeriod last = null;
                    foreach (var tpModel in lifeCylce)
                    {
                        TimePeriod tp = Utility.CreateTimePeriodFromModel(tpModel);
                        tp.AssignedTo = animal;

                        if (lifeCylce.Last().Equals(tpModel))
                        {
                            tp.Start = true;
                        }
                        if (last != null)
                        {
                            tp.Next = last;
                        }

                        animal.TimePeriods.Add(tp);

                        last = tp;
                    }

                    animal.TimePeriods.Reverse();
                }

                if (animal.Id == 0)
                {
                    animal = subjectManager.CreateAnimal(animal);
                }
                else
                {
                    subjectManager.Update(animal);
                    //animal.Parent = Utility.CreateOrSetParents(animal.ScientificName, typeof(Animal), subjectManager);
                    //subjectManager.Update(animal);
                }

                //set parent
                if (animalModel.Parent != null && animalModel.Parent.Id > 0)
                {
                    var parent = subjectManager.GetAll <Node>().Where(n => n.Id.Equals(animalModel.Parent.Id)).FirstOrDefault();
                    animal.Parent = parent;
                }
                else // delete parent from plant
                {
                    animal.Parent = null;
                }

                subjectManager.Update(animal);

                return(Json(animal.Id, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
Example #10
0
        public ActionResult SavePlant(PlantModel plantModel)
        {
            try
            {
                SubjectManager     subjectManager     = new SubjectManager();
                InteractionManager interactionManager = new InteractionManager();

                Plant plant = new Plant();
                if (plantModel.Id > 0)
                {
                    var x = subjectManager.Get(plantModel.Id).Self;
                    plant = x as Plant;
                }

                plant.Name           = plantModel.Name;
                plant.ScientificName = plantModel.ScientificName;

                //Todo Select the type based on the scientific name
                //plant.Rank = Utility.GetTaxonRank(plantModel.ScientificName);
                plant.Rank = plantModel.TaxonRank;

                #region after culture

                foreach (var ac in plantModel.AfterCultures)
                {
                    if (string.IsNullOrEmpty(ac.Name))
                    {
                        break;
                    }

                    Plant afterCultureTmp = null;

                    //add new culture to plant
                    if (ac.Id == 0)
                    {
                        afterCultureTmp = subjectManager.GetAllAsQueryable <Plant>().Where(p => p.Name.Equals(ac.Name)).FirstOrDefault();
                        if (afterCultureTmp != null)
                        {
                            plant.AfterCultures.Add(subjectManager.Get(afterCultureTmp.Id) as Plant);
                        }
                    }
                }

                //delete cultures
                List <string> nameOfDeleteAfterCultures = new List <string>();
                foreach (var ac in plant.AfterCultures)
                {
                    if (!plantModel.AfterCultures.Any(a => a.Name.Equals(ac.Name)))
                    {
                        nameOfDeleteAfterCultures.Add(ac.Name);
                    }
                }

                foreach (var name in nameOfDeleteAfterCultures)
                {
                    var tmp = plant.AfterCultures.Where(a => a.Name.Equals(name)).FirstOrDefault();
                    if (tmp != null)
                    {
                        plant.AfterCultures.Remove(tmp);
                    }
                }

                #endregion after culture

                #region preculture

                foreach (var pc in plantModel.PreCultures)
                {
                    if (string.IsNullOrEmpty(pc.Name))
                    {
                        break;
                    }

                    Plant preCultureTmp = null;;

                    //add new culture to plant
                    if (pc.Id == 0)
                    {
                        preCultureTmp = subjectManager.GetAllAsQueryable <Plant>().Where(p => p.Name.Equals(pc.Name)).FirstOrDefault();
                        if (preCultureTmp != null)
                        {
                            plant.PreCultures.Add(subjectManager.Get(preCultureTmp.Id) as Plant);
                        }
                    }
                }

                //delete cultures
                List <string> nameOfDeletePreCultures = new List <string>();
                foreach (var ac in plant.PreCultures)
                {
                    if (!plantModel.PreCultures.Any(a => a.Name.Equals(ac.Name)))
                    {
                        nameOfDeletePreCultures.Add(ac.Name);
                    }
                }

                foreach (var name in nameOfDeletePreCultures)
                {
                    var tmp = plant.PreCultures.Where(a => a.Name.Equals(name)).FirstOrDefault();
                    if (tmp != null)
                    {
                        plant.PreCultures.Remove(tmp);
                    }
                }

                #endregion preculture

                plant.Description  = plantModel.Description;
                plant.Height       = plantModel.Height;
                plant.LocationType = plantModel.LocationType;

                if (!plantModel.ImagePath.Equals("/Images/Empty.png") && !plant.Medias.Where(m => m.ImagePath.Equals(plantModel.ImagePath)).Any())
                {
                    plant.Medias.Add(new Media()
                    {
                        ImagePath = plantModel.ImagePath,
                        MIMEType  = MimeMapping.GetMimeMapping(plantModel.ImagePath)
                    });
                }

                plant.NutrientClaim = plantModel.NutrientClaim;
                plant.RootDepth     = plantModel.RootDepth;
                plant.SowingDepth   = plantModel.SowingDepth;
                plant.Width         = plantModel.Width;

                plant.TimePeriods = new List <TimePeriod>();

                foreach (var lifeCylce in plantModel.LifeCycles)
                {
                    lifeCylce.Reverse();
                    TimePeriod last = null;
                    foreach (var tpModel in lifeCylce)
                    {
                        TimePeriod tp = Utility.CreateTimePeriodFromModel(tpModel);
                        tp.AssignedTo = plant;

                        if (lifeCylce.Last().Equals(tpModel))
                        {
                            tp.Start = true;
                        }
                        if (last != null)
                        {
                            tp.Next = last;
                        }

                        plant.TimePeriods.Add(tp);

                        last = tp;
                    }

                    plant.TimePeriods.Reverse();
                }

                if (plantModel.Id == 0)
                {
                    plant = subjectManager.CreatePlant(plant);
                }
                else
                {
                    plant = subjectManager.UpdatePlant(plant);
                }

                //set parent
                if (plantModel.Parent != null && plantModel.Parent.Id > 0)
                {
                    var parent = subjectManager.GetAll <Node>().Where(n => n.Id.Equals(plantModel.Parent.Id)).FirstOrDefault();
                    plant.Parent = parent;
                }
                else // delete parent from plant
                {
                    plant.Parent = null;
                }

                subjectManager.Update(plant);

                return(Json(plant.Id, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
Example #11
0
        public static BreadcrumbModel ConvertTo(KeyValuePair <string, string> keyValuePair)
        {
            BreadcrumbModel model          = new BreadcrumbModel();
            SubjectManager  subjectManager = new SubjectManager();

            switch (keyValuePair.Key)
            {
            case "FREETEXT_SEARCH_KEY":
            {
                model.DisplayName  = "Sucheingabe";
                model.DisplayValue = keyValuePair.Value;
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            case "NutrientClaim":
            {
                NutrientClaim nc = (NutrientClaim)Convert.ToInt32(keyValuePair.Value);

                model.DisplayName  = "Nährstoffanspruch";
                model.DisplayValue = nc.GetAttribute <DisplayAttribute>().Name;
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            case "RootDepths":
            {
                RootDepth rd = (RootDepth)Convert.ToInt32(keyValuePair.Value);
                model.DisplayName  = "Wurzel-Tiefe";
                model.DisplayValue = rd.GetAttribute <DisplayAttribute>().Name;
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            case "Sowing":
            {
                model.DisplayName  = "Aussaat";
                model.DisplayValue = ((TimePeriodMonth)Convert.ToInt32(keyValuePair.Value)).ToString();
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            case "Harvest":
            {
                model.DisplayName  = "Ernten";
                model.DisplayValue = ((TimePeriodMonth)Convert.ToInt32(keyValuePair.Value)).ToString();
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            case "Bloom":
            {
                model.DisplayName  = "Blütezeit";
                model.DisplayValue = ((TimePeriodMonth)Convert.ToInt32(keyValuePair.Value)).ToString();
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            case "SeedMaturity":
            {
                model.DisplayName  = "Samenreife";
                model.DisplayValue = ((TimePeriodMonth)Convert.ToInt32(keyValuePair.Value)).ToString();
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            case "PositivInteractionOn":
            {
                string plantName = subjectManager.Get(Convert.ToInt64(keyValuePair.Value))?.Name;

                model.DisplayName  = "Positiven Effekt auf";
                model.DisplayValue = plantName;
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            case "NegativInteractionOn":
            {
                string plantName = subjectManager.Get(Convert.ToInt64(keyValuePair.Value))?.Name;

                model.DisplayName  = "Negativen Effekt auf";
                model.DisplayValue = plantName;
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            case "DoNegativInteraction":
            {
                string plantName = subjectManager.Get(Convert.ToInt64(keyValuePair.Value))?.Name;

                model.DisplayName  = "beeinflusst negativ";
                model.DisplayValue = plantName;
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            case "DoPositivInteraction":
            {
                string plantName = subjectManager.Get(Convert.ToInt64(keyValuePair.Value))?.Name;

                model.DisplayName  = "beeinflusst positiv";
                model.DisplayValue = plantName;
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }

            default:
            {
                model.DisplayName  = keyValuePair.Key;
                model.DisplayValue = keyValuePair.Value;
                model.Key          = keyValuePair.Key;
                model.Value        = keyValuePair.Value;
                break;
            }
            }

            return(model);
        }