예제 #1
0
        public IActionResult PostParticipant(int barbecueId, [FromBody] CreateEditParticipantDto newParticipant)
        {
            var barbecue = barbecueRepository.Get(barbecueId);

            if (barbecue == null)
            {
                throw new NotFoundException("barbecueId", "Resource not found", ErrorResultType.not_found);
            }

            var participant = Mapper.Map <Participant>(newParticipant);

            barbecue.AddParticipant(participant);

            barbecueRepository.Save(barbecue);

            return(CreatedAtRoute(
                       "GetParticipants",
                       new { barbecueId = barbecue.Id },
                       Mapper.Map <ParticipantDto>(participant)
                       ));
        }
예제 #2
0
        public IActionResult PutParticipant(int barbecueId, int participantId, [FromBody] CreateEditParticipantDto editedParticipant)
        {
            var barbecue = barbecueRepository.Get(barbecueId);

            if (barbecue == null)
            {
                throw new NotFoundException("barbecueId", "Resource not found", ErrorResultType.not_found);
            }

            var participant = barbecue.Participants.FirstOrDefault(x => x.Id == participantId);

            if (participant == null)
            {
                throw new NotFoundException("participantId", "Resource not found", ErrorResultType.not_found);
            }

            participant.ChangeName(editedParticipant.Name);
            participant.ChangeIsGoingToDrink(editedParticipant.IsGoingToDrink);
            participant.ChangeDough(editedParticipant.Dough);

            barbecueRepository.Save(barbecue);

            return(Ok(Mapper.Map <ParticipantDto>(participant)));
        }