예제 #1
0
        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));
        }
예제 #2
0
 public async Task Update(string accountName, long id, [FromBody] UpdateExpenseCommand cmd)
 {
     accountName     = Uri.UnescapeDataString(accountName);
     cmd.AccountName = accountName;
     cmd.UserName    = this.currentUser.Name;
     cmd.Id          = id;
     await this.mediator.Send(cmd);
 }
예제 #3
0
        public async Task <IActionResult> UpdateExpense([FromRoute] long id, [FromBody] UpdateExpenseCommand command)
        {
            command.Id = id;
            var response = await _mediator.Send <ResultResponse <ExpenseDTO> >(command);

            if (response.IsSuccess)
            {
                return(Ok(response.Result));
            }
            return(BadRequest(response.ErrorMessage));
        }
예제 #4
0
        public async Task <IActionResult> Update(int id, [FromBody] UpdateExpenseCommand command)
        {
            var result = await _handler.Handle(command);

            if (!_handler.Valid)
            {
                return(BadRequest(_handler.Notifications));
            }

            return(Ok(result));
        }
예제 #5
0
        public async Task <IActionResult> PatchExpense(string id, UpdateExpenseCommand expense)
        {
            if (id != expense.Id)
            {
                return(BadRequest());
            }

            await _mediator.Send(expense);

            return(NoContent());
        }
        public async Task <IActionResult> UpdateExpense(int expenseId, ExpenseForUpdateDto expenseForUpdateDto)
        {
            var command = new UpdateExpenseCommand(expenseId, expenseForUpdateDto);
            var result  = await Mediator.Send(command);

            if (result)
            {
                return(NoContent());
            }

            throw new Exception($"Update Expense {expenseId} failed on save.");
        }
        public async Task <ActionResult> UpdateExpense(int id, ExpenseCreateUpdateDto dto)
        {
            var command = new UpdateExpenseCommand(id, dto);
            var result  = await _mediator.Send(command);

            if (result == null)
            {
                return(NotFound());
            }
            else if (result == false)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
예제 #8
0
        public async Task <ActionResult <Guid> > UpdateExpense([FromRoute] Guid id,
                                                               [FromBody] UpdateExpenseCommand updateExpenseCommand, CancellationToken cancellationToken)
        {
            var userId = User.GetClaim("id");

            if (userId == null)
            {
                return(Forbid());
            }

            updateExpenseCommand.Id      = id;
            updateExpenseCommand.OwnerId = new Guid(userId.Value);

            var result = await _mediator.Send(updateExpenseCommand, cancellationToken);

            return(Ok(result));
        }
예제 #9
0
        public async Task <ICommandResult> Handle(UpdateExpenseCommand command)
        {
            ICommandResult result = null;

            try
            {
                var expense = await _expenseRepository.GetById(command.Id);

                command.Adapt(expense);
                await _expenseRepository.Update(expense);

                return(new MessageResult("Item updated"));
            }
            catch (Exception ex)
            {
                AddNotification("UpdateExpenseCommand", ex.Message);
            }

            return(result);
        }
예제 #10
0
        public async Task <IActionResult> Put(UpdateExpenseCommand command, CancellationToken cancellationToken)
        {
            var result = await _mediator.Send(command, cancellationToken);

            return(Ok(result));
        }
예제 #11
0
        public async Task <ActionResult> Update(UpdateExpenseCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }