public Task <bool> Handle(UpdateExpenseCommand command) { var entity = _expenseRepository.Get(command.Id); if (entity == null) { AddNotification("despesa", "Despesa não localizada"); return(Task.FromResult(false)); } entity.Update( new Description(command.Description), _favoredRepository.Get(command.Favored), new Money(command.Value) ); AddNotifications(entity); if (Invalid) { return(Task.FromResult(false)); } _expenseRepository.Update(entity); _uow.Commit(); return(Task.FromResult(true)); }
public void ExpenseUpdateTest() { Expense expense = null; using (var lifetime = container.BeginLifetimeScope()) { IExpenseRepository expenseRepository = lifetime.Resolve <IExpenseRepository>(); DefaultCommandBus commandBus = lifetime.Resolve <DefaultCommandBus>(); IMappingEngine mapper = lifetime.Resolve <IMappingEngine>(); expense = expenseRepository.Get(c => c.Amount == 120); Assert.IsNotNull(expense, "Error: Expense was not found"); expense.Amount = 150; } using (var lifetime = container.BeginLifetimeScope()) { IExpenseRepository expenseRepository = lifetime.Resolve <IExpenseRepository>(); DefaultCommandBus commandBus = lifetime.Resolve <DefaultCommandBus>(); IMappingEngine mapper = lifetime.Resolve <IMappingEngine>(); CreateOrUpdateExpenseCommand command = mapper.Map <CreateOrUpdateExpenseCommand>(expense); ICommandHandler <CreateOrUpdateExpenseCommand> commnadHandler = lifetime.Resolve <ICommandHandler <CreateOrUpdateExpenseCommand> >(); ICommandResult result = commandBus.Submit(command, commnadHandler); Assert.IsNotNull(result, "Error: Expense was not updated"); Assert.IsTrue(result.Success, "Error: Expense was not updated"); } }
public async Task <ExpenseListViewModel> Upload(IFormFile fileForm, string fileName, int expenseId) { var viewModel = new ExpenseListViewModel(); try { var expense = await _expenseRepository.Get(expenseId); if (fileForm != null && fileForm.Length > 0) { using (var ms = new MemoryStream()) { fileForm.CopyTo(ms); var fileRawData = ms.ToArray(); var salesDocument = new SalesDocumentForm() { ExpenseId = expenseId, Name = fileName, FileRawData = fileRawData }; await _salesDocumentRepository.Create(salesDocument); } } viewModel.VirtualAccountId = expense.VirtualAccountId; viewModel.Expenses = await _expenseRepository.GetAll(expense.VirtualAccountId); } catch (Exception e) { viewModel.Error = new GackoError(e); } return(viewModel); }
public async Task <ExpenseModel> Get(int id) { var expense = await _expenseRepository.Get(id); expense.SalesDocuments = await _salesDocumentRepository.GetAll(expense.Id); return(expense); }
public void ExpenseGetTest() { using (var lifetime = container.BeginLifetimeScope()) { IExpenseRepository expenseRepository = lifetime.Resolve <IExpenseRepository>(); Expense expense = expenseRepository.Get(c => c.Amount == 120); Assert.IsNotNull(expense, "Error: Expense was not found"); } }
public void DeleteExpense(string expenseC) { var expenseToRemove = _expenseRepository.Get(c => c.ExpenseC == expenseC); if (expenseToRemove != null) { _expenseRepository.Delete(expenseToRemove); SaveExpense(); } }
public async Task <ActionResult <Expense> > GetExpense(int id) { var expense = await _repository.Get(id); if (expense == null) { return(NotFound()); } return(expense); }
public async Task <IActionResult> GetExpense(int id) { var expense = await _repository.Get(id); if (expense == null) { return(NotFound()); } var AR = await _authorizationService.AuthorizeAsync(HttpContext.User, expense, "Permission"); if (!AR.Succeeded) { return(Forbid()); } var expenseDto = _mapper.Map <ExpenseDto>(expense); return(Ok(expenseDto)); }
public override IActionResult Get(long id) { try { var data = _repo.Get(id); return(Ok(data)); } catch (Exception ex) { return(Ok(new { status = -1, message = ex.Message })); } }
public void UpdateExpense(Expense e) { var existingExpense = expenseRepository.Get(x => x.ExpenseId == e.ExpenseId && x.ExpenseStoryId == e.ExpenseStoryId); if (existingExpense != null) { existingExpense.Amount = e.Amount; if (!string.IsNullOrEmpty(e.CustomExpenseCategoryId)) { existingExpense.CustomExpenseCategoryId = e.CustomExpenseCategoryId; } expenseRepository.Update(existingExpense); SaveExpense(); } }
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, OperationAuthorizationRequirement requirement, ExpenseDto resourceDto) { if (context.User == null || resourceDto == null) { return; } var resource = await _repository.Get(resourceDto.Id); if (resource == null) { return; } var userId = context.User.Claims.FirstOrDefault(c => c.Type == "UserId"); if (resource.OwnerId.ToString() == userId.Value) { context.Succeed(requirement); } }
public SaveResultModel <Expense> CreateExpense(Expense model) { if (!_expenseValidator.Validate(model, out var errorMessages)) { return(new SaveResultModel <Expense> { Success = false, Model = model, ErrorMessages = errorMessages }); } var alreadyExists = _expenseRepository.Get(g => g.Description == model.Description && g.CurrentAmount == model.CurrentAmount && g.InitialAmount == model.InitialAmount && g.Payer == model.Payer) != null; if (alreadyExists) { return(new SaveResultModel <Expense> { Success = false, Model = model, ErrorMessages = new List <string> { "A expense with the same description, amount and payer already exists." } }); } _expenseRepository.Add(model); _unitOfWork.Commit(); return(new SaveResultModel <Expense> { Success = true, Model = model, ErrorMessages = errorMessages }); }
public List <Expense> Get() { return(expensesRepository.Get()); }
// GET: Expense/Details/5 public ActionResult Details(int id) { return(View(_expenseRepository.Get(id))); // wyszukuje element o podanym id }
public ExpenseDto GetExpense(int teamId) { var aggregate = _expenseRepository.Get(teamId); return(null); }
public IEnumerable <Expense> GetAllIncoming(DateTime startTime, DateTime endTime) { return(_repository .Get(x => x.Label, x => x.Payment) .Where(x => x.IsIncoming && x.Data >= startTime && x.Data < endTime)); }
public async Task <IActionResult> GetExpense(int idExpense) { var expense = await _expenseRepository.Get(idExpense); return(Ok(expense)); }
public IExpenseDetails GetAll(int userId) { return(GetExpenseDetails(_expenseRepository.Get(userId))); }