Exemple #1
0
        /// <summary>
        /// Remove individuals from type based on cohort
        /// </summary>
        /// <param name="RemoveIndividuals"></param>
        /// <param name="ActivityName"></param>
        /// <param name="UserName"></param>
        public void Remove(object RemoveIndividuals, string ActivityName, string UserName)
        {
            OtherAnimalsTypeCohort cohortToAdd  = RemoveIndividuals as OtherAnimalsTypeCohort;
            OtherAnimalsTypeCohort cohortexists = Cohorts.Where(a => a.Age == cohortToAdd.Age & a.Gender == cohortToAdd.Gender).First();

            if (cohortexists == null)
            {
                // tried to remove individuals that do not exist
                throw new Exception("Tried to remove individuals from " + this.Name + " that do not exist");
            }
            else
            {
                cohortexists.Number -= cohortToAdd.Number;
                cohortexists.Number  = Math.Max(0, cohortexists.Number);
            }

            LastCohortChanged = cohortToAdd;
            ResourceTransaction details = new ResourceTransaction();

            details.Debit            = cohortToAdd.Number * -1;
            details.Activity         = ActivityName;
            details.Reason           = UserName;
            details.ResourceType     = this.Name;
            details.ExtraInformation = cohortToAdd;
            LastTransaction          = details;
            TransactionEventArgs eargs = new TransactionEventArgs();

            eargs.Transaction = LastTransaction;
            OnTransactionOccurred(eargs);
        }
Exemple #2
0
        /// <summary>
        /// Add individuals to type based on cohort
        /// </summary>
        /// <param name="AddIndividuals"></param>
        /// <param name="ActivityName"></param>
        /// <param name="UserName"></param>
        public void Add(object AddIndividuals, string ActivityName, string UserName)
        {
            OtherAnimalsTypeCohort cohortToAdd = AddIndividuals as OtherAnimalsTypeCohort;

            OtherAnimalsTypeCohort cohortexists = Cohorts.Where(a => a.Age == cohortToAdd.Age & a.Gender == cohortToAdd.Gender).FirstOrDefault();

            if (cohortexists == null)
            {
                // add new
                Cohorts.Add(cohortToAdd);
            }
            else
            {
                cohortexists.Number += cohortToAdd.Number;
            }

            LastCohortChanged = cohortToAdd;
            ResourceTransaction details = new ResourceTransaction();

            details.Credit           = cohortToAdd.Number;
            details.Activity         = ActivityName;
            details.Reason           = UserName;
            details.ResourceType     = this.Name;
            details.ExtraInformation = cohortToAdd;
            LastTransaction          = details;
            TransactionEventArgs eargs = new TransactionEventArgs();

            eargs.Transaction = LastTransaction;
            OnTransactionOccurred(eargs);
        }