public async Task <JObject> GetExpensesAsync(int whouse, UserProfile user) { var expenses = await expensesDataService.GetMonthExpensesAsync(whouse, user); if (!EnumerableExtensions.Any(expenses)) { var expTypes = await expTypeRepo.GetAllAsync(); var dict = new Dictionary <string, decimal>(); foreach (var et in expTypes) { dict.Add(et.type, 0); } return(GetObject(dict)); } return(GetObject(expenses)); }
public async Task <IEnumerable <ExpensesTypeViewModel> > GetExpensesTypes() { var etDal = await repo.GetAllAsync(); var etList = new List <ExpensesTypeViewModel>(); foreach (var et in etDal) { etList.Add( new ExpensesTypeViewModel { id = et.id, value = et.type } ); } return(etList); }
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); }