private static HousePlantItemDTO ItemToDTO(HousePlantItem plantItem) => new HousePlantItemDTO { ID = plantItem.ID, CommonName = plantItem.CommonName, IsWatered = plantItem.IsWatered };
public async Task <ActionResult <HousePlantItemDTO> > PostHousePlantItem(HousePlantItemDTO housePlantItemDTO) { // Create new housePlantItem with values from DTO var housePlantItem = new HousePlantItem { CommonName = housePlantItemDTO.CommonName, IsWatered = housePlantItemDTO.IsWatered }; _context.HousePlantItems.Add(housePlantItem); await _context.SaveChangesAsync(); return(CreatedAtAction("GetHousePlantItem", new { id = housePlantItem.ID }, ItemToDTO(housePlantItem))); }