public async Task <AddExpenseResponseModel> AddExpense(AddExpenseModel addExpense) { var expense = new Expenditures() { UserId = addExpense.UserId, Amount = addExpense.Amount, Description = addExpense.Description, ExpDate = addExpense.ExpDate, Remarks = addExpense.Remarks }; var createdexpense = await _expenseRepository.AddAsync(expense); // map user object to UserRegisterResponseModel object var createdExpResponse = new AddExpenseResponseModel { UserId = createdexpense.UserId, Amount = createdexpense.Amount, Description = createdexpense.Description, ExpDate = createdexpense.ExpDate, Remarks = createdexpense.Remarks }; return(createdExpResponse); }
public async Task <IActionResult> Add([FromBody] ExpenseViewModel expenseViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = _userManager.GetUserId(User); if (userId == null) { return(StatusCode(401)); } Expense newExpense = new Expense() { Sum = expenseViewModel.Sum, Note = expenseViewModel.Note, CategoryId = expenseViewModel.CategoryId, Date = expenseViewModel.Date, UserId = userId }; if (await _repository.AddAsync(newExpense)) { return(StatusCode(201)); } else { return(StatusCode(500)); } }
public async Task <IActionResult> Add([FromBody] ExpenseViewModel expenseViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Expense newExpense = new Expense() { Sum = expenseViewModel.Sum, Note = expenseViewModel.Note, CategoryId = expenseViewModel.CategoryId, Date = expenseViewModel.Date, //TODO изменить userId UserId = "userid123123" }; if (await _repository.AddAsync(newExpense)) { return(StatusCode(201)); } else { return(StatusCode(500)); } }
public async Task Handle(Command request, CancellationToken cancellationToken) { var expense = _expenseFactory.CreateFrom(ExpenseType.CashExpense, request.Value, request.ExpenseDate, null, null, null, request.Details1, request.Details2, null); await _expenseRepository.AddAsync(expense); await _expenseRepository.SaveChangesAsync(); }
public async Task AddExpenseAsync(Guid budgetId, string title, decimal value, DateTime date) { if (!_budgetRepository.IsBudgetExist(budgetId)) { throw new ServiceExceptions(ServiceErrorCodes.BudgetNotExist, "Cannot relate Income with Budget that doesn't exist"); } await _expenseRepository.AddAsync(new Expense(title, value, date, budgetId)); }
public async Task Handle(CashWithdrawalAdded notification, CancellationToken cancellationToken) { var expense = await _expenseService.CreateExpenseWhen(notification); if (expense != null) { await _expenseRepository.AddAsync(expense); await _expenseRepository.SaveChangesAsync(); } }
public async Task <IActionResult> Create([Bind("Id,Amount,Date,Comment,CategoryId")] Expense expense) { if (ModelState.IsValid && await _expenseRepository.AddAsync(expense) != null) { await _expenseRepository.SaveAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(await _categoryRepository.GetAllAsync(), "Id", "Name", expense.CategoryId); return(View(expense)); }
public async Task <ActionResult <Expense> > PostExpense(ExpenseDTO expense) { var item = await _expenseRepository.AddAsync(BaseEntity.CreateFrom <Expense>(expense)); if (item != null) { await _expenseRepository.SaveAsync(); return(CreatedAtAction("GetExpense", new { id = item.Id }, item)); } return(BadRequest()); }
public async Task <int> Add(Expense expense) { if (expense == null) { throw new ArgumentNullException("expense"); } var expenseId = await _expenseRepository.AddAsync(expense); await this.NotifyToManagers(expenseId); return(expenseId); }
public async Task <ExpenseManageModel> AddAsync(string user, ExpenseAddModel model) { if (model == null) { return(null); } // label already test the group is valid var labelModel = await _labelService.GetByIdAsync(user, model.LabelId); if (labelModel == null) { throw new KeyNotFoundException(); } var objToAdd = _mapper.Map <ExpenseModel>(model); _unitOfWork.BeginTransaction(); var objAdded = await _repository.AddAsync(objToAdd); var result = await _unitOfWork.CommitAsync(); return(result > 0 ? _mapper.Map <ExpenseManageModel>(objAdded) : null); }
public async Task Handle(PosPaymentAdded notification, CancellationToken cancellationToken) { var expenseRecipient = await _expenseRecipientService.AddPosTerminalWhen(notification); if (expenseRecipient != null) { await _expenseRecipientRepository.SaveChangesAsync(); } var expense = await _expenseService.CreateExpenseWhen(notification); if (expense != null) { await _expenseRepository.AddAsync(expense); await _expenseRepository.SaveChangesAsync(); } }
public async Task <int> Add(Expense expense) { if (expense == null) { throw new ArgumentNullException("expense"); } var expenseId = await _expenseRepository.AddAsync(expense); var createdExpense = await _expenseRepository.GetAsync(expenseId); //notify to managers var managersChannels = await _notificationChannelRepository.GetManagersChannelsAsync(); foreach (var notificationChannel in managersChannels) { _notificationService.NewExpenseAdded(notificationChannel, createdExpense); } return(expenseId); }
public async Task Handle(BankTransferAdded notification, CancellationToken cancellationToken) { var savingsTransaction = await _savingsService.CreateSavingsTransactionWhen(notification); if (savingsTransaction != null) { await _savingsTransactionRepository.AddAsync(savingsTransaction); await _savingsTransactionRepository.SaveChangesAsync(); } else { var expense = await _expenseService.CreateExpenseWhen(notification); if (expense != null) { await _expenseRepository.AddAsync(expense); await _expenseRepository.SaveChangesAsync(); } } }
public async Task AddExpenseToCompanyAsync(Expense expense) { await _expenseRepository.AddAsync(expense); await _unitOfWork.CompleteAsync(); }