示例#1
0
        public Item BuildPlant(string plantPart, PlantDetails details)
        {
            var item = new Item {
                Name = plantPart
            };

            switch (plantPart)
            {
            case "fruit":
                item.AddAspect(
                    new Ingestible(foodValue: 210)  //0.2: draw from data
                {
                    IsFruit = true,
                    PlantID = details.ID,
                });
                break;

            case "seed":
                item.AddAspect(
                    new Usable("plant", UseTargetFlags.Direction)
                    .AddEffect("plant", 1)      //0.1: add growth time and plant type
                    .AddCosts(("time", 6), ("energy", 5))
                    );
                break;

            default:
                throw new Exception($"Can't handle plant part [{plantPart}].");
            }

            item.AddAspect(new Plant(details));
            return(item);
        }
        public async Task <ActionResult <PlantDetailsViewModel> > CreatePlantDetails([FromForm] CreateEditPlantDetailsViewModel plantDetailsViewModel)
        {
            var plantDetails = new PlantDetails();

            GetChangesFromViewModel(plantDetails, plantDetailsViewModel);
            plantDetails.UserId = plantDetailsViewModel.UserId;

            if (!plantDetails.IsValid())
            {
                return(BadRequest());
            }

            if ((plantDetailsViewModel.ImageFile != null && !plantDetailsViewModel.ImageFile.IsValidImage()))
            {
                return(BadRequest(new { Message = $"Invalid image" }));
            }

            if (plantDetailsViewModel.ImageFile != null)
            {
                var plantImageViewModel = await _plantImageService.UploadImageAsync(plantDetailsViewModel.ImageFile);

                plantDetails.ImageName = plantImageViewModel.ImageName;
            }

            _context.PlantDetails.Add(plantDetails);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPlantDetails", new { id = plantDetails.PlantDetailsId }, MapToViewModel(plantDetails)));
        }
示例#3
0
        //This BuildPlantDetailsModel pulls in all the information about a plant and primarily pulls data from the PlantDetails
        //class. The properties that are not available in the PlantDetails class are pulled from the Plants class instead.
        private PlantDetailsModel BuildPlantDetailsModel(PlantDetails plantDetails)
        {
            PlantDetailsModel plantDetailsModel = new PlantDetailsModel
            {
                PlantID         = ctx.Plants.FirstOrDefault(z => z.PlantDetailsID == plantDetails.PlantDetailsID).PlantID,
                Name            = ctx.Plants.FirstOrDefault(z => z.PlantDetailsID == plantDetails.PlantDetailsID).Name,
                ScientificName  = ctx.Plants.FirstOrDefault(z => z.PlantDetailsID == plantDetails.PlantDetailsID).ScientificName,
                DaysToGerminate = plantDetails.DaysToGerminate,
                DaysToHarvest   = plantDetails.DaysToHarvest,
                SeedDepth       = plantDetails.SeedDepth,
                IsPerennial     = plantDetails.IsPerennial,
                PlantHeightMax  = plantDetails.PlantHeightMax,
                PlantWidthtMax  = plantDetails.PlantWidthMax,
                SeedSpacing     = plantDetails.SeedSpacing,
                RowSpacing      = plantDetails.RowSpacing,
                IsDeerResistant = plantDetails.IsDeerResistant,
                IsToxicToAnimal = plantDetails.IsToxicToAnimal,
                IsToxicToHuman  = plantDetails.IsToxicToHuman,
                IsMedicinal     = plantDetails.IsMedicinal,
                Image           = plantDetails.Image,
                Description     = plantDetails.Description,
                PlantTypes      = new PlantTypesModel {
                    Name = ctx.PlantTypes.FirstOrDefault(z => z.PlantTypeID == ctx.Plants.FirstOrDefault(r => r.PlantDetailsID == plantDetails.PlantDetailsID).PlantID).Name, Description = ctx.PlantTypes.FirstOrDefault(z => z.PlantTypeID == ctx.Plants.FirstOrDefault(r => r.PlantDetailsID == plantDetails.PlantDetailsID).PlantID).Description
                },
                PlantCare = new PlantCareModel {
                    Temperature = ctx.PlantCare.FirstOrDefault(z => z.PlantCareID == ctx.Plants.FirstOrDefault(r => r.PlantDetailsID == plantDetails.PlantDetailsID).PlantCareID).Temperature, Description = ctx.PlantCare.FirstOrDefault(z => z.PlantCareID == ctx.Plants.FirstOrDefault(r => r.PlantDetailsID == plantDetails.PlantDetailsID).PlantCareID).Description
                },
                PlantSeasons = new PlantSeasonsModel {
                    Name = ctx.PlantSeasons.FirstOrDefault(z => z.SeasonID == ctx.Plants.FirstOrDefault(r => r.PlantDetailsID == plantDetails.PlantDetailsID).SeasonID).Name, Description = ctx.PlantSeasons.FirstOrDefault(z => z.SeasonID == ctx.Plants.FirstOrDefault(r => r.PlantDetailsID == plantDetails.PlantDetailsID).SeasonID).Description
                },
                PlantZones = new PlantZonesModel {
                    ZoneCode = ctx.PlantZones.FirstOrDefault(z => z.ZoneID == ctx.Plants.FirstOrDefault(r => r.PlantDetailsID == plantDetails.PlantDetailsID).ZoneID).ZoneCode, Description = ctx.PlantZones.FirstOrDefault(z => z.ZoneID == ctx.Plants.FirstOrDefault(r => r.PlantDetailsID == plantDetails.PlantDetailsID).ZoneID).Description
                },
                SunExposures = new SunExposureModel
                {
                    Name        = ctx.SunExposures.FirstOrDefault(r => r.SunExposureID == ctx.PlantCare.FirstOrDefault(s => s.PlantCareID == ctx.Plants.FirstOrDefault(z => z.PlantDetailsID == plantDetails.PlantDetailsID).PlantCareID).SunExposureID).Name,
                    Description = ctx.SunExposures.FirstOrDefault(r => r.SunExposureID == ctx.PlantCare.FirstOrDefault(s => s.PlantCareID == ctx.Plants.FirstOrDefault(z => z.PlantDetailsID == plantDetails.PlantDetailsID).PlantCareID).SunExposureID).Description
                },


                WaterNeeds = new WaterNeedsModel
                {
                    Name        = ctx.WaterNeeds.FirstOrDefault(r => r.WaterNeedID == ctx.PlantCare.FirstOrDefault(s => s.PlantCareID == ctx.Plants.FirstOrDefault(z => z.PlantDetailsID == plantDetails.PlantDetailsID).PlantCareID).SunExposureID).Name,
                    Description = ctx.WaterNeeds.FirstOrDefault(r => r.WaterNeedID == ctx.PlantCare.FirstOrDefault(s => s.PlantCareID == ctx.Plants.FirstOrDefault(z => z.PlantDetailsID == plantDetails.PlantDetailsID).PlantCareID).SunExposureID).Description
                },
                RootStructure = new RootStructureModel
                {
                    Name        = ctx.RootStructure.FirstOrDefault(r => r.RootStructureID == ctx.PlantDetails.FirstOrDefault(z => z.PlantDetailsID == plantDetails.PlantDetailsID).RootStructureID).Name,
                    Description = ctx.RootStructure.FirstOrDefault(r => r.RootStructureID == ctx.PlantDetails.FirstOrDefault(z => z.PlantDetailsID == plantDetails.PlantDetailsID).RootStructureID).Description
                }
            };

            return(plantDetailsModel);
        }
        private void GetChangesFromViewModel(PlantDetails plantDetails, CreateEditPlantDetailsViewModel viewModel)
        {
            var category   = _context.PlantCategories.Where(c => EF.Functions.Like(c.Category, viewModel.Category ?? string.Empty)).FirstOrDefault();
            var weightUnit = _context.WeightUnits.Where(c => EF.Functions.Like(c.Unit, viewModel.Unit ?? string.Empty)).FirstOrDefault();

            plantDetails.Name        = viewModel.Name;
            plantDetails.Description = viewModel.Description;
            plantDetails.CategoryId  = category?.Id ?? -1;
            plantDetails.Price       = viewModel.Price;
            plantDetails.Weight      = viewModel.Weight;
            plantDetails.UnitId      = weightUnit?.Id ?? -1;
            plantDetails.Stock       = viewModel.Stock;
        }
示例#5
0
        private void EmitPlantDetails(IEmitter emitter, PlantDetails plantDetails)
        {
            emitter.StartNamedMapping("Plant");

            emitter.EmitKVP("ID", plantDetails.ID.ToString(CultureInfo.InvariantCulture));
            emitter.EmitKVP("MainName", plantDetails.MainName);
            emitter.EmitKVP("FruitAdjective", plantDetails.FruitAdjective);
            emitter.EmitKVP("FruitKnown", plantDetails.FruitKnown.ToString(CultureInfo.InvariantCulture));
            emitter.EmitKVP("SeedAdjective", plantDetails.SeedAdjective);
            emitter.EmitKVP("SeedKnown", plantDetails.SeedKnown.ToString(CultureInfo.InvariantCulture));
            emitter.EmitKVP("GrowthTime", plantDetails.GrowthTime.ToString(CultureInfo.InvariantCulture));

            emitter.EndMapping();
        }
示例#6
0
        //AddPlant builds a new plant based off AddPlantModel. The information is set to the properties in PlantCare and PlantDetails.
        public bool AddPlant(AddPlantModel model)
        {
            PlantCare plantCare = new PlantCare
            {
                SunExposureID = model.SunExposureID,
                WaterNeedID   = model.WaterNeedID,
                Temperature   = model.Temperature,
                Description   = model.PlantCareDescription,
                CreatedDate   = DateTimeOffset.UtcNow
            };

            ctx.PlantCare.Add(plantCare);

            PlantDetails plantDetails = new PlantDetails
            {
                DaysToGerminate = model.DaysToGerminate,
                DaysToHarvest   = model.DaysToHarvest,
                SeedDepth       = model.SeedDepth,
                IsPerennial     = model.IsPerennial,
                PlantHeightMax  = model.PlantHeightMax,
                PlantWidthMax   = model.PlantWidthMax,
                SeedSpacing     = model.SeedSpacing,
                RowSpacing      = model.RowSpacing,
                RootStructureID = model.RootStructureID,
                IsDeerResistant = model.IsDeerResistant,
                IsToxicToAnimal = model.IsToxicToAnimal,
                IsToxicToHuman  = model.IsToxicToHuman,
                IsMedicinal     = model.IsMedicinal,
                Image           = model.Image,
                Description     = model.PlantDetailsDescription,
                CreatedDate     = DateTimeOffset.UtcNow
            };

            ctx.PlantDetails.Add(plantDetails);
            ctx.SaveChanges();
            Plants newPlant = new Plants
            {
                Name           = model.Name,
                ScientificName = model.ScientificName,
                ZoneID         = model.ZoneID,
                SeasonID       = model.SeasonID,
                PlantTypeID    = model.PlantTypeID,
                PlantCareID    = plantCare.PlantCareID,
                PlantDetailsID = plantDetails.PlantDetailsID,
                CreatedDate    = DateTimeOffset.UtcNow
            };

            ctx.Plants.Add(newPlant);
            return(ctx.SaveChanges() == 1);
        }
示例#7
0
        private PlantDetails ParsePlantDetails(IParser parser)
        {
            parser.Consume <MappingStart>();
            var details = new PlantDetails();

            details.ID             = parser.GetKVP_uint("ID");
            details.MainName       = parser.GetKVP_string("MainName");
            details.FruitAdjective = parser.GetKVP_string("FruitAdjective");
            details.FruitKnown     = parser.GetKVP_bool("FruitKnown");
            details.SeedAdjective  = parser.GetKVP_string("SeedAdjective");
            details.SeedKnown      = parser.GetKVP_bool("SeedKnown");
            details.GrowthTime     = parser.GetKVP_int("GrowthTime");

            parser.Consume <MappingEnd>();
            return(details);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.CompanionPlantDetailView);

            var plantRepo = new CompanionPlantsRepository();

            var plantId = Intent.Extras.GetString("plantId");

            _plant = plantRepo.GetPlant(plantId);

            FindViews();
            BindData(_plant.Plant);
            HandleEvents();
        }
 private PlantDetailsViewModel MapToViewModel(PlantDetails plantDetails)
 {
     return(new PlantDetailsViewModel()
     {
         PlantDetailsId = plantDetails.PlantDetailsId,
         Name = plantDetails.Name,
         Description = plantDetails.Description,
         Category = _context.PlantCategories.Find(plantDetails.CategoryId)?.Category ?? string.Empty,
         Price = plantDetails.Price,
         Weight = plantDetails.Weight,
         Unit = _context.WeightUnits.Find(plantDetails.UnitId)?.Unit ?? string.Empty,
         Stock = plantDetails.Stock,
         ImageName = plantDetails.ImageName,
         ImageUri = _plantImageService.GetPlantImageUri(plantDetails.ImageName),
         UserId = plantDetails.UserId
     });
 }
示例#10
0
        public void CanRT_Herbal()
        {
            //if (!Debugger.IsAttached) Debugger.Launch();

            var herbal = new Herbal();
            var thorny = new PlantDetails
            {
                ID             = 77,
                MainName       = "Thornfriend",
                FruitAdjective = "Luminous",
                FruitKnown     = true,
                SeedAdjective  = "Knobbly",
                SeedKnown      = true,
                GrowthTime     = 234,
            };

            var boomy = new PlantDetails
            {
                ID             = 88,
                MainName       = "Boomer",
                FruitAdjective = "Singed",
                FruitKnown     = false,
                SeedAdjective  = "Dark",
                SeedKnown      = false,
                GrowthTime     = 432,
            };

            herbal.AddPlant(thorny);
            herbal.AddPlant(boomy);

            var yaml = _serializer.Serialize(herbal);

            Assert.That(yaml, Is.Not.Null);

            var newBook = _deserializer.Deserialize <IBook>(yaml);

            Assert.That(newBook, Is.TypeOf <Herbal>());
            var newHerbal = (Herbal)newBook;

            var newDetail = newHerbal.PlantByID[77];

            Assert.That(newDetail.MainName, Is.EqualTo("Thornfriend"));
        }
示例#11
0
        public Herbal Herbal_FromNew()
        {
            Herbal herbal = new Herbal();

            herbal.PlantByID   = new Dictionary <uint, PlantDetails>();
            herbal.PlantByName = new Dictionary <string, PlantDetails>();

            PlantDetails plant;

            //0.1.WORLD  Flesh out the plant list, and tuck it into YAML config.
            plant = new PlantDetails
            {
                ID         = 1,
                MainName   = "Boomer",
                GrowthTime = 400,
            };
            herbal.PlantByID[plant.ID]         = plant;
            herbal.PlantByName[plant.MainName] = plant;

            plant = new PlantDetails
            {
                ID         = 2,
                MainName   = "Healer",
                GrowthTime = 400,
            };
            herbal.PlantByID[plant.ID]         = plant;
            herbal.PlantByName[plant.MainName] = plant;

            plant = new PlantDetails
            {
                ID         = 3,
                MainName   = "Thornfriend",
                GrowthTime = 400,
            };
            herbal.PlantByID[plant.ID]         = plant;
            herbal.PlantByName[plant.MainName] = plant;

            return(herbal);
        }
        public ActionResult GetControlPlanIntervalByPlantId(string plantId)
        {
            string date = DateTime.Now.ToString("MM/dd/yyyy");

            try
            {
                var          controlPlan  = controlPlanCollection.AsQueryable <ControlPlanModel>().SingleOrDefault(x => x.PlantId == plantId);
                var          interval     = controlPlan.Intervals.AsQueryable <Intervals>().SingleOrDefault(x => x.date == date);
                PlantDetails plantDetails = new PlantDetails()
                {
                    Control_plan             = interval,
                    Frequency_of_measurement = controlPlan.Frequency_of_measurement,
                    Frequency_of_upload      = controlPlan.Frequency_of_upload
                };
                return(Content(JsonConvert.SerializeObject(plantDetails)));
            }

            catch (Exception e)
            {
                return(Content(JsonConvert.SerializeObject(e.Message)));
            }
        }
示例#13
0
 public void AddPlant(PlantDetails plant)
 {
     PlantByID[plant.ID]         = plant;
     PlantByName[plant.MainName] = plant;
 }
        public ActionResult GetIntervalsByDate(string id)
        {
            string date = DateTime.Now.ToString("M/dd/yyyy");

            try
            {
                var plant = plantCollection.AsQueryable <PlantModel>().SingleOrDefault(x => x.Id == ObjectId.Parse(id));

                var researchCollection = dBContext.database.GetCollection <ResearchModel>("Research");
                var research           = researchCollection.AsQueryable <ResearchModel>().SingleOrDefault(x => x.Id == ObjectId.Parse(plant.ResearchId));

                if (research.Status.Equals("Running"))
                {
                    DateTime end_date = Convert.ToDateTime(research.End_date);
                    DateTime now      = Convert.ToDateTime(date);

                    //checking if we rich the end_date
                    if (end_date.CompareTo(now) == -1)
                    {
                        // update research status to "complete"
                        var filter = Builders <ResearchModel> .Filter.Eq("_id", research.Id);

                        var update = Builders <ResearchModel> .Update
                                     .Set("Status", "Complete");

                        var result = researchCollection.UpdateOne(filter, update);

                        var filter1 = Builders <PlantModel> .Filter.Eq("ResearchId", research.Id);

                        var update1 = Builders <PlantModel> .Update
                                      .Set("Status", "Complete");

                        plantCollection.UpdateMany(filter1, update1);

                        return(Content(JsonConvert.SerializeObject("stop")));
                    }

                    else
                    {
                        var controlPlanCollection = dBContext.database.GetCollection <ControlPlanModel>("ControlPlan");
                        var controlPlan           = controlPlanCollection.AsQueryable <ControlPlanModel>().SingleOrDefault(x => x.PlantId == id);

                        //checking the plant status if still running
                        if (plant.Status.Equals("Running"))
                        {
                            Intervals interval = new Intervals();
                            interval = controlPlan.Intervals.AsQueryable <Intervals>().SingleOrDefault(x => x.date == date);
                            PlantDetails plantDetails = new PlantDetails()
                            {
                                Control_plan             = interval,
                                Frequency_of_measurement = plant.Frequency_of_measurement,
                                Frequency_of_upload      = plant.Frequency_of_upload
                            };
                            return(Content(JsonConvert.SerializeObject(plantDetails)));
                        }
                    }
                }

                // plant status not "Running" - return "stop"
                else if (plant.Status.Equals("Cancel") || plant.Status.Equals("Stop") || plant.Status.Equals("Complete"))
                {
                    return(Content(JsonConvert.SerializeObject("stop")));
                }

                return(null);
            }

            catch (Exception e)
            {
                return(Content(JsonConvert.SerializeObject(e.Message)));
            }
        }