Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <Entities.Expense> > GetAllAsync()
        {
            var x = await _expenseRepository.GetAllAsync();

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

            return(orderByIds);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
 public async Task <ActionResult <ExpenseListDto> > Get()
 {
     return(new ExpenseListDto(await _expenseRepository.GetAllAsync()));
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> GetAllExpense()
        {
            var expenses = await _expenseRepository.GetAllAsync();

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