Example #1
0
        public async Task <EntityResult> UpdateVolunteer(VolunteerViewModel volunteerModel)
        {
            try
            {
                var volunteer = await _volunteerUnitOfWork.VolunteerRepository.GetVolunteerById(volunteerModel.Id);

                Guard.ArgumentIsNull <ArgumentException>(volunteer, nameof(volunteer), VolunteerResource.VolunteerNotFound);
                volunteer.Update(volunteerModel.Name
                                 , volunteerModel.Email, volunteerModel.Phone
                                 , volunteerModel.CityId
                                 , volunteerModel.DistrictId);
                volunteer.Gender  = (Domain.Model.Genders)volunteerModel.Gender;
                volunteer.HasCar  = volunteerModel.HasCar;
                volunteer.Address = volunteerModel.Address;
                volunteer.Notes   = volunteerModel.Notes;


                await _volunteerUnitOfWork.VolunteerRepository.UpdateVolunteer(volunteer);

                await _volunteerUnitOfWork.SaveAsync();

                return(EntityResult.Success);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                throw;
            }
        }
Example #2
0
        public async Task <ActionResult> Create(VolunteerViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var entityResult = await _volunteerService.AddVolunteer(model);

                    if (entityResult.Succeeded)
                    {
                        AddMessageToTempData(CommonResources.SavedSuccessfullyMessage
                                             , BusinessSolutions.MVCCommon.MessageType.Success);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        foreach (var error in entityResult.ValidationErrors)
                        {
                            ModelState.AddModelError("", error.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.Logger.Error(ex);
                AddMessageToView(CommonResources.UnExpectedError
                                 , BusinessSolutions.MVCCommon.MessageType.Error);
            }

            GetRoles();
            return(View(model));
        }
Example #3
0
        public IActionResult Edit(VolunteerViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (ConfigurationManager.AppSettings.IsTrialVersion)
            {
                response.SetIsTrial();
                return(Ok(response));
            }
            using (_dbContext)
            {
                var entity = _dbContext.SystemUser.FirstOrDefault(x => x.SystemUserUuid == model.SystemUserUuid);
                entity.RealName = model.RealName;
                entity.Phone    = model.Phone;
                entity.AddTime  = model.AddTime;
                if (!string.IsNullOrEmpty(entity.AddTime))
                {
                    entity.AddTime = DateTime.Parse(model.AddTime).ToString("yyyy-MM-dd");
                }
                else
                {
                    entity.AddTime = model.AddTime;
                }
                _dbContext.SaveChanges();
                return(Ok(response));
            }
        }
        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()));
            }
        }
        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 clusterCoordinators = (person != null && person.ClusterId.HasValue) ?
                                      _clusterCoordinatorService.GetAllCoordinatorsForCluster(person.ClusterId.Value).ToList() :
                                      new List <ClusterCoordinator>().AsEnumerable();

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

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

            return(model);
        }
Example #6
0
 public VolunteerViewModel Update(VolunteerViewModel volunteerViewModel)
 {
     _uow.BeginTransaction();
     _volunteerService.Update(_mapper.Map <VolunteerViewModel, Volunteer>(volunteerViewModel));
     _uow.Commit();
     return(volunteerViewModel);
 }
Example #7
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));
        }
        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);
        }
Example #9
0
        public VolunteerViewModel Add(VolunteerViewModel volunteerViewModel)
        {
            var volunteer = _mapper.Map <VolunteerViewModel, Volunteer>(volunteerViewModel);

            _volunteerService.Add(volunteer);
            return(volunteerViewModel);
        }
Example #10
0
        public void RemoveCommitmentById_Valid_RedirectsToHome()
        {
            // Arrange
            var commitments = new List <Commitment>()
            {
                new Commitment()
                {
                    Id = 7, PersonId = 13
                }
            };

            _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"));
        }
Example #11
0
        private VolunteerDTO Create(VolunteerViewModel viewModel)
        {
            try
            {
                log.Debug(VolunteerViewModel.FormatVolunteerViewModel(viewModel));

                VolunteerDTO volunteer = new VolunteerDTO();

                // copy values
                viewModel.UpdateDTO(volunteer, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                volunteer.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                volunteer.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_volunteerService.AddVolunteer - " + VolunteerDTO.FormatVolunteerDTO(volunteer));

                int id = _volunteerService.AddVolunteer(volunteer);

                volunteer.VolunteerId = id;

                log.Debug("result: 'success', id: " + id);

                return(volunteer);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Example #12
0
        /// <summary>
        /// Get Volunteer by id
        /// </summary>
        /// <param name="id">Volunteer id</param>
        /// <returns>Volunteer json view model</returns>
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_volunteerService.GetVolunteer - volunteerId: " + id + " ");

                var volunteer = new VolunteerViewModel(_volunteerService.GetVolunteer(id));

                log.Debug("_volunteerService.GetVolunteer - " + VolunteerViewModel.FormatVolunteerViewModel(volunteer));

                log.Debug("result: 'success'");

                //return Json(volunteer, JsonRequestBehavior.AllowGet);
                //return Content(JsonConvert.SerializeObject(volunteer), "application/json");
                //return volunteer;
                //return JsonConvert.SerializeObject(volunteer);
                return(Ok(volunteer));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
        public IActionResult Volunteer(VolunteerViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!volunteerRepository.CheckUniqueEmail(viewModel.Email))
            {
                volunteerRepository.Add(new VolunteerModel()
                {
                    VolunteerId = viewModel.VolunteerId,
                    FirstName   = viewModel.FirstName,
                    LastName    = viewModel.LastName,
                    Email       = viewModel.Email,
                    Age         = viewModel.Age,
                    Description = viewModel.Description
                });

                ViewBag.message = "Your registration was successful!";
            }
            else
            {
                ViewBag.message = "You already used this email to submit this form!";
            }

            return(View(viewModel));
        }
Example #14
0
        public void Assign_BadDateRange_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(""));

            _webSecurity.SetupGet(x => x.CurrentUserId).Returns(10);

            // 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);
        }
Example #15
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));
        }
Example #16
0
        public ActionResult _GrpVolunteerList(int grpId)
        {
            var vols     = db.Groups.Find(grpId).Volunteers.ToList().OrderByDescending(v => v.RegTime);
            var volViews = VolunteerViewModel.GetVolunteerViews(vols);

            return(View(new GridModel(volViews)));
        }
Example #17
0
        public VolunteerViewModel Update(VolunteerViewModel volunteerViewModel)
        {
            var volunteer = _mapper.Map <VolunteerViewModel, Volunteer>(volunteerViewModel);

            _volunteerService.Update(volunteer, volunteer.Id);
            return(volunteerViewModel);
        }
Example #18
0
        public ActionResult Create()
        {
            var model = new VolunteerViewModel();

            GetRoles();
            return(View(model));
        }
        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"));
        }
        public IActionResult Dashboard()
        {
            List <Volunteer>   V   = volunteerRepo.AddRoles();
            VolunteerViewModel vol = new VolunteerViewModel(V);

            return(View(vol));
        }
Example #21
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));
        }
        public ActionResult _OrgVolunteerList(int orgId)
        {
            var vols     = db.Organizations.Find(orgId).Volunteers.ToList().OrderByDescending(v => v.RegTime);
            var volViews = VolunteerViewModel.GetVolunteerViews(vols);

            return(View(new GridModel(volViews)));
        }
        public ActionResult _ShowOrgVolunteers(int orgId)
        {
            var vols     = db.Organizations.Find(orgId).Volunteers.ToList().OrderByDescending(v => v.RegTime);
            var volViews = VolunteerViewModel.GetVolunteerViews(vols);

            ViewBag.orgId = orgId;
            return(View(volViews));
        }
Example #24
0
        public ActionResult _ShowGrpVolunteers(int grpId)
        {
            var vols     = db.Groups.Find(grpId).Volunteers.ToList().OrderByDescending(v => v.RegTime);
            var volViews = VolunteerViewModel.GetVolunteerViews(vols);

            ViewBag.grpId = grpId;
            return(View(volViews));
        }
Example #25
0
        /// <summary>
        ///  Returns the List of Volunteers
        /// </summary>
        /// <returns></returns>
        public VolunteerViewModel Index()
        {
            var myData = new VolunteerViewModel();

            myData.VolunteerList = repository.Index();

            return(myData);
        }
Example #26
0
        public ActionResult VolunteerEditProfile(Volunteer volunteer, int locationId)
        {
            ViewBag.LocationId = locationId;
            var locations            = lookUpRepository.GetLocations();
            var organizations        = lookUpRepository.GetOrganizations();
            VolunteerViewModel model = new VolunteerViewModel(locations, organizations);

            model.Volunteer = volunteer;
            return(View("EditVolunteerProfile", model));
        }
Example #27
0
        /// <summary>
        /// This is the details of the selected volunteer that the user has chosen
        /// This allows them to select what position that they are volunteering for
        /// </summary>
        /// <param name="id">The id associated with the selected user</param>
        /// <returns>A view that has details of the user and allows the to submit thier record and position</returns>
        public ActionResult VolunteerDetails(int?id)
        {
            IEnumerable <Volunteer> volunteer = new List <Volunteer>();

            volunteer = db.Volunteers.Where(v => v.volunteerID == id).ToList();
            VolunteerViewModel         volunteerViewModel         = new VolunteerViewModel(volunteer, db.Ethnicities.ToList());
            VolunteerPositionViewModel volunteerPositionViewModel = new VolunteerPositionViewModel(volunteerViewModel, db.Positions.ToList());

            return(View(volunteerPositionViewModel));
        }
        public ActionResult _SaveVolunteerAjaxEditing(int id)
        {
            var volunteer = db.Volunteers.Find(id);
            var volView   = new VolunteerViewModel(volunteer);

            TryUpdateModel(volView);
            volView.UpdateVolunteerModel(volunteer);
            db.Entry(volunteer).State = EntityState.Modified;
            db.SaveChanges();
            return(_OrgVolunteerList(volunteer.OrganizationId));
        }
Example #29
0
        public async Task <ViewResult> Edit(Guid Id)
        {
            var volunteers = await _volunteerService.GetIncompleteVolunteersAsync();

            var model = new VolunteerViewModel()
            {
                Volunteers = volunteers
            };

            return(View(model.Volunteers.FirstOrDefault(v => v.Id == Id)));
        }
Example #30
0
        public async Task <IActionResult> Index()
        {
            var volunteers = await _volunteerService.GetIncompleteVolunteersAsync();

            var model = new VolunteerViewModel()
            {
                Volunteers = volunteers
            };

            return(View(model));
        }