public async Task <IActionResult> Participate(int?id, EventParticipateViewModel viewModel) { if (id == null) { return(StatusCode((int)HttpStatusCode.BadRequest)); } if (viewModel.CurrentEvent.Start < DateTime.Now) { return(StatusCode((int)HttpStatusCode.BadRequest)); } var user = await _userManager.GetUserAsync(this.User); _participationRepository.Update((int)id, user.UserId, viewModel); // Send participation update to opted-in admins var admins = await _userManager.GetUsersInRoleAsync(RoleNames.ROLE_ADMIN); foreach (var admin in admins) { var config = _notificationConfigurationRepository.GetConfigurationForUser(admin.UserId); if (config != null && config.UserParticipationUpdated) { await _eMailSender.SendUserParticipationEmail(admin.Email); } } return(RedirectToAction(MethodNames.INDEX)); }
public async Task <IActionResult> Register(RegisterViewModel viewModel) { if (ModelState.IsValid) { var user = new User() { UserName = viewModel.Username, Registered = DateTime.Now, Email = viewModel.Mail }; var result = await _userManager.CreateAsync(user, viewModel.Password); if (result.Succeeded) { await _userManager.UpdateAsync(user); var admins = await _userManager.GetUsersInRoleAsync(RoleNames.ROLE_ADMIN); foreach (var admin in admins) { var config = _notificationConfigurationRepository.GetConfigurationForUser(admin.UserId); if (config != null && config.NewUserRegistered) { await _eMailSender.SendUserConfirmationEmail(admin.Email); } } return(RedirectToAction(MethodNames.ACC_REGISTERED)); } else { ModelState.AddModelError("err_register", _localizer[AccountStrings.ACC_ERR_DUPLICATE_REGISTRATION]); } } return(View(viewModel)); }