Exemple #1
0
        public async Task <ServiceResponse <GetEventDto> > UpdateEvent(UpdateEventDto updatedEvent)
        {
            ServiceResponse <GetEventDto> serviceResponse = new ServiceResponse <GetEventDto>();

            try
            {
                webApi.Models.Event events = await _context.Events.Include(c => c.Tournament.user).FirstOrDefaultAsync(c => c.eventID == updatedEvent.eventID);

                if (events.Tournament.user.Id == GetUserId())
                {
                    events.eventName        = updatedEvent.eventName;
                    events.Tournament       = updatedEvent.Tournament;
                    events.eventNumber      = updatedEvent.eventNumber;
                    events.eventDateTime    = updatedEvent.eventDateTime;
                    events.eventEndDateTime = updatedEvent.eventEndDateTime;


                    _context.Events.Update(events);
                    await _context.SaveChangesAsync();

                    serviceResponse.Data = _mapper.Map <GetEventDto>(events);
                }
                else
                {
                    serviceResponse.Success = false;
                    serviceResponse.Message = "Event not found.";
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            return(serviceResponse);
        }
Exemple #2
0
        public async Task <ServiceResponse <List <GetEventDto> > > DeleteEvent(int id)
        {
            ServiceResponse <List <GetEventDto> > serviceResponse = new ServiceResponse <List <GetEventDto> >();

            try
            {
                webApi.Models.Event events = await _context.Events
                                             .FirstOrDefaultAsync(c => c.eventID == id && c.Tournament.user.Id == GetUserId());

                if (events != null)
                {
                    _context.Events.Remove(events);
                    await _context.SaveChangesAsync();

                    serviceResponse.Data = (_context.Events.Where(c => c.Tournament.user.Id == GetUserId())
                                            .Select(c => _mapper.Map <GetEventDto>(c))).ToList();
                }
                else
                {
                    serviceResponse.Success = false;
                    serviceResponse.Message = "Event not found.";
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            return(serviceResponse);
        }
        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);
        }
Exemple #4
0
        public async Task <ServiceResponse <GetEventDto> > GetEventById(int id)
        {
            ServiceResponse <GetEventDto> serviceResponse = new ServiceResponse <GetEventDto>();

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


            serviceResponse.Data = _mapper.Map <GetEventDto>(events);
            return(serviceResponse);
        }
Exemple #5
0
        int  GetUserId() => int.Parse(_httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier));   // Authenticated user.

        public async Task <ServiceResponse <GetTournamentDto> > AddEvents(AddEventDto newEvent)
        {
            ServiceResponse <GetTournamentDto> response = new ServiceResponse <GetTournamentDto>();

            try
            {
                webApi.Models.Tournament tournament = await _context.Tournaments
                                                      .FirstOrDefaultAsync(t => t.TournamentId == newEvent.TournamentId &&
                                                                           t.user.Id == int.Parse(_httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)));

                if (tournament == null)
                {
                    response.Success = false;
                    response.Message = "Tournament not found.";
                    return(response);
                }

                webApi.Models.Event events = new webApi.Models.Event
                {
                    eventName     = newEvent.EventName,
                    eventNumber   = newEvent.Eventnumber,
                    eventDateTime = newEvent.EventDate,
                    Tournament    = tournament
                };
                await _context.Events.AddAsync(events);

                await _context.SaveChangesAsync();

                response.Data = _mapper.Map <GetTournamentDto>(tournament);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }