public async Task <ActionResult <AttendeeViewModel> > GetAttendeeRandomForItemId(string itemId) { if (!await _itemRepository.ExistItemByIdAsync(itemId)) { return(NotFound()); } var entity = _attendeeRepository.GetAttendeeRandomForItemId(itemId); if (entity == null) // 清單中的參與者都獲獎了 { return(NoContent()); } entity.AttendeeIsAwarded = true; _attendeeRepository.UpdateAttendee(entity); _winnerRepository.CreateWinnerForItemIdAttendeeId(itemId, entity.AttendeeId, new Winner()); var result = await _winnerRepository.SaveAsync(); if (!result) { return(BadRequest()); } var model = _mapper.Map <AttendeeViewModel>(entity); return(Ok(model)); }