public async Task <ServiceResponse <GetEventDto> > AddDetailEvents(AddEventDetailDto newDetailEvent)
        {
            ServiceResponse <GetEventDto> response = new ServiceResponse <GetEventDto>();

            try
            {
                webApi.Models.Event events = await _context.Events
                                             .Include(c => c.Tournament)
                                             .Include(c => c.EventDetail).ThenInclude(cs => cs.EventDetailStatus)
                                             .FirstOrDefaultAsync(c => c.eventID == newDetailEvent.eventID &&
                                                                  c.Tournament.user.Id == int.Parse(_httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)));

                if (events == null)
                {
                    response.Success = false;
                    response.Message = "Event not found.";
                    return(response);
                }
                EventDetailStatus eventStatus = await _context.EventDetailStatuses
                                                .FirstOrDefaultAsync(s => s.EventDetailStatusId == newDetailEvent.EventDetailStatusId);

                if (eventStatus == null)
                {
                    response.Success = false;
                    response.Message = "Event Stutus not found";
                    return(response);
                }
                webApi.Models.EventDetail eventDetail = new  webApi.Models.EventDetail
                {
                    Event             = events,
                    EventDetailStatus = eventStatus,
                    EventDetailName   = newDetailEvent.eventDetailName,
                    EventDetailNumber = newDetailEvent.eventDetailNumber,
                    EventDetailOdd    = newDetailEvent.eventDetailOdd,
                    FinishingPosition = newDetailEvent.finishingPosition,
                    FirstTimer        = newDetailEvent.firstTimer
                };

                await _context.EventDetails.AddAsync(eventDetail);

                await _context.SaveChangesAsync();

                response.Data = _mapper.Map <GetEventDto>(events);
            }catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Beispiel #2
0
 public async Task <IActionResult> AddDetailEvent(AddEventDetailDto newDetailEvent)
 {
     return(Ok(await _eventDetailService.AddDetailEvents(newDetailEvent)));
 }