Esempio n. 1
0
        public ActionResult Assign(VolunteerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", GetDefaultViewModel(model)));
            }

            try
            {
                var person = _volunteerSvc.FindByUserId(_webSecurity.CurrentUserId);
                if (person == null)
                {
                    throw new ArgumentException(
                              "The logged in user is either the administrator or does not have a valid account for joining a crisis.");
                }
                _disasterSvc.AssignToVolunteer(model.SelectedDisasterId,
                                               person.Id, model.SelectedStartDate, model.SelectedEndDate, model.VolunteerType);

                return(Redirect("/Home"));
            }
            catch (ArgumentException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            var modelToReturn = GetDefaultViewModel();

            modelToReturn.SelectedDisasterId = model.SelectedDisasterId;
            modelToReturn.SelectedStartDate  = model.SelectedStartDate;
            modelToReturn.SelectedEndDate    = model.SelectedEndDate;

            return(View("Index", modelToReturn));
        }
        public ActionResult AddContact(ListByDisasterViewModel model)
        {
            try
            {
                var person = _volunteerSvc.FindByUserId(_webSecurity.CurrentUserId);
                if (!person.OrganizationId.HasValue)
                {
                    throw new ArgumentException("Signed in User is not part of an Organization");
                }

                _adminSvc.AddContactForOrganization(person.OrganizationId.Value, model.AddContactId);
            }
            catch (ArgumentException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            var viewModel = new ListByDisasterViewModel
            {
                Disasters        = _disasterSvc.GetActiveList(),
                SelectedDisaster = model.SelectedDisaster,
                CommitmentDate   = model.CommitmentDate
            };

            return(View("ListByDisaster", viewModel));
        }
Esempio n. 3
0
        public ActionResult Checkin(int commitmentId)
        {
            var person = _volunteerSvc.FindByUserId(_webSecurity.CurrentUserId);

            if (person != null)
            {
                var commitment = _volunteerSvc.RetrieveCommitments(person.Id, true)
                                 .FirstOrDefault(x => x.Id == commitmentId);
                if (commitment != null)
                {
                    commitment.PersonIsCheckedIn = true;
                    _volunteerSvc.UpdateCommitment(commitment);
                }
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        public ActionResult RegisterNewOrganization()
        {
            var person = VolunteerService.FindByUserId(WebSecurityWrapper.CurrentUserId);

            if (person == null)
            {
                throw new InvalidOperationException("A volunteer must be logged in to register a new organization.");
            }

            var model = new NewOrganizationViewModel()
            {
                Address          = new Address(),
                OrganizationName = "",
                Type             = OrganizationTypeEnum.Local
            };

            return(View(model));
        }
        public ActionResult ChangeContactInfo()
        {
            if (WebSecurity.CurrentUserId == 1)
            {
                TempData["AdminContactError"] = "Administrator is not allowed to have contact details!";
                return(RedirectToAction("Index", "Home"));
            }
            var personToUpdate = _volunteerSvc.FindByUserId(WebSecurity.CurrentUserId);

            if (personToUpdate != null)
            {
                ChangeContactInfoViewModel model = new ChangeContactInfoViewModel {
                    Email = personToUpdate.Email, PhoneNumber = personToUpdate.PhoneNumber
                };
                return(View(model));
            }

            return(View("ChangeContactInfo", DetermineLayout(), null));
        }
Esempio n. 6
0
        public ActionResult RegisterNewOrganization()
        {
            var person   = VolunteerService.FindByUserId(WebSecurityWrapper.CurrentUserId);
            int personId = 0;

            if (person != null)
            {
                personId = person.Id;
            }

            var model = new NewOrganizationViewModel()
            {
                Address          = new Address(),
                OrganizationName = "",
                Type             = OrganizationTypeEnum.Local,
                UserIdRegisteringOrganization = personId
            };

            return(View(model));
        }
Esempio n. 7
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                // First assume the username was typed in.
                var userName = model.UserNameOrEmail;
                var userId   = _webSecurity.GetUserId(model.UserNameOrEmail);
                if (userId == -1)
                {
                    // If the user was not found by name, assume his email was typed in.
                    var user = _volunteerSvc.FindUserByEmail(model.UserNameOrEmail);
                    if (user != null)
                    {
                        userName = user.UserName;
                        userId   = user.Id;
                    }
                }

                // Only send email when user actually exists. For security reasons
                // don't show an error when the given user doesn't exist.
                if (userId != -1)
                {
                    var volunteer = _volunteerSvc.FindByUserId(userId);
                    if (volunteer != null)
                    {
                        var token = _webSecurity.GeneratePasswordResetToken(userName);
                        // Generate the absolute Url for the password reset action.
                        var routeValues = new RouteValueDictionary {
                            { "token", token }
                        };
                        var passwordResetLink = Url.Action("ResetPassword", "Account", routeValues, Request.Url.Scheme);

                        var body    = String.Format(@"<p>Click on the following link to reset your password: <a href='{0}'>{0}</a></p>", passwordResetLink);
                        var message = new Message("CrisisCheckin - Password Reset", body);

                        _messageService.SendMessage(message, volunteer);
                    }
                }
                return(RedirectToAction("PasswordResetRequested"));
            }
            return(View(model));
        }
Esempio n. 8
0
        public ActionResult CheckinResource(VolunteerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", GetDefaultViewModel(model)));
            }

            try
            {
                var person = _volunteerSvc.FindByUserId(_webSecurity.CurrentUserId);
                if (person == null)
                {
                    throw new ArgumentException(
                              "The logged in user is either the administrator or does not have a valid account for joining a crisis.");
                }
                _disasterSvc.AddResourceCheckIn(person.Organization, person, model.SelectedDisasterId, model.Description,
                                                model.Qty, model.SelectedResourceTypeId, model.ResourceStartDate, model.ResourceEndDate, model.Location);

                return(Redirect("/Home"));
            }
            catch (ArgumentException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            var modelToReturn = GetDefaultViewModel();

            modelToReturn.SelectedDisasterId = model.SelectedDisasterId;
            modelToReturn.SelectedStartDate  = model.SelectedStartDate;
            modelToReturn.SelectedEndDate    = model.SelectedEndDate;
            modelToReturn.SelectedClusterId  = model.SelectedClusterId;
            modelToReturn.Description        = model.Description;
            modelToReturn.Qty = model.Qty;
            modelToReturn.SelectedResourceTypeId = model.SelectedResourceTypeId;
            modelToReturn.ResourceStartDate      = model.ResourceStartDate;
            modelToReturn.ResourceEndDate        = model.ResourceEndDate;
            modelToReturn.Location = model.Location;

            if (model.SelectedDisasterId != 0)
            {
                modelToReturn.DisasterClusters
                    = _disasterClusterSvc.GetClustersForADisaster(model.SelectedDisasterId);
            }

            return(View("Index", modelToReturn));
        }