public async Task <IActionResult> OnPostSaveTimesAsync(IFormCollection formData) { AppUser currentUser = _userManager.GetUserAsync(User).Result; await _context.Entry(currentUser).Reference(p => p.VolunteerProfile).LoadAsync(); await _context.Entry(currentUser.VolunteerProfile).Collection(p => p.Availabilities).LoadAsync(); AvailabilityHandler availability = new AvailabilityHandler(); bool updateWasSuccessful = await availability.UpdateVolunteerAvailability(formData, currentUser.VolunteerProfile, _context); if (!updateWasSuccessful) { return(RedirectToPage(new { statusMessage = "Error: One or more of the availabilities you entered was missing either a start time or end time." })); } return(RedirectToPage(new { statusMessage = "You have successfully changed your availability" })); }
public async Task <IActionResult> OnPostSaveChangesAsync(IFormCollection formData, int id, string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); var errors = ModelState.Values.Select(v => v.Errors); if (!ModelState.IsValid) { return(OnGet(id: id, statusMessage: "Error: One or more of the fields was not filled in properly.")); } // retrieve the user to be updated, load volunteer profile and all navigation properties AppUser user = await _context.Users.FirstOrDefaultAsync(u => u.VolunteerProfile.Id == id); await _context.Entry(user).Reference(p => p.VolunteerProfile).LoadAsync(); await _context.Entry(user.VolunteerProfile).Collection(p => p.Availabilities).LoadAsync(); await _context.Entry(user.VolunteerProfile).Collection(p => p.References).LoadAsync(); await _context.Entry(user.VolunteerProfile).Collection(p => p.WorkExperiences).LoadAsync(); bool DuplicateEmailFound = await _context.Users.AnyAsync(u => u.NormalizedEmail == DetailsModel.Email.ToUpper() && u.Id != user.Id); if (DuplicateEmailFound) { return(OnGet(id: id, statusMessage: "Error: The email you entered already belongs to someone else.")); } await UpdateUserProfile(user); var volunteer = await _context.VolunteerProfiles.FirstOrDefaultAsync(p => p.Id == id); AvailabilityHandler availability = new AvailabilityHandler(); bool successfullySetAvailabilities = await availability.UpdateVolunteerAvailability(formData, volunteer, _context); if (!successfullySetAvailabilities) { return(RedirectToPage(new { statusMessage = "Error: One of the availabilities you entered was invalid. Make sure you enter a value for both the start and end time." })); } return(RedirectToPage(new { statusMessage = "Successfully updated the volunteer profile." })); }