public async Task Create(TransactionCreateModel newT, int user_id) { AccountsUserModel acc = new AccountsUserModel() { IdARS = _unitOfWork.Accounts.GetAccountId(user_id, "ARS") }; if (acc.IdARS == null || acc.IdARS <= 0 || user_id <= 0) { throw new CustomException(404, "No se pudo obtener alguno de los datos del usuario"); } var saldo = _accountBusiness.GetAccountBalance(user_id, "ARS"); if ((newT.Type.ToLower() == "payment") && (saldo - newT.Amount < 0)) { throw new CustomException(400, "No hay saldo suficiente para realizar la transacción"); } Transactions transaction = _mapper.Map <Transactions>(newT); transaction.AccountId = (int)acc.IdARS; _unitOfWork.Transactions.Insert(transaction); await _unitOfWork.Complete(); }
public ActionResult Create(TransactionCreateModel model) { try { ModelState.Remove("Item.Name"); ModelState.Remove("Item.Description"); if (ModelState.IsValid) { model.Transaction.BuyerId = WebSecurity.CurrentUserId; model.Transaction.ItemId = model.Item.ItemId; model.Transaction.StatusId = 1; model.Transaction.DateCreated = DateTime.Now; model.Transaction.DateModified = DateTime.Now; db.Transactions.Add(model.Transaction); db.SaveChanges(); ViewBag.ReturnUrl = Url.Action("Index", "Transaction"); return(View("Success")); } model.Item = db.Items.Find(model.Item.ItemId); model.MethodList = new SelectList(db.Methods, "MethodId", "Name"); model.MyItems = db.Items.Where(m => m.UserId == WebSecurity.CurrentUserId); return(View(model)); } catch { return(View("Error")); } }
public ActionResult UnsafeTransaction(TransactionCreateModel model) { if (model.Priv == null) { return(Json(_api.Api.SendTransaction(new CreateTransactionModel(model)))); } else { byte[] Private; try { Private = Base58CheckEncoding.DecodePlain(model.Priv); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.Forbidden; return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } try { return(Json(_api.Api.SendTransaction(new CreateTransactionModel(model), Private))); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.Forbidden; return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } } }
public async Task <TransactionCreateModel> GetCreateModel() { using (var uow = UnitOfWorkFactory.Create()) { var Model = new TransactionCreateModel(); return(Model); } }
public async Task <IActionResult> Create([FromBody] TransactionCreateModel newT) { //solo transacciones en ARS try { var user_id = int.Parse(User.Claims.First(i => i.Type == "UserId").Value); await _transactionBusiness.Create(newT, user_id); return(StatusCode(201)); } catch (Exception) { throw; } }
public async Task <TransactionCreateModel> GetCreateModel() { using (var uow = UnitOfWorkFactory.Create()) { var Model = new TransactionCreateModel(); Model.Operations = Mapper.Map <List <OperationIndexModel> >(await uow.Operations.GetAllAsync()); Model.Projects = Mapper.Map <List <ProjectIndexModel> >(await uow.Projects.GetAllAsync()); Model.Scores = Mapper.Map <List <ScoreIndexModel> >(await uow.Scores.GetAllAsync()); Model.counterParties = Mapper.Map <List <CounterPartyIndexModel> >(await uow.CounterParties.GetAllAsync()); return(Model); } }
public async Task AddTransactionsShouldBeHandled() { const string csvString = @"“Invoice777”,”600.00”,”EUR”,”10/17/2019 02:04:59”, “Done”"; var csvDataStream = new MemoryStream(Encoding.UTF8.GetBytes(csvString)); const string csvDatePattern = "dd/MM/yyyy hh:mm:ss"; var publicId = "Invoice777"; var code = "EUR"; var status = "D"; var amount = 600; var date = DateTimeOffset.ParseExact("10/17/2019 02:04:59", csvDatePattern, CultureInfo.InvariantCulture); var entity = new Transaction { PublicId = publicId, Amount = amount, Date = date, Code = code, Status = status }; var model = new TransactionCreateModel { PublicId = publicId, Amount = amount, Date = date, Code = code, Status = status }; var entities = new List <Transaction> { entity }; var models = new List <TransactionCreateModel> { model }; var parseResults = new ParseResults(models); _transactionsParserProviderMock.Setup(x => x.GetParser(csvDataStream)).ReturnsAsync(_transactionsDataParser.Object); _transactionsDataParser.Setup(x => x.CanParseData(csvDataStream)).ReturnsAsync(true); _transactionsDataParser.Setup(x => x.ParseAllFile()).ReturnsAsync(parseResults); _mapperMock.Setup(x => x.Map <IEnumerable <Transaction> >(models)).Returns(entities); _transactionRepositoryMock.Setup(x => x.Add(entity)); await _transactionsService.AddTransactions(csvDataStream); _transactionsParserProviderMock.Verify(x => x.GetParser(csvDataStream), Times.Once); _transactionsDataParser.Verify(x => x.CanParseData(csvDataStream), Times.Once); _transactionsDataParser.Verify(x => x.ParseAllFile(), Times.Once); _mapperMock.Verify(x => x.Map <IEnumerable <Transaction> >(models), Times.Once); _transactionRepositoryMock.Verify(x => x.Add(entity), Times.Once); }
public ActionResult Transaction(TransactionCreateModel model) { Response.Headers.Add("content-type", "application/json"); try { return(Json(_api.Api.SendTransaction(new CreateTransactionModel(model), model.Priv))); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.Forbidden; return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } }
public ActionResult CreatePervStr(TransactionCreateModel model) { Response.Headers.Add("content-type", "application/json"); try { model.Priv = BitConverter.ToString(_api.Api.GetSignature(new CreateTransactionModel(model))).Replace("-", ""); return(Json(model)); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.Forbidden; return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } }
public static int CreateTransactionConsole(string accountNum, int transactionType) { int accountId = GetAccountIdFromAccountNumberForConsole(accountNum); TransactionCreateModel transaction = new TransactionCreateModel { AccountID = accountId, TransactionType = transactionType, CreatedUtc = DateTime.Now }; int transactionId = CreateTransactionService().CreateTransaction(transaction); return(transactionId); }
public int CreateTransaction(TransactionCreateModel model) { using (var ctx = new BankEntities()) { var entity = new Transaction { TransactionType = model.TransactionType, AccountID = model.AccountID }; ctx.Transactions.Add(entity); ctx.SaveChanges(); return(entity.TransactionID); } }
public async Task <Response> Create(TransactionCreateModel model, ClaimsPrincipal User) { using (var uow = UnitOfWorkFactory.Create()) { var _User = await UserManager.FindByNameAsync(User.Identity.Name); if (!uow.Scores.Check(model.ScoreId)) { 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 = "В транзакции указан несуществующий проект!" }); } var Score = await uow.Scores.GetByIdAsync(model.ScoreId); var Operation = await uow.Operations.GetByIdAsync(model.OperationId); if (!validateSum(model.Sum, Score.Balance, Operation.OperationTypeId)) { return(new Response { Status = StatusEnum.Error, Message = "На счету недостаточно денег!" }); } model.UserId = _User.Id; var Transaction = Mapper.Map <Transaction>(model); await uow.Transactions.CreateAsync(Transaction); return(new Response { Status = StatusEnum.Accept, Message = "Транзакция успешно создана." }); } }
// itemId represent id of item to be bought // GET: /Transaction/Create?{itemId} public ActionResult Create(int itemId) { var item = db.Items.Find(itemId); var methodList = new SelectList(db.Methods, "MethodId", "Name"); var transaction = new Transaction(); var myItems = db.Items.Where(m => m.UserId == WebSecurity.CurrentUserId); var vm = new TransactionCreateModel() { Item = item, MyItems = myItems, MethodList = methodList, Transaction = transaction }; return(View(vm)); }
public async Task <ActionResult <TransactionExcelModel> > Create(TransactionCreateModel model) { var Result = await TransactionService.Create(model, User); return(Ok(Result)); }
public async Task <IActionResult> Create(TransactionCreateModel model) { var id = await _service.Create(model.CustomerId, model.ProductId, model.Quantity); return(Created(nameof(Create), id)); }