public Barbecue Run(string barbecueId, Participant[] participants)
        {
            var barbecue = _barbecueRepository.FindOne(barbecueId);

            if (barbecue == null)
            {
                throw new ArgumentException("Churrasco não encontrado");
            }

            var update = Builders <Barbecue> .Update.Set(x => x.Participants, participants);

            _barbecueRepository.Update(barbecueId, update);

            return(barbecue);
        }
Beispiel #2
0
        public ActionResult <Barbecue> Get(string id)
        {
            try
            {
                var barbecueSchedule = _barbecueRepository.FindOne(id);
                if (barbecueSchedule == null)
                {
                    return(NotFound());
                }

                return(new ObjectResult(barbecueSchedule));
            }
            catch (Exception error)
            {
                return(BadRequest(error));
            }
        }
Beispiel #3
0
        public Barbecue Run(string barbecueId, Participant participant)
        {
            var barbecue = _barbecueRepository.FindOne(barbecueId);

            if (barbecue == null)
            {
                throw new ArgumentException("Churrasco não encontrado");
            }

            if (barbecue.Participants.Any(x => x.Name.Equals(participant.Name, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new Exception("Participante já cadastrado");
            }

            var participants = barbecue.Participants.ToList();

            participants.Add(participant);

            var update = Builders <Barbecue> .Update.Set(x => x.Participants, participants);

            _barbecueRepository.Update(barbecueId, update);

            return(barbecue);
        }