Пример #1
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));
        }
        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.
            var worked = await _channel.AddRegistration(new EventRegistrationChannelRequest(registration.Id ));

            if (!worked)
            {
                // what is your Plan B???
            }
            // 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));
        }