예제 #1
0
        public void AssignToVolunteer(int disasterId, int personId, DateTime startDate, DateTime endDate)
        {
            if (DateTime.Compare(endDate, startDate) < 0)
            {
                throw new ArgumentException("endDate cannot be earlier than startDate");
            }

            // check if the start and end date falls within an existing commitment
            // disregard any disasters that are inactive
            Expression <Func <Commitment, bool> > dateInRange = c =>
                                                                (DateTime.Compare(c.StartDate, endDate) <= 0) &&
                                                                (DateTime.Compare(c.EndDate, startDate) >= 0);

            var hasExistingCommitment = (from c in _dataService.Commitments
                                         join d in _dataService.Disasters on c.DisasterId equals d.Id
                                         where d.IsActive && c.PersonId == personId
                                         select c).Any(dateInRange);

            if (hasExistingCommitment)
            {
                throw new ArgumentException("there is already a commitment for this date range");
            }

            _dataService.AddCommitment(new Commitment
            {
                PersonId   = personId,
                DisasterId = disasterId,
                StartDate  = startDate,
                EndDate    = endDate
            });
        }
예제 #2
0
        public void AssignToVolunteer(int disasterId, int personId, DateTime startDate, DateTime endDate,
                                      int volunteerType, int clusterId, string location)
        {
            if (DateTime.Compare(endDate, startDate) < 0)
            {
                throw new ArgumentException("Please enter an end date that is greater than or equal to the start date.");
            }
            if (DateTime.Compare(DateTime.Today, startDate) > 0)
            {
                throw new ArgumentException("Please enter a start date that is greater than or equal to today's date.");
            }

            // check if the start and end date falls within an existing commitment
            // disregard any disasters that are inactive
            Expression <Func <Commitment, bool> > dateInRange = c =>
                                                                (DateTime.Compare(c.StartDate, endDate) <= 0) &&
                                                                (DateTime.Compare(c.EndDate, startDate) >= 0);

            var hasExistingCommitment = (from c in _dataService.Commitments
                                         join d in _dataService.Disasters on c.DisasterId equals d.Id
                                         where d.IsActive && c.PersonId == personId
                                         select c).Any(dateInRange);

            if (hasExistingCommitment)
            {
                throw new ArgumentException("You already have a commitment for this date range.");
            }

            var hasCluster = _dataService.Clusters.Any(c => c.Id == clusterId);

            if (!hasCluster)
            {
                throw new ArgumentException("There is no cluster for this disaster. Please pick a different disaster.");
            }

            _dataService.AddCommitment(new Commitment
            {
                PersonId        = personId,
                DisasterId      = disasterId,
                StartDate       = startDate,
                EndDate         = endDate,
                VolunteerTypeId = volunteerType,
                ClusterId       = clusterId,
                Location        = location
            });
        }
예제 #3
0
        public Commitment AssignToVolunteer(Disaster disaster, Person person, DateTime startDate, DateTime endDate)
        {
            if (disaster == null)
            {
                throw new ArgumentNullException("disaster");
            }
            if (person == null)
            {
                throw new ArgumentNullException("person");
            }
            if (DateTime.Compare(endDate, startDate) < 0)
            {
                throw new ArgumentException("endDate cannot be earlier than startDate");
            }

            // check if the start and end date falls within an existing commitment
            // disregard any disasters that are inactive
            Expression <Func <Commitment, bool> > dateInRange = c =>
                                                                (DateTime.Compare(c.StartDate, startDate) <= 0 && DateTime.Compare(c.EndDate, startDate) >= 0) ||
                                                                (DateTime.Compare(c.StartDate, endDate) <= 0 && DateTime.Compare(c.EndDate, endDate) >= 0);

            var hasExistingCommitment = (from c in ourService.Commitments
                                         join d in ourService.Disasters on c.DisasterId equals d.Id
                                         where d.IsActive
                                         select c).Any(dateInRange);

            if (hasExistingCommitment)
            {
                throw new ArgumentException("there is already a commitment for this date range");
            }

            return(ourService.AddCommitment(new Commitment()
            {
                PersonId = person.Id,
                DisasterId = disaster.Id,
                StartDate = startDate,
                EndDate = endDate
            }));
        }
예제 #4
0
        public Commitment AssignToVolunteer(Disaster disaster, Person person, DateTime startDate, DateTime endDate)
        {
            if (disaster == null)
            {
                throw new ArgumentNullException("disaster");
            }
            if (person == null)
            {
                throw new ArgumentNullException("person");
            }
            if (DateTime.Compare(endDate, startDate) < 0)
            {
                throw new ArgumentException("endDate cannot be earlier than startDate");
            }

            return(ourService.AddCommitment(new Commitment()
            {
                PersonId = person.Id,
                DisasterId = disaster.Id,
                StartDate = startDate,
                EndDate = endDate
            }));
        }