public async Task <Guid> Create(Guid plantId, CreateAdministeredNutrientModel model) { Plant plant = await _database.Plants.FindAsync(plantId); if (plant is null) { throw new PlantNotFoundException(plantId); } Nutrient nutrient = await _database.Nutrients.FindAsync(model.NutrientId); if (nutrient is null) { throw new NutrientNotFoundException(model.NutrientId); } if (model.Date < plant.Planted) { throw new NutrientAdministrationDateBeforePlantDateException(); } AdministeredNutrient administeredNutrient = plant.AdministerNutrient(nutrient, model.Amount, model.Date, model.CreateEvent); _database.Plants.Update(plant); await _database.SaveAsync(); return(administeredNutrient.Id); }
public static AdministeredNutrient DomainModel(Nutrient nutrient = null, Plant plant = null, DateTime?date = null, bool createEvent = false) { Plant nutritionedPlant = plant ?? Plants.ModelFactory.DomainModel(); return(nutritionedPlant.AdministerNutrient( nutrient ?? Tests.Nutrients.ModelFactory.DomainModel(), 1.0, date ?? DateTime.Now, createEvent)); }
protected override AdministeredNutrient CreateDomainObject() => _nutritionedPlant.AdministerNutrient(_nutrient, 1.0, DateTime.Now);