public async Task <PlantResponse> GetAllPlants() { var result = await _plantsRepository.GetAll(); PlantResponse plantResponse = new PlantResponse(); plantResponse.plants = new List <PlantRow>(); foreach (var item in result) { PlantRow plantRow = new PlantRow(); item.CopyPropertiesTo(plantRow); TimeSpan timeSpan = DateTime.Now - item.LastWateringDate; if (timeSpan.TotalHours >= 6) { plantRow.plantsStatus = PlantsStatus.ReadyToWattering; plantRow.statusName = PlantsStatus.ReadyToWattering.ToString(); } else { plantRow.plantsStatus = PlantsStatus.Watered; plantRow.statusName = PlantsStatus.Watered.ToString(); } plantResponse.plants.Add(plantRow); } plantResponse.ResultCount = plantResponse.plants.Count; plantResponse.ToSuccess <PlantResponse>(); return(plantResponse); }
public IActionResult Create([FromBody] CreatePlantRequest newPlant) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var plant = _plants.Create(newPlant); var url = Url.Action("GetById", new { id = plant.PlantId }); var responseViewModel = new PlantResponse(plant); return(Created(url, responseViewModel)); }
public async Task <PlantResponse> GetAllPlants() { PlantResponse plantResponse = await _plantsService.GetAllPlants(); return(plantResponse); }