コード例 #1
0
ファイル: Snapshot.cs プロジェクト: terjeknutsen/Budgee
        private DailyAmount CalculateDaily()
        {
            if (period == null)
            {
                return(DailyAmount.FromDecimal(0m));
            }
            var income = totalIncome?.Amount ?? 0m;
            var outgo  = totalOutgo?.Amount ?? 0m;
            var daily  = Math.Round(((income - outgo) / period.Days), 2);

            return(DailyAmount.FromDecimal(daily));
        }
コード例 #2
0
ファイル: Snapshot.cs プロジェクト: terjeknutsen/Budgee
        protected override void When(object @event)
        {
            switch (@event)
            {
            case Events.DailyBudgetCreated e:
                ParentId  = new DailyBudgetId(e.Id);
                Id        = new SnapshotId(Guid.NewGuid());
                Daily     = DailyAmount.FromDecimal(0m);
                Available = Available.FromDecimal(0m);
                break;

            case Events.PeriodAddedToDailyBudget e:
                period = Period.Create(e.Start, e.End);
                SetPeriod(e.EntryDate);
                break;

            case Events.PeriodStartChanged e:
                period = Period.Create(e.Start, period.ToB);
                SetPeriod(e.EntryDate);
                break;

            case Events.PeriodEndChanged e:
                period = Period.Create(period.FromA, e.End);
                SetPeriod(e.EntryDate);
                break;

            case Events.IncomeAddedToDailyBudget e:
                SetTotalIncome(Amount.FromDecimal(e.TotalIncome), e.EntryDate);
                break;

            case Events.IncomeRemoved e:
                SetTotalIncome(Amount.FromDecimal(e.TotalIncome), e.EntryDate);
                break;

            case Events.IncomeAmountChanged e:
                SetTotalIncome(Amount.FromDecimal(e.TotalIncome), e.EntryDate);
                break;

            case Events.OutgoAddedToDailyBudget e:
                SetTotalOutgo(Amount.FromDecimal(e.TotalOutgo), e.EntryDate);
                break;

            case Events.OutgoRemoved e:
                SetTotalOutgo(Amount.FromDecimal(e.TotalOutgo), e.EntryDate);
                break;

            case Events.OutgoAmountChanged e:
                SetTotalOutgo(Amount.FromDecimal(e.TotalOutgo), e.EntryDate);
                break;

            case Events.ExpenditureAdded e:
                SetTotalExpenditures(Amount.FromDecimal(e.TotalExpenditure), e.EntryDate);
                break;

            case Events.ExpenditureAmountChanged e:
                SetTotalExpenditures(Amount.FromDecimal(e.TotalExpenditure), e.EntryDate);
                break;

            case Events.SnapshotChanged e:
                Daily     = DailyAmount.FromDecimal(e.Daily);
                Available = Available.FromDecimal(e.Available);
                break;
            }
        }