public IActionResult Update(int id, [FromBody] UserPlantUpdateViewModel model) { UserPlant plant = _plantData.Get(id); if (plant == null) { return(NotFound()); } if (!ModelState.IsValid) { return(UnprocessableEntity(new ValidationErrorModel(ModelState))); } PlantType plantType = _plantData.GetPlantType(model.TypeID); plant.NickName = model.NickName; plant.WherePurchased = model.WherePurchased; plant.PlantType = plantType; plant.ReceiveNotifications = model.ReceiveNotifications; plant.IsFavorite = model.IsFavorite; plant.PrimaryImageID = model.PrimaryImageID; UserPlantDisplayViewModel updated = new UserPlantDisplayViewModel(plant); _plantData.Update(plant); _plantData.Commit(); return(Ok(updated)); }
public IActionResult Update(int id, [FromBody] PlantTypeUpdateViewModel model) { PlantType plant = _plantData.GetPlantType(id); if (plant == null) { return(NotFound()); } if (!ModelState.IsValid) { return(UnprocessableEntity(new ValidationErrorModel(ModelState))); } PlantType plantType = _plantData.GetPlantType(model.PlantTypeID); plant.LatinName = model.LatinName.Trim(); plant.CommonName = model.CommonName.Trim(); plant.StockImageID = model.StockImageID; plant.Description = model.Description; plant.Difficulty = model.Difficulty; plant.HumidityLowLevel = model.HumidityLowLevel; plant.HumidityHighLevel = model.HumidityHighLevel; plant.LightLevel = model.LightLevel; plant.LightTime = model.LightTime; plant.SoilPh = model.SoilPh; plant.FertilizerFrequency = model.FertilizerFrequency; plant.FertalizerType = model.FertalizerType; plant.WateringFrequency = model.WateringFrequency; plant.WaterType = model.WaterType; plant.ToxicToCats = model.ToxicToCats; plant.ToxicToDogs = model.ToxicToDogs; plant.ToxicToSmallAnimals = model.ToxicToSmallAnimals; plant.ScienceKingdom = (model.ScienceKingdom ?? "").Trim(); plant.ScienceClade1 = (model.ScienceClade1 ?? "").Trim(); plant.ScienceClade2 = (model.ScienceClade2 ?? "").Trim(); plant.ScienceClade3 = (model.ScienceClade3 ?? "").Trim(); plant.ScienceOrder = (model.ScienceOrder ?? "").Trim(); plant.ScienceFamily = (model.ScienceFamily ?? "").Trim(); plant.ScienceSubfamily = (model.ScienceSubfamily ?? "").Trim(); plant.ScienceGenus = model.ScienceGenus.Trim(); PlantTypeDisplayViewModel updated = new PlantTypeDisplayViewModel(plant); _plantData.Update(plant); _plantData.Commit(); return(Ok(updated)); }