Пример #1
0
        public ActionResult Assign(VolunteerViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (DateTime.Compare(model.SelectedEndDate, model.SelectedStartDate) >= 0)
                {
                    Person me = _volunteerSvc.FindByUserId(WebSecurity.CurrentUserId);
                    _disasterSvc.AssignToVolunteer(new Disaster { Id = model.SelectedDisaster },
                        me, model.SelectedStartDate, model.SelectedEndDate);
                }
                else
                {
                    ModelState.AddModelError("", "Start Date must come before End Date.");
                    var modelToReturn = GetDefaultViewModel();
                    modelToReturn.SelectedDisaster = model.SelectedDisaster;
                    modelToReturn.SelectedStartDate = model.SelectedStartDate;
                    modelToReturn.SelectedEndDate = model.SelectedEndDate;
                    return View("Index", modelToReturn);
                }

                return Redirect("/Home");
            }
            else
            {
                return View("Index", GetDefaultViewModel());
            }
        }
Пример #2
0
        public ActionResult Assign(VolunteerViewModel model)
        {
            if (!ModelState.IsValid)
                return View("Index", GetDefaultViewModel(model));

            try
            {
                if (DateTime.Compare(DateTime.Today, model.SelectedStartDate) > 0)
                {
                    throw new ArgumentException("Please enter a start date that is greater than today's date.");
                }

                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);

                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 void Assign_BadDateRange_ReturnsIndexView()
        {
            // Arrange
            var disaster = new Mock<IDisaster>();
            var volunteer = new Mock<IVolunteerService>();
            var webSecurity = new Mock<IWebSecurityWrapper>();

            var controller = new HomeController(disaster.Object, volunteer.Object, webSecurity.Object);

            disaster.Setup(x => x.AssignToVolunteer(
                It.IsAny<int>(),
                It.IsAny<int>(),
                It.IsAny<DateTime>(),
                It.IsAny<DateTime>())).Throws(new ArgumentException(""));

            volunteer.Setup(x => x.FindByUserId(It.IsAny<int>())).Returns(new Person());
            webSecurity.SetupGet(x => x.CurrentUserId).Returns(10);

            // Act
            var viewModel = new VolunteerViewModel { SelectedStartDate = DateTime.Today.AddDays(1) };
            var response = controller.Assign(viewModel);

            // Assert
            var view = response as ViewResult;
            Assert.IsTrue(view.ViewName.Equals("Index"));
            Assert.IsTrue(view.ViewData.ModelState.Count >= 1);
        }
Пример #4
0
        public ActionResult Assign(VolunteerViewModel model)
        {
            if (!ModelState.IsValid) return View("Index", GetDefaultViewModel());

            try
            {
                if (DateTime.Compare(DateTime.Today, model.SelectedStartDate) > 0)
                {
                    throw new ArgumentException("Please enter a start date that is greater than today's date.");
                }

                Person me = _volunteerSvc.FindByUserId(_webSecurity.CurrentUserId);
                _disasterSvc.AssignToVolunteer(new Disaster { Id = model.SelectedDisaster },
                    me, model.SelectedStartDate, model.SelectedEndDate);

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

            var modelToReturn = GetDefaultViewModel();
            modelToReturn.SelectedDisaster = model.SelectedDisaster;
            modelToReturn.SelectedStartDate = model.SelectedStartDate;
            modelToReturn.SelectedEndDate = model.SelectedEndDate;

            return View("Index", modelToReturn);
        }
Пример #5
0
        public ActionResult RemoveCommitment(VolunteerViewModel model)
        {
            if (!ModelState.IsValid) return View("Index", GetDefaultViewModel(model));

            try
            {
                var person = _volunteerSvc.FindByUserId(_webSecurity.CurrentUserId);
                var commitments = _volunteerSvc.RetrieveCommitments(person.Id, true).AsEnumerable();

                if (commitments.Where(c => c.Id == model.RemoveCommitmentId).FirstOrDefault() == null)
                {
                    throw new ArgumentException("Commitment supplied is not yours.");
                }

                _disasterSvc.RemoveCommitmentById(model.RemoveCommitmentId);

                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);
        }
Пример #6
0
        private VolunteerViewModel GetDefaultViewModel()
        {
            var person = _volunteerSvc.FindByUserId(WebSecurity.CurrentUserId);
            IEnumerable<Commitment> comms = (person != null) ?
                _volunteerSvc.RetrieveCommitments(person, true) :
                new List<Commitment>().AsEnumerable();

            var model = new VolunteerViewModel
            {
                Disasters = _disasterSvc.GetActiveList(),
                MyCommitments = comms
            };

            return model;
        }
        public void Assign_ValidDateRange_RedirectsToHome()
        {
            // Arrange
            var disaster = new Mock<IDisaster>();
            var volunteer = new Mock<IVolunteerService>();
            var webSecurity = new Mock<IWebSecurityWrapper>();
            volunteer.Setup(service => service.FindByUserId(It.IsAny<int>())).Returns(new Person());
            var controller = new HomeController(disaster.Object, volunteer.Object, webSecurity.Object);

            // Act
            var viewModel = new VolunteerViewModel { SelectedStartDate = DateTime.Today.AddDays(1) };
            var response = controller.Assign(viewModel);

            // Assert
            var result = response as RedirectResult;
            Assert.IsTrue(result.Url.ToLower().Contains("home"));
        }
Пример #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);
        }
        public void Assign_BadStartDate_ReturnsIndexView()
        {
            // Arrange
            _volunteerService.Setup(x => x.FindByUserId(It.IsAny<int>())).Returns(new Person());
            _disaster.Setup(x => x.AssignToVolunteer(
                It.IsAny<int>(),
                It.IsAny<int>(),
                It.IsAny<DateTime>(),
                It.IsAny<DateTime>(),
                It.IsAny<int>())).Throws(new ArgumentException(""));

            // Act
            var viewModel = new VolunteerViewModel { SelectedStartDate = DateTime.Today.AddDays(-1) };
            var response = _controllerUnderTest.Assign(viewModel);

            // Assert
            var view = response as ViewResult;
            Assert.IsTrue(view.ViewName.Equals("Index"));
            Assert.IsTrue(view.ViewData.ModelState.Count >= 1);
        }
Пример #10
0
        private VolunteerViewModel GetDefaultViewModel(VolunteerViewModel viewModel = null)
        {
            var person = _volunteerSvc.FindByUserId(_webSecurity.CurrentUserId);
            var commitments = (person != null) ?
                _volunteerSvc.RetrieveCommitments(person.Id, true) :
                new List<Commitment>().AsEnumerable();

            var model = new VolunteerViewModel
            {
                Disasters = _disasterSvc.GetActiveList(),
                MyCommitments = commitments
            };
            if (viewModel != null)
            {
                model.SelectedDisasterId = viewModel.SelectedDisasterId;
                model.SelectedStartDate = viewModel.SelectedStartDate;
                model.SelectedEndDate = viewModel.SelectedEndDate;
            }

            return model;
        }
Пример #11
0
        public ActionResult RemoveResource(VolunteerViewModel model)
        {
            if (!ModelState.IsValid)
                return View("Index", GetDefaultViewModel(model));

            try
            {
                var person = _volunteerSvc.FindByUserId(_webSecurity.CurrentUserId);
                if (!person.OrganizationId.HasValue)
                {
                    throw new ArgumentException("Signed in User is not part of an Organization");
                }

                var resources = _adminService.GetResourceCheckinsForOrganization(person.OrganizationId.Value);

                var resource = resources.FirstOrDefault(r => r.ResourceId == model.RemoveResourceId);
                if (resource == null)
                {
                    throw new ArgumentException("Resource supplied is not yours.");
                }

                _disasterSvc.RemoveResourceById(resource.ResourceId);

                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;

            return View("Index", modelToReturn);
        }
Пример #12
0
        public void RemoveCommitmentById_NotYourCommitment_ReturnsIndexView()
        {
            // Arrange
            _volunteerService.Setup(x => x.FindByUserId(It.IsAny<int>())).Returns(new Person());

            // Act
            var viewModel = new VolunteerViewModel { RemoveCommitmentId = int.MinValue };
            var response = _controllerUnderTest.RemoveCommitment(viewModel);

            // Assert
            var view = response as ViewResult;
            Assert.IsTrue(view.ViewName.Equals("Index"));
            Assert.IsTrue(view.ViewData.ModelState.Count >= 1);
        }
Пример #13
0
        private VolunteerViewModel GetDefaultViewModel(VolunteerViewModel viewModel = null)
        {
            var person = _volunteerSvc.FindByUserId(_webSecurity.CurrentUserId);

            var commitments = (person != null) ?
                _volunteerSvc.RetrieveCommitments(person.Id, true) :
                new List<Commitment>().AsEnumerable();

            var resources = (person != null && person.OrganizationId.HasValue) ?
                _adminService.GetResourceCheckinsForOrganization(person.OrganizationId.Value) :
                new List<Resource>().AsEnumerable();

            var resourceTypes = _adminService.GetResourceTypes();

            var commitmentForToday = commitments.FirstOrDefault(x => x.StartDate <= DateTime.Today && DateTime.Today <= x.EndDate);

            var clusterCoordinators = (commitmentForToday != null && commitmentForToday.ClusterId.HasValue) ?
                 _clusterCoordinatorService.GetAllCoordinatorsForCluster(commitmentForToday.ClusterId.Value).ToList() :
                new List<ClusterCoordinator>().AsEnumerable();


            List<AvailableAction> availableActions = new List<AvailableAction>();
            if (commitmentForToday != null)
            {
                if (commitmentForToday.Status != CommitmentStatus.Here)
                {
                    availableActions.Add(new AvailableAction
                    {
                        ActionName = "Checkin",
                        ButtonText = "Check-in",
                        Description = " Start helping now!",
                        ButtonId = "check-in-button"
                    });
                }
                if (commitmentForToday.Status == CommitmentStatus.Planned)
                {
                    availableActions.Add(new AvailableAction
                    {
                        ActionName = "ReportDelay",
                        ButtonText = "Delayed",
                        Description = " I'll be there when I can.",
                        ButtonId = "delayed-button",
                        FormId = "delayed-form"
                    });
                }
                if (commitmentForToday.Status == CommitmentStatus.Here)
                {
                    availableActions.Add(new AvailableAction
                    {
                        ActionName = "Checkout",
                        ButtonText = "Check-out",
                        Description = " Thank you for your help today!",
                        ButtonId = "check-out-button"
                    });
                }
                if (commitmentForToday.Status != CommitmentStatus.Unavailable)
                {
                    availableActions.Add(new AvailableAction
                    {
                        ActionName = "ReportUnavailable",
                        ButtonText = "Unavailable",
                        Description = " I can't help you at this time.",
                        ButtonId = "unavailable-button"
                    });
                }
            }

            var model = new VolunteerViewModel
            {
                Disasters = _disasterSvc.GetActiveList(),
                DisasterClusters = _disasterClusterSvc.GetClustersForADisaster(0),
                MyCommitments = commitments,
                MyOrgResources = resources,
                ResourceTypes = resourceTypes,
                AvailableActions = availableActions,
                VolunteerTypes = _volunteerTypes.GetList(),
                Person = person,
                ClusterCoordinators = clusterCoordinators
            };

            if (viewModel != null)
            {
                model.SelectedDisasterId = viewModel.SelectedDisasterId;
                model.SelectedStartDate = viewModel.SelectedStartDate;
                model.SelectedEndDate = viewModel.SelectedEndDate;
                model.SelectedClusterId = viewModel.SelectedClusterId;

                model.Description = viewModel.Description;
                model.Qty = viewModel.Qty;
                model.SelectedResourceTypeId = viewModel.SelectedResourceTypeId;
                model.ResourceStartDate = viewModel.ResourceStartDate;
                model.ResourceEndDate = viewModel.ResourceEndDate;

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

            return model;
        }
Пример #14
0
        public void RemoveCommitmentById_Valid_RedirectsToHome()
        {
            // Arrange
            var commitments = new List<Commitment>() { new Commitment() { Id = 7, PersonId = 13, ClusterId = 1, DisasterId = 1}};

            _volunteerService.Setup(service => service.FindByUserId(It.IsAny<int>())).Returns(new Person() { Id = 13 });
            _volunteerService.Setup(service => service.RetrieveCommitments(13, true)).Returns(commitments.AsQueryable());

            // Act
            var viewModel = new VolunteerViewModel { RemoveCommitmentId = 7 };
            var response = _controllerUnderTest.RemoveCommitment(viewModel);

            // Assert
            var result = response as RedirectResult;
            Assert.IsTrue(result.Url.ToLower().Contains("home"));
        }
Пример #15
0
        public void Assign_ValidDateRange_RedirectsToHome()
        {
            // Arrange
            _volunteerService.Setup(x => x.FindByUserId(It.IsAny<int>())).Returns(new Person());

            // Act
            var viewModel = new VolunteerViewModel { SelectedStartDate = DateTime.Today.AddDays(1) };
            var response = _controllerUnderTest.Assign(viewModel);

            // Assert
            var result = response as RedirectResult;
            Assert.IsTrue(result.Url.ToLower().Contains("home"));
        }
        public void RemoveCommitmentById_Valid_RedirectsToHome()
        {
            // Arrange

            var commitments = new List<Commitment>() { new Commitment() { Id = 7, PersonId = 13}};
            var disaster = new Mock<IDisaster>();
            var volunteer = new Mock<IVolunteerService>();
            var webSecurity = new Mock<IWebSecurityWrapper>();
            volunteer.Setup(service => service.FindByUserId(It.IsAny<int>())).Returns(new Person() { Id = 13 });
            volunteer.Setup(service => service.RetrieveCommitments(13, true)).Returns(commitments.AsQueryable());
            var controller = new HomeController(disaster.Object, volunteer.Object, webSecurity.Object);

            // Act
            var viewModel = new VolunteerViewModel { RemoveCommitmentId = 7 };
            var response = controller.RemoveCommitment(viewModel);

            // Assert
            var result = response as RedirectResult;
            Assert.IsTrue(result.Url.ToLower().Contains("home"));
        }
Пример #17
0
        private VolunteerViewModel GetDefaultViewModel(VolunteerViewModel viewModel = null)
        {
            var person = _volunteerSvc.FindByUserId(_webSecurity.CurrentUserId);
            var commitments = (person != null) ?
                _volunteerSvc.RetrieveCommitments(person.Id, true) :
                new List<Commitment>().AsEnumerable();
            var commitmentForToday = commitments.FirstOrDefault(x => x.StartDate <= DateTime.Today && DateTime.Today <= x.EndDate);

            var clusterCoordinators =  (commitmentForToday != null && commitmentForToday.ClusterId.HasValue) ?
                 _clusterCoordinatorService.GetAllCoordinatorsForCluster(commitmentForToday.ClusterId.Value).ToList() :
                new List<ClusterCoordinator>().AsEnumerable();

            var model = new VolunteerViewModel
            {
                Disasters = _disasterSvc.GetActiveList(),
                DisasterClusters = _disasterClusterSvc.GetClustersForADisaster(0),
                MyCommitments = commitments,
                VolunteerTypes = _volunteerTypes.GetList(),
                Person = person,
                ClusterCoordinators = clusterCoordinators
            };

            if (viewModel != null)
            {
                model.SelectedDisasterId = viewModel.SelectedDisasterId;
                model.SelectedStartDate = viewModel.SelectedStartDate;
                model.SelectedEndDate = viewModel.SelectedEndDate;
                model.SelectedClusterId = viewModel.SelectedClusterId;

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

            return model;
        }
        public void RemoveCommitmentById_NotYourCommitment_ReturnsIndexView()
        {
            // Arrange
            var disaster = new Mock<IDisaster>();
            var volunteer = new Mock<IVolunteerService>();
            var webSecurity = new Mock<IWebSecurityWrapper>();
            volunteer.Setup(service => service.FindByUserId(It.IsAny<int>())).Returns(new Person());
            var controller = new HomeController(disaster.Object, volunteer.Object, webSecurity.Object);

            // Act
            var viewModel = new VolunteerViewModel { RemoveCommitmentId = int.MinValue };
            var response = controller.RemoveCommitment(viewModel);

            // Assert
            var view = response as ViewResult;
            Assert.IsTrue(view.ViewName.Equals("Index"));
            Assert.IsTrue(view.ViewData.ModelState.Count >= 1);
        }