Exemplo n.º 1
0
        public void AggregateSubscription_should_not_be_available_if_not_all_constraints_satisfied()
        {
            var handler = new AvailabilityHandler();
            var aggSub  = new SubscriptionAggregate(SubscriptionSystem, entityId, typeof(Entity), typeof(World));

            aggSub.SetAvailabilityHandler(handler);

            Assert.IsFalse(handler.IsAvailable);
            Assert.Throws <InvalidOperationException>(() => aggSub.GetValue <Entity>());
        }
Exemplo n.º 2
0
        public void AggregateSubscription_should_be_available_if_all_constraints_satisfied()
        {
            var handler = new AvailabilityHandler();
            var aggSub  = new SubscriptionAggregate(SubscriptionSystem, entityId, typeof(EntityId), typeof(World));

            aggSub.SetAvailabilityHandler(handler);

            Assert.IsTrue(handler.IsAvailable);
            Assert.AreEqual(entityId, aggSub.GetValue <EntityId>());
            Assert.AreEqual(World, aggSub.GetValue <World>());
        }
        public async Task <IActionResult> OnGet(string statusMessage = null)
        {
            StatusMessage = statusMessage;
            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();

            LoggedInUser = currentUser.VolunteerProfile.FirstName + " " + currentUser.VolunteerProfile.LastName;
            AvailabilityHandler availability = new AvailabilityHandler();

            OldAvailability = availability.GetSortedAvailability(currentUser.VolunteerProfile.Availabilities);

            return(Page());
        }
        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" }));
        }
Exemplo n.º 5
0
        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." }));
        }
Exemplo n.º 6
0
        private void PrepareModel(int id)
        {
            var volunteerUserProfile = _context.Users
                                       .Include(p => p.VolunteerProfile)
                                       .Include(p => p.VolunteerProfile.WorkExperiences)
                                       .Include(p => p.VolunteerProfile.References)
                                       .Include(p => p.VolunteerProfile.Availabilities)
                                       .Include(p => p.VolunteerProfile.Positions).ThenInclude(p => p.Position)
                                       .FirstOrDefault(u => u.VolunteerProfile.Id == id);

            DetailsModel       = _mapper.Map <VolunteerAdminReadEditDto>(volunteerUserProfile.VolunteerProfile);
            DetailsModel.Email = volunteerUserProfile.Email;

            Positions = _context.Positions.Where(p => p.Name != "All" && !p.Deleted).ToList();

            AvailabilityHandler availability = new AvailabilityHandler();

            OldAvailability = availability.GetSortedAvailability(volunteerUserProfile.VolunteerProfile.Availabilities);

            CurrentPage = $"Volunteer Details for {volunteerUserProfile.VolunteerProfile.FirstName} {volunteerUserProfile.VolunteerProfile.LastName}";
        }
Exemplo n.º 7
0
 // GET: Users/Login
 public IActionResult LogIn()
 {
     AvailabilityHandler.GetHandled(_context);
     return(View());
 }
Exemplo n.º 8
0
        public async Task <IActionResult> OnPostAsync(IFormCollection formData)
        {
            Positions = _context.Positions.ToList();
            // if we want to add external logins later on
            // ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

            if (!ModelState.IsValid)
            {
                return(OnGet());
            }

            Volunteer.WorkExperiences = WorkExperiences;
            Volunteer.References      = References;
            Volunteer.ApprovalStatus  = ApprovalStatus.Pending;

            var domainVolunteerProfile = _mapper.Map <VolunteerProfile>(Volunteer);

            AppUser user = new AppUser
            {
                UserName         = Volunteer.Email,
                Email            = Volunteer.Email,
                VolunteerProfile = domainVolunteerProfile
            };
            var availHandler = new AvailabilityHandler();

            user.VolunteerProfile.Availabilities = availHandler.GetAvailabilitiesFromFormData(formData, user.VolunteerProfile);
            user.VolunteerProfile.Alerts         = new List <Alert>()
            {
                new ApplicationAlert {
                    Date = DateTime.Now, Volunteer = user.VolunteerProfile, Read = false
                }
            };
            user.VolunteerProfile.Positions = AssignPreferredPositions(user.VolunteerProfile);

            IdentityResult accountCreationResult = null;
            IdentityResult addToRoleResult       = null;

            if (user.VolunteerProfile.Availabilities != null)
            {
                accountCreationResult = await _userManager.CreateAsync(user, Volunteer.Password);

                addToRoleResult = await _userManager.AddToRoleAsync(user, "Volunteer");

                if (accountCreationResult.Succeeded && addToRoleResult.Succeeded)
                {
                    await _context.Entry(user.VolunteerProfile).Collection(p => p.Alerts).LoadAsync();

                    _logger.LogInformation("User created a new account with password.");
                    // we should also figure out if we even need account confirmation

                    try
                    {
                        await TrySendConfirmationEmail(user);

                        return(RedirectToPage("/Account/Login", new { registeredUserId = user.Id, statusMessage = "Thank you for applying to the Medicine Hat Food Bank! You will receive a confirmation email to confirm your account. Check your spam/junk folder if the email is not in your inbox." }));
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError(String.Empty, "Email failed to send.");
                        _logger.LogError(ex.Message);
                    }
                }
                else
                {
                    if (accountCreationResult != null && !accountCreationResult.Succeeded)
                    {
                        if (_context.Users.Any(e => e.Email == Volunteer.Email))
                        {
                            ModelState.AddModelError("EmailError", "This email is already in use.");
                        }

                        AddIdentityErrors(accountCreationResult);
                    }
                    if (addToRoleResult != null && !addToRoleResult.Succeeded)
                    {
                        AddIdentityErrors(addToRoleResult);
                    }
                }
            }
            else
            {
                if (user.VolunteerProfile.Availabilities == null)
                {
                    ModelState.AddModelError("AvailabilityError", "One or more of the availability ranges are invalid.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }