Exemplo n.º 1
0
        /// <summary>
        /// Remove individuals from type based on cohort
        /// </summary>
        /// <param name="removeIndividuals"></param>
        /// <param name="activity"></param>
        /// <param name="reason"></param>
        public void Remove(object removeIndividuals, CLEMModel activity, string reason)
        {
            OtherAnimalsTypeCohort cohortToRemove = removeIndividuals as OtherAnimalsTypeCohort;
            OtherAnimalsTypeCohort cohortexists   = Cohorts.Where(a => a.Age == cohortToRemove.Age && a.Gender == cohortToRemove.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 -= cohortToRemove.Number;
                cohortexists.Number  = Math.Max(0, cohortexists.Number);
            }

            LastCohortChanged = cohortToRemove;
            ResourceTransaction details = new ResourceTransaction
            {
                Loss             = cohortToRemove.Number,
                Activity         = activity,
                Reason           = reason,
                ResourceType     = this,
                ExtraInformation = cohortToRemove
            };

            LastTransaction = details;
            TransactionEventArgs eargs = new TransactionEventArgs
            {
                Transaction = LastTransaction
            };

            OnTransactionOccurred(eargs);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Remove individuals from type based on cohort
        /// </summary>
        /// <param name="RemoveIndividuals"></param>
        /// <param name="ActivityName"></param>
        /// <param name="Reason"></param>
        public void Remove(object RemoveIndividuals, string ActivityName, string Reason)
        {
            OtherAnimalsTypeCohort cohortToRemove = RemoveIndividuals as OtherAnimalsTypeCohort;
            OtherAnimalsTypeCohort cohortexists   = Cohorts.Where(a => a.Age == cohortToRemove.Age & a.Gender == cohortToRemove.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 -= cohortToRemove.Number;
                cohortexists.Number  = Math.Max(0, cohortexists.Number);
            }

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

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

            eargs.Transaction = LastTransaction;
            OnTransactionOccurred(eargs);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add individuals to type based on cohort
        /// </summary>
        /// <param name="addIndividuals"></param>
        /// <param name="activity"></param>
        /// <param name="reason"></param>
        public new void Add(object addIndividuals, CLEMModel activity, string reason)
        {
            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
            {
                Gain             = cohortToAdd.Number,
                Activity         = activity,
                Reason           = reason,
                ResourceType     = this,
                ExtraInformation = cohortToAdd
            };

            LastTransaction = details;
            lastGain        = cohortToAdd.Number;
            TransactionEventArgs eargs = new TransactionEventArgs
            {
                Transaction = LastTransaction
            };

            OnTransactionOccurred(eargs);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add individuals to type based on cohort
        /// </summary>
        /// <param name="AddIndividuals"></param>
        /// <param name="ActivityName"></param>
        /// <param name="Reason"></param>
        public void Add(object AddIndividuals, string ActivityName, string Reason)
        {
            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           = Reason;
            details.ResourceType     = this.Name;
            details.ExtraInformation = cohortToAdd;
            LastTransaction          = details;
            TransactionEventArgs eargs = new TransactionEventArgs();

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