public IEnumerable <ExpensesJsonModel> GetExpensesForView(int id) { List <ExpensesJsonModel> jsonModels = new List <ExpensesJsonModel>(); var expenses = from e in _context.Expenses join enc in _context.ExpCategories on e.Id equals enc.ExpensesId join c in _context.ExpensesCategories on enc.ExpensesCategoryId equals c.Id where (e.CashAccount.Id == id) select new { Id = e.Id, Amount = e.Amount, Category = c.Name, Note = e.Note, Date = e.Date, CashAccount_Id = e.CashAccount.Id }; foreach (var e in expenses) { var expense = new ExpensesJsonModel() { Id = e.Id, Amount = e.Amount, Category = e.Category, Note = e.Note, Date = e.Date, CashAccount_Id = e.CashAccount_Id }; jsonModels.Add(expense); } return(jsonModels); }
public async Task <HttpResponseMessage> CreateExpens(string url, string accessToken, ExpensesJsonModel content) { var response = await _clientFactory.CreateClient(accessToken) .PostAsJsonAsync(url, content); return(response.EnsureSuccessStatusCode()); }
public async Task <IActionResult> Update(ExpensesJsonModel expensesJson) { if (expensesJson == null) { return(BadRequest()); } if (!_expensesRepository.Exists(expensesJson.Id)) { return(NotFound()); } var expenses = _mapper.Map <ExpensesJsonModel, Expenses>(expensesJson); await _expensesRepository.Update(expenses); return(Ok()); }
public async Task <IActionResult> Create(ExpensesJsonModel expensesJson) { if (expensesJson == null) { return(BadRequest()); } var expensesCategory = await _expensesCategoryRepository.GetItemByName(expensesJson.Category); var expenses = _mapper.Map <ExpensesJsonModel, Expenses>(expensesJson); expenses.Date = DateTime.Now; await _expensesRepository.Create(expenses, expensesJson.CashAccount_Id); await _expensesRepository.CreateComunication( await _expensesRepository.GetItemByDate(expenses.Date), expensesCategory); return(Ok()); }
public async Task <IActionResult> Create(ExpensesViewModel expensesViewModel) { if (ModelState.IsValid) { var accessToken = await HttpContext.GetTokenAsync("access_token"); ExpensesJsonModel expense = _mapper.Map <ExpensesViewModel, ExpensesJsonModel>(expensesViewModel); expense.CashAccount_Id = CashAccount_Id; var result = await _expensesRepository.CreateExpens( "https://localhost:44382/Expenses/Create", accessToken, expense); if (result.IsSuccessStatusCode) { return(RedirectToAction("Index", "Expenses")); } } return(View(expensesViewModel)); }