Ejemplo n.º 1
0
        /// <summary>
        /// Get a dictionary with keys and count from the system
        /// Plants, Animals, Interactions, Beete, User
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, int> GetStatistics()
        {
            Dictionary <string, int> tmp                = new Dictionary <string, int>();
            SubjectManager           subjectManager     = new SubjectManager();
            InteractionManager       interactionManager = new InteractionManager();
            PatchManager             patchManager       = new PatchManager();

            int plantsCount  = subjectManager.GetAll <Plant>().Length;
            int animalsCount = subjectManager.GetAll <Animal>().Length;
            int actionsCount = interactionManager.GetAll <Interaction>().Length;
            int patchesCount = patchManager.GetAll <Patch>().Length;
            int usersCount   = 0;

            int varietiesPlantCount = subjectManager.GetAll <Plant>().Where(p => p.Rank.Equals(TaxonRank.SubSpecies)).Count();
            int animalSpeciesCount  = subjectManager.GetAll <Animal>().Where(p => p.Rank.Equals(TaxonRank.Species)).Count();


            tmp.Add("Pflanzen", plantsCount);
            tmp.Add("Sorten", varietiesPlantCount);
            tmp.Add("Tiere", animalsCount);
            tmp.Add("TierArten", animalSpeciesCount);
            tmp.Add("Interaktionen", actionsCount);
            tmp.Add("Gärten", patchesCount);
            tmp.Add("Nutzer", usersCount);

            return(tmp);
        }
Ejemplo n.º 2
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"));;
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        private TreeElement GetTreeElement(Node node)
        {
            SubjectManager subjectManager = new SubjectManager();


            if (node != null)
            {
                TreeElement tmp = new TreeElement();

                tmp.id   = node.Id;
                tmp.name = node.Name;

                var children = subjectManager.GetAll <Node>().Where(c => c.Parent != null && c.Parent.Id.Equals(node.Id));
                if (children != null)
                {
                    foreach (var child in children)
                    {
                        tmp.children.Add(GetTreeElement(child));
                    }
                }

                return(tmp);
            }

            return(null);
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
        private void testIntractions()
        {
            SubjectManager subjectManager = new SubjectManager();


            Subject subject = new Subject();

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

            Subject Object = new Subject();

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

            Predicate positive =
                subjectManager.GetAll <Predicate>().Where(p => p.Name.ToLower().Equals("positiv")).FirstOrDefault();

            Predicate predicate = new Predicate();

            predicate.Parent = positive;
            predicate.Name   = "X";

            InteractionManager interactionManager = new InteractionManager();
            Interaction        interaction        = new Interaction();

            interaction.Subject   = subject;
            interaction.Object    = Object;
            interaction.Predicate = predicate;

            interactionManager.Create(interaction);
            interactionManager.Delete(interaction);
        }
Ejemplo n.º 7
0
        public ActionResult Search(bool reset = false)
        {
            //ToDo think about setting sessions, is this the rigth place ?
            //load all names in session

            getAllNames();

            if (reset)
            {
                ResetSearchProvider();
            }

            SearchProvider sp             = GetSearchProvider();
            SubjectManager subjectManager = new SubjectManager();

            //Get all subjects
            var subjects = subjectManager.GetAll <Subject>();

            SearchModel Model = new SearchModel(subjects.ToList().OrderBy(s => s.Name).ToList());

            SearchManager searchManager = new SearchManager();

            var species = searchManager.Search(sp.SearchCriterias);

            if (species != null)
            {
                //convert all subjects to subjectModels
                species = species.OrderBy(p => p.Name);
                species.ToList().ForEach(s => Model.Species.Add(NodeModel.Convert(s)));
            }

            Model.SearchCriterias = sp.SearchCriterias;

            return(View("Search", Model));
        }
Ejemplo n.º 8
0
        private IQueryable <Species> searchTimeFilter(string key, string value)
        {
            switch (key)
            {
            case "Sowing":
            {
                IEnumerable <Sowing> sowingMatchesList =
                    _manager.GetAll <Sowing>().Where(s => s.EndMonth.ToString().Equals(value) || s.StartMonth.ToString().Equals(value)).ToList();

                if (sowingMatchesList.Any())
                {
                    var plants = from plant in _manager.GetAllAsQueryable <Plant>()
                                 where plant.TimePeriods.Any(s => sowingMatchesList.Select(e => e.Id.Equals(s.Id) && s is Sowing).Any())
                                 select plant;

                    return(plants.AsQueryable());
                }

                break;
            }

            default:
            {
                return(null);
            }
            }

            return(null);
        }
Ejemplo n.º 9
0
 public IActionResult AddG(GradeModel model)
 {
     if (ModelState.IsValid)
     {
         var student = StudentManager.GetAll().FirstOrDefault(c => c.Name == model.StudentName && c.Surname == model.StudentSurname);
         var subject = SubjectManager.GetAll().FirstOrDefault(c => c.Name == model.SubjectName);
         //model.Subject = SubjectController.Subjects.Find(s => s.Name == model.SubjectName);
         //model.Student = StudentController.Students.Find(s => s.Name == model.StudentName && s.Surname == model.StudentSurname);
         if (student == null)
         {
             ModelState.AddModelError("stu", "Skolnieks nav atrasts!");
         }
         else if (subject == null)
         {
             ModelState.AddModelError("sub", "Priekšmets nav atrasts!");
         }
         else if (model.Grade < 1 || model.Grade > 10)
         {
             ModelState.AddModelError("gra", "Atzīmei jābūt intervālā no 1 līdz 10!");
         }
         else
         {
             GradeManager.Create(model.Grade, model.Comment, student.Id, subject.Id);
             return(RedirectToAction(nameof(IndexG)));
         }
     }
     return(View(model));
 }
Ejemplo n.º 10
0
        public ActionResult AddPlant(long id, long patchId)
        {
            try
            {
                PatchManager patchManager = new PatchManager();
                Patch        patch        = patchManager.Get(patchId);

                SubjectManager subjectManager = new SubjectManager();

                long plantId = id;

                Plant p = subjectManager.GetAll <Plant>().Where(x => x.Id.Equals(plantId)).FirstOrDefault();

                Placement placement = new Placement();
                placement.Plant = p;
                placement.Patch = patch;

                PlacementModel model = PatchModelHelper.ConvertTo(placement);

                return(PartialView("Placement", model));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 11
0
        private Node LoadParent(Node node, SubjectManager subjectManager)
        {
            if (node.Parent != null)
            {
                LoadParent(node.Parent, subjectManager);
            }

            return(subjectManager.GetAll <Node>().Where(n => n.Id.Equals(node.Id)).FirstOrDefault());
        }
Ejemplo n.º 12
0
        private static Species GetOrCreateSpecies(string speciesName, Type type, SubjectManager subjectManager, Taxon genus)
        {
            WikipediaReader wReader = new WikipediaReader();

            Species species = new Species();

            if (type.Equals(typeof(Plant)))
            {
                species = new Plant();

                if (subjectManager.GetAll <Species>().Any(s => s.ScientificName.Equals(speciesName)))
                {
                    species = subjectManager.GetAll <Plant>().FirstOrDefault(s => s.ScientificName.Equals(speciesName));
                }
                else
                {
                    species.ScientificName = speciesName;
                    species.Name           = wReader.GetName(speciesName);
                    species.Parent         = genus;
                    species.Rank           = TaxonRank.Species;
                    subjectManager.Create(species);
                }
            }
            else if (type.Equals(typeof(Animal)))
            {
                species = new Animal();

                if (subjectManager.GetAll <Species>().Any(s => s.ScientificName.Equals(speciesName)))
                {
                    species = subjectManager.GetAll <Animal>().FirstOrDefault(s => s.ScientificName.Equals(speciesName));
                }
                else
                {
                    species.ScientificName = speciesName;
                    species.Name           = wReader.GetName(speciesName);
                    species.Parent         = genus;
                    species.Rank           = TaxonRank.Species;
                    subjectManager.Create(species);
                }
            }

            return(species);
        }
Ejemplo n.º 13
0
        // GET api/<controller>/5
        public AnimalModel Get(int id)
        {
            SubjectManager manager = new SubjectManager();
            var            animal  = manager.GetAll <Animal>().Where(p => p.Id.Equals(id)).FirstOrDefault();

            AnimalModel model = AnimalModel.Convert(animal);

            model.Interactions = AnimalModel.ConverInteractionModels(manager.GetAllDependingInteractions(animal, true).ToList());

            return(model);
        }
Ejemplo n.º 14
0
        public ActionResult CheckNameOfSimpleLink(string name)
        {
            SubjectManager subjectManager = new SubjectManager();

            if (subjectManager.GetAll <Node>().Any(n => n.Name.Equals(name)))
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 15
0
        public ActionResult CheckImpactSubject(string impactSubject)
        {
            SubjectManager subjectManager = new SubjectManager();

            if (subjectManager.GetAll <Subject>().Any(n => n.Name.Equals(impactSubject)))
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 16
0
        // GET: Predicate
        public ActionResult Index()
        {
            SubjectManager        subjectManager = new SubjectManager();
            List <PredicateModel> Model          = new List <PredicateModel>();

            var predicates = subjectManager.GetAll <Predicate>();

            predicates.ToList().ForEach(p => Model.Add(PredicateModel.Convert(p)));

            return(View(Model));
        }
Ejemplo n.º 17
0
        public ActionResult CheckPredicate(string predicate)
        {
            SubjectManager subjectManager = new SubjectManager();

            if (subjectManager.GetAll <Predicate>().Any(n => n.Name.Equals(predicate)))
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 18
0
        // GET api/<controller>
        public List <NodeModel> Get()
        {
            List <NodeModel> list = new List <NodeModel>();

            SubjectManager manager = new SubjectManager();
            var            species = manager.GetAll <Species>();

            species.OrderBy(s => s.Name).ToList().ForEach(n => list.Add(NodeModel.Convert(n)));


            return(list);
        }
Ejemplo n.º 19
0
        // GET api/<controller>
        public List <PlantModel> Get()
        {
            List <PlantModel> list = new List <PlantModel>();

            SubjectManager manager = new SubjectManager();
            var            plants  = manager.GetAll <Plant>();

            plants.ToList().ForEach(n => list.Add(PlantModel.Convert(n)));


            return(list);
        }
Ejemplo n.º 20
0
        // GET api/<controller>/5
        public PlantModel Get(int id)
        {
            SubjectManager manager = new SubjectManager();
            var            plant   = manager.GetAll <Plant>().Where(p => p.Id.Equals(id)).FirstOrDefault();

            PlantModel model = PlantModel.Convert(plant);

            model.Interactions = PlantModel.ConverInteractionModels(manager.GetAllDependingInteractions(plant, true).ToList());


            return(model);
        }
Ejemplo n.º 21
0
        // GET api/<controller>
        public List <AnimalModel> Get()
        {
            List <AnimalModel> list = new List <AnimalModel>();

            SubjectManager manager = new SubjectManager();
            var            animals = manager.GetAll <Animal>();

            animals.ToList().ForEach(n => list.Add(AnimalModel.Convert(n)));


            return(list);
        }
Ejemplo n.º 22
0
        // GET: Data
        public ActionResult Index()
        {
            DataModel model = new DataModel();

            SubjectManager manager = new SubjectManager();

            //model.Species = DataModelHelper.ToDataTable<Species>(manager.GetAll<Species>());

            List <PlantModel> lPLants = new List <PlantModel>();

            manager.GetAll <Plant>().ToList().ForEach(p => lPLants.Add(PlantModel.Convert(p)));
            model.Plants = DataModelHelper.ToDataTable <PlantModel>(lPLants);
            return(View(model));
        }
Ejemplo n.º 23
0
        private static Taxon GetOrCreateGenus(string genusName, SubjectManager subjectManager)
        {
            WikipediaReader wReader = new WikipediaReader();

            Taxon genus = new Taxon();

            if (subjectManager.GetAll <Taxon>().Any(s => s.ScientificName.Equals(genusName)))
            {
                genus = subjectManager.GetAll <Taxon>().FirstOrDefault(s => s.ScientificName.Equals(genusName));

                if (string.IsNullOrEmpty(genus.Name) && !string.IsNullOrEmpty(genus.ScientificName))
                {
                    genus.Name = wReader.GetName(genus.ScientificName);
                }

                if (string.IsNullOrEmpty(genus.ScientificName) && !string.IsNullOrEmpty(genus.Name))
                {
                    genus.ScientificName = wReader.GetScientificName(genus.Name);
                }
            }
            else
            {
                genus.ScientificName = genusName;
                genus.Name           = wReader.GetName(genusName);

                if (String.IsNullOrEmpty(genus.Name))
                {
                    genus.Name = genusName;
                }

                genus.Rank = TaxonRank.Genus;

                subjectManager.Create(genus);
            }

            return(genus);
        }
Ejemplo n.º 24
0
        public JsonResult GetEvents()
        {
            SubjectManager subjectmanager = new SubjectManager();

            var events = new List <object>();

            foreach (var VARIABLE in subjectmanager.GetAll <TimePeriod>())
            {
                if (VARIABLE != null)
                {
                    events.Add(getEventFromTimeperiod(VARIABLE));
                }
            }

            return(Json(events.ToArray(), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 25
0
        public JsonResult GetEventsForGantt()
        {
            SubjectManager subjectmanager = new SubjectManager();

            var events = new List <object>();

            foreach (var plant in subjectmanager.GetAll <Plant>().ToList().OrderBy(p => p.Name))
            {
                if (plant != null)
                {
                    events.AddRange(GantHelper.GetAllEventsFromSubject(plant));
                }
            }

            return(Json(events.ToArray(), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 26
0
        public static Placement ConvertTo(PlacementJsonModel placementJsonModel)
        {
            Placement placement = new Placement();

            placement.Transformation = placementJsonModel.Transformation;

            SubjectManager subjectManager = new SubjectManager();

            placement.Plant = subjectManager.GetAll <Plant>().Where(p => p.Id.Equals(placementJsonModel.PlantId)).FirstOrDefault();

            PatchManager patchManager = new PatchManager();

            placement.Patch = patchManager.Get(placementJsonModel.PatchId);


            return(placement);
        }
Ejemplo n.º 27
0
        public ActionResult CheckScientificNameExist(string scientificName, string initScientificName)
        {
            SubjectManager subjectManager = new SubjectManager();
            string         defaultstring  = "";

            if (!String.IsNullOrEmpty(initScientificName))
            {
                defaultstring = initScientificName;
            }

            if (subjectManager.GetAll <Node>().Any(n => n.ScientificName != null && n.ScientificName.Equals(scientificName) && !n.ScientificName.Equals(defaultstring)))
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 28
0
        private List <string> getAllPredicateNames()
        {
            if (Session[ALL_PREDICATES] == null)
            {
                SubjectManager subjectManager = new SubjectManager();

                //ToDo change the position of load this
                //load Viewdata
                // load all subject for autocomplete
                Session[ALL_PREDICATES] = subjectManager.GetAll <Predicate>().Select(s => s.Name);
                //Session[ALL_PREDICATES] = subjectManager.GetAll<Predicate>().Select(s => s.Name);
            }

            List <string> tmp = Session[ALL_PREDICATES] as List <string>;

            return(tmp);
        }
Ejemplo n.º 29
0
        private List <string> getAllScientficNames()
        {
            if (Session[ALL_SCIENTIFIC_NAMES] == null)
            {
                SubjectManager subjectManager = new SubjectManager();

                //ToDo change the position of load this
                //load Viewdata
                // load all subject for autocomplete
                Session[ALL_SCIENTIFIC_NAMES] = subjectManager.GetAll <Species>().Select(s => s.ScientificName).ToList();
                //Session[ALL_PREDICATES] = subjectManager.GetAll<Predicate>().Select(s => s.Name);
            }

            List <string> tmp = Session[ALL_SCIENTIFIC_NAMES] as List <string>;

            tmp.Sort();
            return(tmp);
        }
Ejemplo n.º 30
0
 public static GradeModel ToModel(this GradesDb gra)
 {
     return(new GradeModel()
     {
         StudentName = StudentManager.GetAll().FirstOrDefault(c => c.Id == gra.StudentId).Name,
         StudentSurname = StudentManager.GetAll().FirstOrDefault(c => c.Id == gra.StudentId).Surname,
         SubjectName = SubjectManager.GetAll().FirstOrDefault(c => c.Id == gra.SubjectId).Name,
         OGradeId = gra.Id,
         Grade = gra.Grade,
         Comment = gra.Comment,
         Subject = new SubjectModel()
         {
             OSubjectId = gra.SubjectId,
         },
         Student = new StudentModel()
         {
             OStudentId = gra.StudentId,
         },
     });
 }