Exemple #1
0
        public async Task <IActionResult> ChangeValidation([FromBody] BookingValidationDeserializer bookingValidationDsl,
                                                           [FromRoute] bool validation)
        {
            Booking booking = await BookingServices.GetByIdsAsync(bookingValidationDsl.UserId,
                                                                  bookingValidationDsl.EventId, BookingServices.WithUserAndEvent(Context.Booking));

            if (booking == null)
            {
                return(NotFound("Booking not found"));
            }

            booking.Present = validation;

            if (!validation && booking.Event.JuryPoint.HasValue)
            {
                BookingServices.RemoveJuryPoints(
                    BookingServices.GetJuryPoint(bookingValidationDsl.UserId, (float)booking.Event.JuryPoint)
                    );
            }
            else if (booking.Event.JuryPoint.HasValue)
            {
                BookingServices.CreateJuryPoint((float)booking.Event.JuryPoint, bookingValidationDsl.UserId);
                EmailServices.SendFor(booking.User, booking.Event, BookingTemplate.PRESENT);
            }

            try {
                Context.Booking.Update(booking);
                await Context.SaveChangesAsync();
            } catch (DbUpdateException ex) {
                return(BadRequest(ex));
            }

            return(NoContent());
        }