public void Transaction_TransactionCreate_ReturnsTransactionIndexView() { var viewModel = new TransactionEditModel() { Transaction = new TransactionDto() { ProductId = 1, ToInventoryId = 1, Quantity = 2, TransactionId = 1 } }; var result = _controller.Create(viewModel) as RedirectToRouteResult; Assert.That(result.RouteValues["Action"], Is.EqualTo("Index")); }
public async Task <IActionResult> Edit(int?id, [FromBody] TransactionEditModel NewTransaction) { try { if (id == null || id <= 0) { throw new CustomException(400, "Id no válido"); } var user_id = int.Parse(User.Claims.First(i => i.Type == "UserId").Value); await _transactionBusiness.Edit(id, NewTransaction, user_id); return(StatusCode(200)); } catch { throw; } }
public void TransactionsController_PostCreateViewModel_DbSetReceivedAddAndContextReceivedSaveChanges() { var viewModel = new TransactionEditModel { Transaction = new TransactionDto() { ProductId = 1, FromInventoryId = 1, ToInventoryId = 2, TransactionId = 1, FromInventory = _inventory } }; _transactionsController.Create(viewModel); _context.Received(1).SaveChanges(); }
public async Task <Response> Edit(TransactionEditModel model, ClaimsPrincipal User) { using (var uow = UnitOfWorkFactory.Create()) { var Transaction = Mapper.Map <Transaction>(model); if (model == null) { return new Response { Status = StatusEnum.Error, Message = "ничего на сервер не отправлено" } } ; if (!uow.Operations.Check(model.OperationId)) { return new Response { Status = StatusEnum.Error, Message = "Нет такого типа операций" } } ; if (!uow.Projects.Check(model.ProjectId)) { return new Response { Status = StatusEnum.Error, Message = "Нет такого проекта!" } } ; if (!uow.Scores.Check(model.ScoreId)) { return new Response { Status = StatusEnum.Error, Message = "Нет такого счета!" } } ; var _User = await UserManager.FindByNameAsync(User.Identity.Name); Transaction.UserId = _User.Id; Transaction.TransactionDate = Transaction.TransactionDate.ToLocalTime(); await uow.Transactions.UpdateAsync(Transaction); return(new Response { Status = StatusEnum.Accept, Message = "Редактирование транзакции прошло успешно." }); } }
public async Task Edit(int?id, TransactionEditModel NewTransaction, int user_id) { AccountsUserModel acc = new AccountsUserModel { IdARS = _unitOfWork.Accounts.GetAccountId(user_id, "ARS"), IdUSD = _unitOfWork.Accounts.GetAccountId(user_id, "USD") }; if (acc.IdUSD == null || acc.IdUSD <= 0 || acc.IdARS == null || acc.IdARS <= 0) { throw new CustomException(404, "No se encontró alguna de las cuentas del usuario"); } var transaction_buscada = _unitOfWork.Transactions.FindTransaction((int)id, (int)acc.IdUSD, (int)acc.IdARS); if (transaction_buscada != null) { if ((bool)transaction_buscada.Category.Editable) { var transactionLog = new TransactionLog { TransactionId = transaction_buscada.Id, NewValue = NewTransaction.Concept }; transaction_buscada.Concept = NewTransaction.Concept; _unitOfWork.TransactionLog.Insert(transactionLog); //inserto el nuevo cambio en transaction log _unitOfWork.Transactions.Update(transaction_buscada); await _unitOfWork.Complete(); return; } else { throw new CustomException(400, "La transacción no es editable"); } } else { throw new CustomException(400, "No se encontró la transacción"); } }
public async Task <IActionResult> Update(TransactionEditModel model) { var transaction = await _transactionService.GetAsync(model.Id); if (transaction == null) { return(NotFound()); } if (ModelState.IsValid) { _mapper.Map(model, transaction); await _transactionService.UpdateAsync(transaction); return(RedirectToAction("Details", new { id = transaction.Id })); } await PrepareModelAsync(model); return(View(model)); }
public async Task <Response> Edit(TransactionEditModel model, ClaimsPrincipal User) { using (var uow = UnitOfWorkFactory.Create()) { var Transaction = Mapper.Map <Transaction>(model); Transaction.Discriminator = "Transaction"; if (model == null) { return new Response { Status = StatusEnum.Error, Message = "ничего на сервер не отправлено" } } ; if (!uow.Operations.Check(model.OperationId)) { return new Response { Status = StatusEnum.Error, Message = "Нет такого типа операций" } } ; if (!uow.Projects.Check(model.ProjectId)) { return new Response { Status = StatusEnum.Error, Message = "Нет такого проекта!" } } ; if (!uow.Scores.Check(model.ScoreId)) { return new Response { Status = StatusEnum.Error, Message = "Нет такого счета!" } } ; Score OldScore = null; Operation OldOperation = null; var Operation = await uow.Operations.GetByIdAsync(model.OperationId); var Score = await uow.Scores.GetByIdAsync(model.ScoreId); var OldIds = uow.Transactions.GetScoreIdAndOperationId(Transaction.Id); var OldSum = uow.FinanceActions.GetSumFinanceAction(Transaction.Id); if (Operation.Id != OldIds.Item1) { OldOperation = await uow.Operations.GetByIdAsync(OldIds.Item1); } if (Score.Id != OldIds.Item2) { OldScore = await uow.Scores.GetByIdAsync(OldIds.Item2); } var HelperModel = new TransactionEditHelperModelBuilder() .SetNewOperationTypeId(Operation.OperationTypeId) .SetOldOperationTypeId(OldOperation != null ? OldOperation.OperationTypeId : Operation.OperationTypeId) .SetNewScore1(Score) .SetOldScore1(OldScore) .SetNewTransactionSum(Transaction.Sum) .SetOldTransactionSum(OldSum) .Build(); var CheckScoreEdit = await RedactAndCheckTransaction(HelperModel); if (!CheckScoreEdit.Item1) { return(new Response { Status = StatusEnum.Error, Message = "На счету недостаточно денег для редактируемой суммы" }); } await uow.Scores.UpdateAsync(Score); if (OldScore != null) { await uow.Scores.UpdateAsync(OldScore); } var _User = await UserManager.FindByNameAsync(User.Identity.Name); Transaction.UserId = _User.Id; Transaction.ActionDate = Transaction.ActionDate; await uow.Transactions.UpdateAsync(Transaction); return(new Response { Status = StatusEnum.Accept, Message = "Редактирование транзакции прошло успешно." }); } }