public async Task <RegistrationForViewDto> Register(int excelId, DataForRegistrationDto dataForRegistration) { if (await HasRegistered(excelId, dataForRegistration.EventId)) { throw new OperationInvalidException("Already registered for the event."); } if (dataForRegistration.TeamId != null) { return(await RegisterWithTeam(excelId, dataForRegistration.EventId, Convert.ToInt32(dataForRegistration.TeamId))); } var eventToRegister = await _eventRepo.GetEvent(dataForRegistration.EventId, null); if (eventToRegister == null) { throw new DataInvalidException("Invalid event ID."); } if (eventToRegister.RegistrationOpen == null || !Convert.ToBoolean(eventToRegister.RegistrationOpen)) { throw new DataInvalidException("Registration Closed"); } if (eventToRegister.IsTeam) { throw new DataInvalidException("Need team Id to register for team event."); } var newRegistration = new Registration { EventId = dataForRegistration.EventId, ExcelId = excelId }; await _context.Registrations.AddAsync(newRegistration); await _context.SaveChangesAsync(); return(_mapper.Map <RegistrationForViewDto>(newRegistration)); }
public async Task <RegistrationForViewDto> ChangeTeam(int excelId, DataForRegistrationDto dataForRegistration) { var eventWithTeams = await _eventRepo.GetEventWithTeam(dataForRegistration.EventId, Convert.ToInt32(dataForRegistration.TeamId)); if (eventWithTeams.RegistrationOpen == null || !Convert.ToBoolean(eventWithTeams.RegistrationOpen)) { throw new DataInvalidException("Registration Closed"); } if (eventWithTeams.Registrations.Count < eventWithTeams.TeamSize) { var registration = await _context.Registrations.FirstOrDefaultAsync(r => r.EventId == dataForRegistration.EventId && r.ExcelId == excelId); registration.TeamId = dataForRegistration.TeamId; await _context.SaveChangesAsync(); registration.Team = await _context.Teams.AsNoTracking() .FirstOrDefaultAsync(team => team.Id == dataForRegistration.TeamId); return(_mapper.Map <RegistrationForViewDto>(registration)); } throw new DataInvalidException("Team is full"); }
public async Task <ActionResult <bool> > ChangeTeam(DataForRegistrationDto dataForRegistration) { var excelId = int.Parse(User.Claims.First(x => x.Type == "user_id").Value); return(Ok(await _repo.ChangeTeam(excelId, dataForRegistration))); }
public async Task <ActionResult <RegistrationForViewDto> > AddRegistration(DataForRegistrationDto dataForRegistration) { var excelId = int.Parse(User.Claims.First(i => i.Type == "user_id").Value); return(Ok(await _repo.Register(excelId, dataForRegistration))); }
public async Task <ActionResult <Bookmark> > Add(DataForRegistrationDto dataForRegistration) { var excelId = int.Parse(this.User.Claims.First(i => i.Type == "user_id").Value); return(Ok(await _repo.Add(excelId, dataForRegistration.EventId))); }
public async Task <ActionResult <List <RegistrationForViewDto> > > ClearUserData(DataForRegistrationDto data) { return(Ok(await _repo.ClearUserData(data.Id))); }