public async Task <IActionResult> CreateExpense(CreateExpenseViewModel createExpense) { string userId = _userManager.GetUserId(User); if (ModelState.IsValid) { if (createExpense.SumByn < await _balanceService.GetBalance(userId, createExpense.Date)) { Expense expense = _mapper.Map <Expense>(createExpense); expense.UserId = _userManager.GetUserId(User); await _balanceService.AddExpense(expense); return(RedirectToAction("Index")); } else { ModelState.AddModelError("CreateExpense.Sum", "Не достаточно средств"); } } List <IncomeCategory> incomeCategory = await _balanceService.GetUserIncomeCategories(userId); List <ExpenseCategory> expenseCategory = await _balanceService.GetUserExpenseCategories(userId); IEnumerable <Currency> currency = await _balanceService.GetCurrency(); SelectList currencySelectList = new SelectList(currency, "Id", "Code"); CreateIncomeViewModel createIncomeViewModel = new CreateIncomeViewModel { Categories = new SelectList(incomeCategory, "Id", "Title"), Currencies = currencySelectList }; createExpense.Categories = new SelectList(expenseCategory, "Id", "Title"); createExpense.Currencies = currencySelectList; IReadOnlyList <Income> incomes = await _balanceService.GetUserIncomes(userId, ""); IReadOnlyList <Expense> expenses = await _balanceService.GetUserExpenses(userId, ""); var operations = _mapper.Map <IReadOnlyList <Income>, List <OperationViewModel> >(incomes); operations.AddRange(_mapper.Map <IReadOnlyList <Expense>, List <OperationViewModel> >(expenses)); BalanceViewModel balanceViewModel = new BalanceViewModel { CreateIncome = createIncomeViewModel, CreateExpense = createExpense, Operations = operations.OrderBy(x => x.Date).ToList(), SortOperations = new SortOperationsViewModel(SortState.DateTimeAsc) }; return(View("Index", balanceViewModel)); }
public async Task <IActionResult> Index(string searchString, SortState sortOrder = SortState.DateTimeDesc) { string userId = _userManager.GetUserId(User); List <IncomeCategory> incomeCategory = await _balanceService.GetUserIncomeCategories(userId); List <ExpenseCategory> expenseCategory = await _balanceService.GetUserExpenseCategories(userId); IEnumerable <Currency> currency = await _balanceService.GetCurrency(); SelectList currencySelectList = new SelectList(currency, "Id", "Code"); CreateIncomeViewModel createIncomeViewModel = new CreateIncomeViewModel { Categories = new SelectList(incomeCategory, "Id", "Title"), Currencies = currencySelectList }; CreateExpenseViewModel createExpenseViewModel = new CreateExpenseViewModel { Categories = new SelectList(expenseCategory, "Id", "Title"), Currencies = currencySelectList }; IReadOnlyList <Income> incomes = await _balanceService.GetUserIncomes(userId, searchString); IReadOnlyList <Expense> expense = await _balanceService.GetUserExpenses(userId, searchString); var operations = _mapper.Map <IReadOnlyList <Income>, List <OperationViewModel> >(incomes); operations.AddRange(_mapper.Map <IReadOnlyList <Expense>, List <OperationViewModel> >(expense)); operations = sortOrder switch { SortState.DateTimeDesc => operations.OrderByDescending(s => s.Date).ToList(), SortState.CategoryAsc => operations.OrderBy(s => s.Category).ToList(), SortState.CategoryDesc => operations.OrderByDescending(s => s.Category).ToList(), SortState.SumAsc => operations.OrderBy(s => s.SumByn).ToList(), SortState.SumDesc => operations.OrderByDescending(s => s.SumByn).ToList(), _ => operations.OrderBy(s => s.Date).ToList(), }; BalanceViewModel balanceViewModel = new BalanceViewModel { CreateIncome = createIncomeViewModel, CreateExpense = createExpenseViewModel, Operations = operations, SearchString = searchString, SortOperations = new SortOperationsViewModel(sortOrder) }; return(View(balanceViewModel)); }
public ActionResult Income(CreateIncomeViewModel model) { try { return(null); } catch (Exception e) { this.HandleError(e); return(this.JsonError(data: null, message: ValidationResources.Generic_Error)); } }
public ActionResult Income() { var model = new CreateIncomeViewModel(); return(View(model)); }