public IActionResult WaterPlants([FromBody] UserPlantUpdateModel model) { if (!ModelState.IsValid) { return(UnprocessableEntity(new ValidationErrorModel(ModelState))); } List <UserPlant> plantList = _plantData.Get(model.PlantIdArray).ToList(); if (plantList == null) { return(NotFound()); } foreach (UserPlant plant in plantList) { // TODO: add error handling. //desired behavior is that if one fails, the commit does not run plant.LastWatered = model.TimeStamp; plant.WaterAgain = GetNextWater( model.TimeStamp, plant.PlantType); _plantData.Update(plant); } IEnumerable <UserPlantDisplayViewModel> models = plantList.Select(p => new UserPlantDisplayViewModel(p)); _plantData.Commit(); return(Ok(models)); }
public IActionResult FeedPlants([FromBody] UserPlantUpdateModel model) { if (!ModelState.IsValid) { return(UnprocessableEntity(new ValidationErrorModel(ModelState))); } List <UserPlant> plantList = _plantData.Get(model.PlantIdArray).ToList(); if (plantList == null) { return(NotFound()); } foreach (UserPlant plant in plantList) { plant.LastFertalized = model.TimeStamp; plant.FertalizeAgain = GetNextFeed( model.TimeStamp, plant.PlantType); _plantData.Update(plant); } IEnumerable <UserPlantDisplayViewModel> models = plantList.Select(p => new UserPlantDisplayViewModel(p)); _plantData.Commit(); return(Ok(models)); }