public async Task <IActionResult> Renew(string id) { if (id == null) { return(NotFound()); } var applicationUser = await _context.ApplicationUser.SingleOrDefaultAsync(m => m.Id == id); if (applicationUser == null) { return(NotFound()); } var viewModel = new MemberRenewViewModel { Id = applicationUser.Id, FirstName = applicationUser.FirstName, LastName = applicationUser.LastName, Street1 = applicationUser.Street1, Street2 = applicationUser.Street2, City = applicationUser.City, State = applicationUser.State, ZipCode = applicationUser.ZipCode, Phone = applicationUser.PhoneNumber, Email = applicationUser.Email, WhenJoined = applicationUser.WhenJoined, WhenExpires = applicationUser.WhenExpires, NewWhenExpires = applicationUser.WhenExpires < DateTime.Now ? DateTime.Now.AddYears(1) : applicationUser.WhenExpires.AddYears(1) }; return(View(viewModel)); }
public async Task <IActionResult> Renew([Bind("Id,NewWhenExpires")] MemberRenewViewModel viewModel) { var applicationUser = await _context.ApplicationUser.SingleOrDefaultAsync(m => m.Id == viewModel.Id); if (viewModel.Id != applicationUser.Id) { return(NotFound()); } if (ModelState.IsValid) { try { applicationUser.WhenExpires = viewModel.NewWhenExpires; applicationUser.Status = "Active"; _context.Update(applicationUser); Response.Cookies.Append("FlashSuccess", "Member " + applicationUser.FirstName + " " + applicationUser.LastName + " was successfully renewed"); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApplicationUserExists(applicationUser.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } viewModel = new MemberRenewViewModel { Id = applicationUser.Id, FirstName = applicationUser.FirstName, LastName = applicationUser.LastName, Street1 = applicationUser.Street1, Street2 = applicationUser.Street2, City = applicationUser.City, State = applicationUser.State, ZipCode = applicationUser.ZipCode, Phone = applicationUser.PhoneNumber, Email = applicationUser.Email, WhenJoined = applicationUser.WhenJoined, WhenExpires = applicationUser.WhenExpires, NewWhenExpires = applicationUser.WhenExpires < DateTime.Now ? DateTime.Now.AddYears(1) : applicationUser.WhenExpires.AddYears(1) }; return(View(viewModel)); }
public async Task <IActionResult> Renew([Bind("Id,NewWhenExpires")] MemberRenewViewModel viewModel) { ViewBag.User = await GetCurrentUser(); var applicationUser = await _context.ApplicationUser.SingleOrDefaultAsync(m => m.Id == viewModel.Id); if (viewModel.Id != applicationUser.Id) { return(NotFound()); } if (ModelState.IsValid) { try { applicationUser.WhenExpires = viewModel.NewWhenExpires; if (applicationUser.WhenExpires < DateTime.Now) { await _userManager.RemoveFromRoleAsync(applicationUser, "League"); await _userManager.RemoveFromRoleAsync(applicationUser, "Chapter"); await _userManager.RemoveFromRoleAsync(applicationUser, "Member"); if (applicationUser.SecurityGroup != "Guest") { await _userManager.AddToRoleAsync(applicationUser, "Member"); } applicationUser.SecurityGroup = "Member"; } applicationUser.Status = "Active"; _context.Update(applicationUser); Response.Cookies.Append("FlashSuccess", "Member " + applicationUser.FirstName + " " + applicationUser.LastName + " was successfully renewed"); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApplicationUserExists(applicationUser.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } viewModel = new MemberRenewViewModel { Id = applicationUser.Id, FirstName = applicationUser.FirstName, LastName = applicationUser.LastName, Pseudonym = applicationUser.Pseudonym, ContactName = applicationUser.ContactName, Street1 = applicationUser.Street1, Street2 = applicationUser.Street2, City = applicationUser.City, State = applicationUser.State, ZipCode = applicationUser.ZipCode, Phone = applicationUser.PhoneNumber, Email = applicationUser.Email, WhenJoined = applicationUser.WhenJoined, WhenExpires = applicationUser.WhenExpires, NewWhenExpires = applicationUser.WhenExpires < DateTime.Now ? DateTime.Now.AddYears(1) : applicationUser.WhenExpires.AddYears(1) }; ViewBag.CommonName = applicationUser.CommonName; return(View(viewModel)); }