public async Task <ServiceResponse <List <GetRegistrationDTO> > > AddRegistration(AddRegistrationDTO newRegistration) { ServiceResponse <List <GetRegistrationDTO> > serviceResponse = new ServiceResponse <List <GetRegistrationDTO> >(); Registration registration = _mapper.Map <Registration>(newRegistration); // Associating new registration with user's JWT claim "u => u.Id == GetUserId()" registration.User = await _context.Users.FirstOrDefaultAsync(u => u.Id == GetUserId()); await _context.Registrations.AddAsync(registration); await _context.SaveChangesAsync(); serviceResponse.Data = (_context.Registrations.Select(c => _mapper.Map <GetRegistrationDTO>(c))).ToList(); serviceResponse.Message = "User has succesfully registered to course."; return(serviceResponse); }
public async Task <IActionResult> AddRegistration(AddRegistrationDTO newRegistration) { return(Ok(await _registrationService.AddRegistration(newRegistration))); }