public async Task <IActionResult> UpdateRequestedItem(Guid requestedItemId, UpdateRequestedItemDto updateItemDto) { var itemToUpdate = await _beachBuddyRepository.GetRequestedItem(requestedItemId); if (itemToUpdate == null) { return(NotFound()); } if (updateItemDto.Name == null) { updateItemDto.Name = itemToUpdate.Name; } if (updateItemDto.Count == 0) { updateItemDto.Count = itemToUpdate.Count; } // Only set the completed time if it was previously not set if (updateItemDto.IsRequestCompleted && !itemToUpdate.IsRequestCompleted) { itemToUpdate.CompletedDateTime = DateTimeOffset.UtcNow; } _mapper.Map(updateItemDto, itemToUpdate); _beachBuddyRepository.UpdateRequestedItem(itemToUpdate); await _beachBuddyRepository.Save(); var itemToReturn = _mapper.Map <RequestedItemDto>(itemToUpdate); // Notify other devices an item has been changed await _notificationService.sendNotification(itemToUpdate, NotificationType.RequestedItemCompleted, null, null, true); return(Ok(itemToReturn)); }