public IActionResult Create([FromBody] CultivationComment cultivationComment)
 {
     if (cultivationComment.text == null || cultivationComment.cultivation == null)
     {
         return(BadRequest());
     }
     else
     {
         CultivationComment newCultivationComment = CultivationComment.AddCultivationComents(cultivationComment.text, cultivationComment.cultivation);
         if (newCultivationComment.text.Equals(cultivationComment.text))
         {
             return(CreatedAtRoute("GetCultivationComment", new { newCultivationComment.id }, newCultivationComment));
         }
     }
     return(BadRequest());
 }
Пример #2
0
        public IActionResult PrepareDataBase(bool prepare)
        {
            ClearDataBase();

            if (prepare)
            {
                Random gen = new Random();

                List <string> plantsNames = new List <string>();
                plantsNames.Add("Awokado");
                plantsNames.Add("Lychee");
                plantsNames.Add("Cytryna");
                plantsNames.Add("Pomarańcza");
                plantsNames.Add("Mango");

                foreach (string plantName in plantsNames)
                {
                    int newPlantId = Plant.CreatePlant(plantName).id;

                    for (int i = 0; i < 5; i++)
                    {
                        Variety.CreateVariety(PlantSpecies.GetPlantSpeciesByName(plantName).id, $"Odmiana {i}");
                    }
                }

                for (int i = 0; i < 4; i++)
                {
                    int id = Tunnel.CreateTunnel($"Tunnel {i}").id;
                    AvrDevice.CreateAvrDevice($"localhost/espSim/{i + 10}", id);

                    for (int j = 0; j < gen.Next(1, 6); j++)
                    {
                        List <Plant> plants          = Plant.GetPlants();
                        int          plantTableIndex = gen.Next(0, plants.Count - 1);


                        int breedingId = Cultivation.CreateCultivation($"Hodowla {i}/{j}", plants[plantTableIndex].id, i + i * j + 1, id, DateTime.Now).id;
                        for (int k = 0; k < gen.Next(0, 10); k++)
                        {
                            CultivationComment.AddCultivationComents($"Komentarz do hodowli { i + i * j * k}", breedingId);
                        }
                    }
                }
            }

            return(new NoContentResult());
        }