コード例 #1
0
 private static HousePlantItemDTO ItemToDTO(HousePlantItem plantItem) =>
 new HousePlantItemDTO
 {
     ID         = plantItem.ID,
     CommonName = plantItem.CommonName,
     IsWatered  = plantItem.IsWatered
 };
コード例 #2
0
        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)));
        }