Exemplo n.º 1
0
        private void SetParentTest()
        {
            SubjectManager subjectManager = new SubjectManager();

            var a = subjectManager.GetAll <Plant>().FirstOrDefault(s => s.Id == 299);
            var b = subjectManager.GetAll <Node>().FirstOrDefault(s => s.Id == 240);

            a.Parent = b;

            subjectManager.Update(a);
            a.Parent = null;
            subjectManager.Update(a);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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));
            }
        }
Exemplo n.º 6
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));
            }
        }