Exemplo n.º 1
0
        public async Task <IEnumerable <ExpensesViewModel> > GetExpenses(UserProfile user, int?shopId, DateTime from, DateTime to)
        {
            var list = new List <ExpensesViewModel>();
            IEnumerable <Expense> expenses = null;

            var avl = _shopsChecker.CheckAvailability(user, shopId);

            if (!avl.isCorrectShop)
            {
                return(new List <ExpensesViewModel>());
            }
            ;
            if (!avl.hasShop && avl.isAdmin)
            {
                expenses = await _expRepo.GetExpensesAsync(user.business_id.Value, null, from, to);
            }
            else if (!avl.hasShop && !avl.isAdmin)
            {
                return(new List <ExpensesViewModel>());
            }
            else if (avl.hasShop)
            {
                expenses = await _expRepo.GetExpensesAsync(user.business_id.Value, shopId.Value, from, to);
            }

            if (expenses == null || !expenses.Any())
            {
                return(new List <ExpensesViewModel>());
            }
            ;



            foreach (var group in expenses)
            {
                var expensesViewModel = new ExpensesViewModel {
                    id = group.id, reportDate = group.report_date, totalSum = group.sum, shopId = group.shop_id
                };

                var dict = new List <ExpensesValueViewModel>();
                foreach (var ed in group.ExpensesDetails)
                {
                    dict.Add(new ExpensesValueViewModel
                    {
                        id    = ed.expenses_type_id,
                        key   = ed.ExpensesType.type,
                        value = ed.sum
                    });
                }

                expensesViewModel.expenses = dict;
                list.Add(expensesViewModel);
            }

            return(list);
        }
Exemplo n.º 2
0
        public async Task <Dictionary <string, decimal> > GetMonthExpensesAsync(int shopId, UserProfile user)
        {
            var dt         = DateTime.Now;
            var resultDict = new Dictionary <string, decimal>();
            var business   = user.business_id.Value;
            int?shop       = 0;

            if (shopId == 0 && user.shop_id == null)
            {
                shop = null;
            }
            else
            {
                shop = shopId;
            }

            var expenses = await expRepo.GetExpensesAsync(business, shop, new DateTime(dt.Year, dt.Month, 1), dt);

            var expTypes = await expTypeRepo.GetAllAsync();

            foreach (var exp in expenses)
            {
                foreach (var expDetail in exp.ExpensesDetails)
                {
                    if (!resultDict.ContainsKey(expDetail.ExpensesType.type))
                    {
                        resultDict.Add(expDetail.ExpensesType.type, expDetail.sum);
                    }
                    else
                    {
                        resultDict[expDetail.ExpensesType.type] += expDetail.sum;
                    }
                }
            }

            return(resultDict);
        }
Exemplo n.º 3
0
 public async Task <IEnumerable <ExpenseDto> > GetExpensesAsync()
 {
     return((await _expensesRepository.GetExpensesAsync()).Select(expense => expense.AsDto()));
 }
        public async Task <IEnumerable <ExpenseDto> > GetExpensesAsync()
        {
            var expenses = repository.GetExpensesAsync();

            return((await expenses).Select(expense => expense.AsDto()));
        }