public async Task <IActionResult> PutEventType(string id, EventType eventType) { if (id != eventType.EventTypeId) { return(BadRequest()); } _context.Entry(eventType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EventTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutRegistrationStatus(byte id, RegistrationStatus registrationStatus) { if (id != registrationStatus.RegistrationStatusId) { return(BadRequest()); } _context.Entry(registrationStatus).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RegistrationStatusExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCharity(int id, Charity charity) { if (id != charity.CharityId) { return(BadRequest()); } _context.Entry(charity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CharityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSponsorship(int id, Sponsorship sponsorship) { if (id != sponsorship.SponsorshipId) { return(BadRequest()); } _context.Entry(sponsorship).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SponsorshipExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <UserWithToken> > Register([FromBody] User user) { await _context.User.AddAsync(user); await _context.SaveChangesAsync(); var userWithToken = new UserWithToken(user); var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_jwtsettings.SecretKey); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Email) }), Expires = DateTime.UtcNow.AddMonths(3), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); userWithToken.Token = tokenHandler.WriteToken(token); return(userWithToken); }
public async Task <IActionResult> PutRunner(int id, [FromBody] Runner runner) { if (id != runner.RunnerId) { return(BadRequest()); } var runnerFinded = await _context.Runner.Include(x => x.EmailNavigation) .AsNoTracking() .SingleOrDefaultAsync(x => x.RunnerId == runner.RunnerId); runnerFinded.EmailNavigation = runner.EmailNavigation; runnerFinded.DateOfBirth = runner.DateOfBirth; runnerFinded.Gender = runner.Gender; runnerFinded.CountryCode = runner.CountryCode; try { _context.Runner.Update(runner); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RunnerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMarathon(byte id, Marathon marathon) { if (id != marathon.MarathonId) { return(BadRequest()); } _context.Entry(marathon).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MarathonExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutVolunteer(int id, Volunteer volunteer) { if (id != volunteer.VolunteerId) { return(BadRequest()); } _context.Entry(volunteer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VolunteerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Registration> > PostRegistration(Registration registration) { _context.Registration.Add(registration); await _context.SaveChangesAsync(); return(CreatedAtAction("GetRegistration", new { id = registration.RegistrationId }, registration)); }
public async Task <ActionResult <RegistrationEvent> > PostRegistrationEvent(RegistrationEvent registrationEvent) { var currentCountPacitipants = await _context.Event.CountAsync(x => x.EventId == registrationEvent.EventId); var currentEvent = await _context.Event.SingleOrDefaultAsync(x => x.EventId == registrationEvent.EventId); if (currentCountPacitipants + 1 < currentEvent.MaxParticipants) { _context.RegistrationEvent.Add(registrationEvent); await _context.SaveChangesAsync(); } else { return(Problem(detail: "MaxParticipants", statusCode: 404)); } return(CreatedAtAction("GetRegistrationEvent", new { id = registrationEvent.RegistrationEventId }, registrationEvent)); }