Beispiel #1
0
        public async Task <PlanSummary> GetCurrentPlanSummaryAsync()
        {
            IGenericRepository <Plan> plansRepo = RepositoryFactory.GetGenericRepository <Plan>();
            var filter = new PlansFilter
            {
                PageSize = 1
            };

            filter.SetFilters(GetCurrentPlanCondition());

            IList <Plan> plans = await plansRepo.GetAsync(filter);

            if (plans == null || plans.Count == 0 || plans.Count > 1)
            {
                throw new DocumentNotFoundException("Nie odnaleziono planu budżetowego o wskazanych kryteriach");
            }

            Plan plan = plans.SingleOrDefault();

            if (plan == null)
            {
                throw new DocumentNotFoundException("Nie odnaleziono planu budżetowego o wskazanych kryteriach");
            }

            return(await GetSummaryAsync(plan.Id));
        }
Beispiel #2
0
        public async Task <IList <PlanListItem> > GetAsync(PlansFilter filter)
        {
            IGenericRepository <Plan> repo = RepositoryFactory.GetGenericRepository <Plan>();

            var currentPlanFilter = new PlansFilter
            {
                PageSize = 1
            };

            currentPlanFilter.SetFilters(GetCurrentPlanCondition());

            string currentPlanId = (await repo.GetAsAsync(plan => plan.Id, currentPlanFilter))
                                   .FirstOrDefault();

            var searchFilter      = filter ?? new PlansFilter();
            var filterExpressions = new List <Expression <Func <Plan, bool> > >();

            if (searchFilter.DateTo != null)
            {
                filterExpressions.Add(plan => plan.EndDate == null || plan.EndDate <= searchFilter.DateTo);
            }

            if (searchFilter.DateFrom != null)
            {
                filterExpressions.Add(plan => plan.StartDate == null || plan.StartDate >= searchFilter.DateFrom);
            }

            searchFilter.SetFilters(filterExpressions.ToArray());

            Expression <Func <Plan, PlanListItem> > planSummaryMapExpression = plan => new PlanListItem
            {
                Id          = plan.Id,
                StartDate   = plan.StartDate,
                EndDate     = plan.EndDate,
                IncomesSum  = plan.Incomes.Sum(income => income.Amount),
                ExpensesSum = plan.Expenses.Sum(expense => expense.Amount),
                IsActive    = plan.Id == currentPlanId
            };

            return(await repo.GetAsAsync(planSummaryMapExpression, searchFilter));
        }
Beispiel #3
0
        public override async Task InsertAsync(Plan document)
        {
            IGenericRepository <Plan> repo = RepositoryFactory.GetGenericRepository <Plan>();
            var filter = new PlansFilter
            {
                PageSize = 1
            };

            filter.SetFilters(plan => document.StartDate <= plan.StartDate);

            IList <Plan> existingCurrentPlans = await repo.GetAsync(filter);

            if (existingCurrentPlans.Any())
            {
                throw new DuplicateNameException("Już istnieje plan budżetowy dla wybranego okresu");
            }

            await SyncCategoriesAsync <IncomeCategory>(document);
            await SyncCategoriesAsync <ExpenseCategory>(document);

            await repo.InsertAsync(document);
        }