public async Task <Models.Products.Fertilizer> Create(FertilizerForCreate newFertilizer) { var fertilizer = new Models.Products.Fertilizer { Name = newFertilizer.Name, Description = newFertilizer.Description, ImageUrl = newFertilizer.ImageUrl, ProductType = "fertilizer", CoverageArea = newFertilizer.CoverageArea, CoverageAreaUnitOfMeasure = newFertilizer.CoverageAreaUnitOfMeasure, PackageSize = newFertilizer.PackageSize, PackageSizeUnitOfMeasure = newFertilizer.PackageSizeUnitOfMeasure, CompatibleGrassTypes = newFertilizer.CompatibleGrassTypes, ConditionOfLawn = newFertilizer.ConditionOfLawn, Features = newFertilizer.Features, LongevityInWeeks = newFertilizer.LongevityInWeeks, PercentNitrogen = newFertilizer.PercentNitrogen, PercentPhosphorous = newFertilizer.PercentPhosphorous, PercentPotassium = newFertilizer.PercentPotassium, IsOrganic = newFertilizer.IsOrganic, ContainsPostEmergentWeedControl = newFertilizer.ContainsPostEmergentWeedControl, ContainsPreEmergentWeedControl = newFertilizer.ContainsPreEmergentWeedControl, SeasonsOfUse = newFertilizer.SeasonsOfUse, CreatedDate = DateTime.UtcNow, UpdatedDate = DateTime.UtcNow }; await _fertilizers.InsertOneAsync(fertilizer); return(fertilizer); }
public async Task Update(string fertilizerId, FertilizerForUpdate updatedFertilizer) { var fertilizer = new Models.Products.Fertilizer { Id = fertilizerId, Name = updatedFertilizer.Name, Description = updatedFertilizer.Description, ImageUrl = updatedFertilizer.ImageUrl, ProductType = "fertilizer", CoverageArea = updatedFertilizer.CoverageArea, CoverageAreaUnitOfMeasure = updatedFertilizer.CoverageAreaUnitOfMeasure, PackageSize = updatedFertilizer.PackageSize, PackageSizeUnitOfMeasure = updatedFertilizer.PackageSizeUnitOfMeasure, CompatibleGrassTypes = updatedFertilizer.CompatibleGrassTypes, ConditionOfLawn = updatedFertilizer.ConditionOfLawn, Features = updatedFertilizer.Features, LongevityInWeeks = updatedFertilizer.LongevityInWeeks, PercentNitrogen = updatedFertilizer.PercentNitrogen, PercentPhosphorous = updatedFertilizer.PercentPhosphorous, PercentPotassium = updatedFertilizer.PercentPotassium, IsOrganic = updatedFertilizer.IsOrganic, ContainsPostEmergentWeedControl = updatedFertilizer.ContainsPostEmergentWeedControl, ContainsPreEmergentWeedControl = updatedFertilizer.ContainsPreEmergentWeedControl, SeasonsOfUse = updatedFertilizer.SeasonsOfUse, UpdatedDate = DateTime.UtcNow }; var result = await _fertilizers.ReplaceOneAsync(f => f.Id == fertilizerId, fertilizer); if (result.MatchedCount == 0) { throw new FertilizerNotFoundException(fertilizerId); } }
public Fertilizer(Models.Products.Fertilizer fertilizer) : base(fertilizer.Id, fertilizer.Name, fertilizer.Description, fertilizer.ImageUrl, fertilizer.ProductType) { CoverageArea = fertilizer.CoverageArea; CoverageAreaUnitOfMeasure = fertilizer.CoverageAreaUnitOfMeasure; PackageSize = fertilizer.PackageSize; PackageSizeUnitOfMeasure = fertilizer.PackageSizeUnitOfMeasure; CompatibleGrassTypes = fertilizer.CompatibleGrassTypes; ConditionOfLawn = fertilizer.ConditionOfLawn; Features = fertilizer.Features; LongevityInWeeks = fertilizer.LongevityInWeeks; PercentNitrogen = fertilizer.PercentNitrogen; PercentPhosphorous = fertilizer.PercentPhosphorous; PercentPotassium = fertilizer.PercentPotassium; IsOrganic = fertilizer.IsOrganic; ContainsPostEmergentWeedControl = fertilizer.ContainsPostEmergentWeedControl; ContainsPreEmergentWeedControl = fertilizer.ContainsPreEmergentWeedControl; SeasonsOfUse = fertilizer.SeasonsOfUse; }