Пример #1
0
        public async Task <ICollection <int> > GetAllYearsAsync(string user, long group)
        {
            var models = await _repository.GetAllAsync();

            var results = models
                          .Where(g => g.GroupId.Equals(group) && g.Group.GroupUser.Any(gu => gu.UserId.Equals(user)))
                          .Select(x => x.Date.Year)
                          .Distinct()
                          .OrderBy(x => x);

            return(_mapper.Map <ICollection <int> >(results));
        }
Пример #2
0
        public async Task <IEnumerable <Entities.Expense> > GetAllAsync()
        {
            var x = await _expenseRepository.GetAllAsync();

            var orderByIds = x.OrderBy(o => o.Id).ToList();

            return(orderByIds);
        }
Пример #3
0
        public async Task <ActionResult <IEnumerable <Expense> > > GetExpenses([FromQuery] int?CategoryId = null)
        {
            if (CategoryId != null)
            {
                var expenses = await _expenseRepository.GetByCategoryIdAsync(CategoryId.Value);

                return(expenses.ToList());
            }
            return((await _expenseRepository.GetAllAsync()).ToList());
        }
Пример #4
0
        public async Task <IEnumerable <CategorySummary> > AllSummariesAsync()
        {
            // get all categories & expenses
            var myCategories = await _categoryRepository.GetAllAsync();

            var myExpenses = await _expenseRepository.GetAllAsync();

            // generate summaries
            List <CategorySummary> summaries = new List <CategorySummary>();

            foreach (var category in myCategories)
            {
                var thisMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                var summary   = new CategorySummary
                {
                    Category         = category,
                    TotalSpentAmount = myExpenses
                                       .Where(x => x.CategoryId == category.Id)
                                       .Select(x => x.Amount)
                                       .Sum(),
                    TotalBoughtCount = myExpenses
                                       .Where(x => x.CategoryId == category.Id)
                                       .ToList()
                                       .Count,
                    ThisMonthSpentAmount = myExpenses
                                           .Where(x => x.CategoryId == category.Id)
                                           .Where(x => x.Date >= thisMonth)
                                           .Select(x => x.Amount)
                                           .Sum(),
                    ThisMonthBoughtCount = myExpenses
                                           .Where(x => x.CategoryId == category.Id)
                                           .Where(x => x.Date >= thisMonth)
                                           .ToList()
                                           .Count
                };
                summaries.Add(summary);
            }
            return(summaries);
        }
Пример #5
0
 public async Task <ActionResult <ExpenseListDto> > Get()
 {
     return(new ExpenseListDto(await _expenseRepository.GetAllAsync()));
 }
Пример #6
0
        public async Task <IActionResult> GetAllExpense()
        {
            var expenses = await _expenseRepository.GetAllAsync();

            return(Ok(expenses.WrapResponse(Request.Path)));
        }
Пример #7
0
 // GET: Expenses
 public async Task <ViewResult> Index(int id, string sortBy, int?page)
 {
     return(View(await _expenseRepository.GetAllAsync(id, page, sortBy)));
 }