Пример #1
0
        public async Task <ActionResult> AddParticipant(int id, [FromBody] PostParticipantRequest request)
        {
            // Validate it -- elided for class.
            // make sure there is event with that id.
            var savedEvent = await _context.Events.SingleOrDefaultAsync(e => e.Id == id);

            if (savedEvent == null)
            {
                return(NotFound("No Event with that Id"));
            }

            bool employeeIsActive = await _employeeService.CheckEmployeeIsActive(request.Id);

            if (!employeeIsActive)
            {
                return(BadRequest("That employee is no longer active."));
            }

            // TODO: What if they are registered already?
            //  - return a 400. Just saying "Nope".
            //  - return a conflict - this is saying "this thing conflicts with something else"
            //  - you could update the data with the request... maybe they want to use a different email address.
            //  - if they just posted twice (that kinda thing happens in the weird WWW)
            //  - return a redirect to their registration.
            // add a participant using the data from the request.
            //EventParticipant participant = new EventParticipant();
            //var particpant = new EventParticipant();
            EventParticipant participant = new()
            {
                EmployeeId = request.Id,
                Name       = request.FirstName + " " + request.LastName,
                EMail      = request.Email,
                Phone      = request.Phone
            };

            // just ask the other API, does this employee exist?
            //  --
            // save it.
            if (savedEvent.Participants == null)
            {
                savedEvent.Participants = new List <EventParticipant>();
            }
            savedEvent.Participants.Add(participant);
            await _context.SaveChangesAsync();

            // return something... CreatedAtRoute
            return(Ok());
        }
Пример #2
0
        public async Task <ActionResult> AddRegistration(int eventId, [FromBody] PostReservationRequest request)
        {
            // check to see if there is an event with that id.
            var savedEvent = await _context.Events.SingleOrDefaultAsync(e => e.Id == eventId);

            if (savedEvent == null)
            {
                return(NotFound());
            }
            // add this registration as a pending registration.
            EventRegistration registration = new()
            {
                EmployeeId = request.Id,
                Name       = request.FirstName + " " + request.LastName,
                EMail      = request.Email,
                Phone      = request.Phone,
                Status     = EventRegistrationStatus.Pending
            };

            savedEvent.Registrations.Add(registration);
            await _context.SaveChangesAsync();

            // Magic! -- tell the background worker to process this thing.
            // return a 201 Created with a link to the get/id method, with a copy of that registration
            // which will say status "pending".


            return(CreatedAtRoute("get-event-reservation",
                                  new { eventId = savedEvent.Id, registrationId = registration.Id },
                                  registration));
        }
Пример #3
0
        public async Task <ActionResult> AddRegistration(int eventId, [FromBody] PostReservationRequest request)
        {
            var savedEvent = await _context.Events.SingleOrDefaultAsync(e => e.Id == eventId);

            if (savedEvent == null)
            {
                return(NotFound());
            }

            EventRegistration registration = new()
            {
                EmployeedId = request.Id,
                Name        = request.FirstName + " " + request.LastName,
                Email       = request.Email,
                Phone       = request.Phone,
                Status      = EventRegistrationStatus.Pending
            };

            savedEvent.Registrations.Add(registration);
            await _context.SaveChangesAsync();

            var worked = await _channel.AddRegistration(new EventRegistrationChannelRequest(registration.Id));

            return(CreatedAtRoute("get-event-registration",
                                  new { eventId = savedEvent.Id, registrationId = registration.Id },
                                  registration));
        }