Exemplo n.º 1
0
        private ApiResponse Update(int id, UpdateTransactionViewModel model)
        {
            var apiResp = new ApiResponse
            {
                Type = ResponseType.Fail
            };

            _transactionBusiness.OwnerId = GetUserId().Value;

            var transaction = new Dto.Transaction
            {
                Id             = id,
                TypeId         = model.TypeId.Value,
                Amount         = model.Amount.Value,
                Description    = model.Description,
                AttachmentName = model.AttachmentName,
                IsDebt         = _transactionBusiness.IsDebtTransaction(model.TypeId.Value),
                Date           = model.Date,
                ModifiedAt     = DateTime.UtcNow
            };

            var resp = _transactionBusiness.Edit(transaction);

            if (resp.Type != ResponseType.Success)
            {
                apiResp.ErrorCode = resp.ErrorCode;
                return(apiResp);
            }

            apiResp.Type = ResponseType.Success;
            return(apiResp);
        }
Exemplo n.º 2
0
        public IActionResult Update(int id)
        {
            var courierId         = _transactionService.GetCourierIdForTransaction(id);
            var updateTransaction = new UpdateTransactionViewModel {
                TransactionId = id, CourierId = courierId
            };

            return(View(updateTransaction));
        }
Exemplo n.º 3
0
        public bool UpdateTransaction(UpdateTransactionViewModel updateView)
        {
            var vTransaction = Utilities.CopyEntityFields <UpdateTransactionViewModel, ValidatedTransactions>(updateView);

            _context.ValidatedTransactions.Add(vTransaction);

            var transaction = _context.Transactions.Find(updateView.TransactionId);

            transaction.Status = TransactionStatus.Delivered;
            _context.Transactions.Update(transaction);

            return(_context.SaveChanges() > 0);
        }
Exemplo n.º 4
0
        public IActionResult Put([FromRoute] IdViewModel idModel, [FromBody] UpdateTransactionViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(GetModelStateErrorResponse(ModelState)));
            }

            var resp = Update(idModel.Id, model);

            if (resp.Type != ResponseType.Success)
            {
                return(BadRequest(resp));
            }

            return(Ok(resp));
        }
        public async Task <IActionResult> UpdateTransaction([FromForm] UpdateTransactionViewModel transactionModel)
        {
            if (transactionModel == null)
            {
                return(BadRequest("Object of type transaction is null"));
            }
            if (!ModelState.IsValid)
            {
                return(View(transactionModel));
            }
            else
            {
                try
                {
                    var transaction = await transactionService.GetTransactionById(transactionModel.Id);

                    if (transaction == null)
                    {
                        return(NotFound($"Transaction with id {transactionModel.Id} not find"));
                    }
                    else
                    {
                        var updatedTransaction = UpdateTransactionToTransactionDTOMapper.Instance.MapBack(transactionModel);

                        var result = await transactionService.UpdateTransaction(updatedTransaction);

                        if (result.IsError)
                        {
                            ModelState.AddModelError("", result.Message);
                            return(View(transactionModel));
                        }
                        return(RedirectToAction("Error", "Home", result.Message));
                    }
                }
                catch (DbUpdateException ex)
                {
                    logger.LogError($"Unable to update transaction becuase of {ex.Message}");
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                    return(View(transactionModel));
                }
            }
        }
Exemplo n.º 6
0
        public IActionResult Update(UpdateTransactionViewModel updateTransaction)
        {
            var success = _transactionService.UpdateTransaction(updateTransaction);

            return(RedirectToIndex(success));
        }