示例#1
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);
        }
示例#2
0
        // UpdatePlant takes in the plantID of the plant you would like to update and the new information you want updated. The values must be within the set
        // values of the variables (SeasonID between 1-4, etc.).
        public bool UpdatePlant(int plantID, UpdatePlantModel model)
        {
            int       plantCareID = ctx.Plants.Single(e => e.PlantID == plantID).PlantCareID;
            PlantCare plantCare   = ctx.PlantCare.FirstOrDefault(e => e.PlantCareID == plantCareID);


            plantCare.SunExposureID = model.SunExposureID;
            plantCare.WaterNeedID   = model.WaterNeedID;
            plantCare.Temperature   = model.Temperature;
            plantCare.Description   = model.Description;
            plantCare.ModifiedDate  = DateTimeOffset.UtcNow;



            Plants plants = ctx.Plants.Single(e => e.PlantID == plantID);

            plants.Name           = model.Name;
            plants.ScientificName = model.ScientificName;
            plants.ZoneID         = model.ZoneID;
            plants.SeasonID       = model.SeasonID;
            plants.PlantTypeID    = model.PlantTypeID;
            plants.ModifiedDate   = DateTimeOffset.UtcNow;
            return(ctx.SaveChanges() == 2);
        }