Example #1
0
        public ActionResult PostTransaction(TransactionCreate model)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44320/api/transaction");
                string token = DeserializeToken();
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);

                var postTask = client.PostAsJsonAsync <TransactionCreate>("transaction", model);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("GetTransaction"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, result.Content.ReadAsStringAsync().Result);
                }
            }

            return(View(model));
        }
Example #2
0
        public ActionResult Create(TransactionCreate transaction)
        {
            if (!ModelState.IsValid)
            {
                return(View(transaction));
            }

            var service         = CreateTransactionService();
            var customerService = CreateCustomerService();
            var productService  = CreateProductService();

            customerService.GetCustomerById(transaction.CustomerId);
            productService.GetProductById(transaction.ProductId);

            ViewBag.CustomerId = new SelectList(customerService.GetCustomers(), "CustomerId", "LastName", transaction.CustomerId);
            ViewBag.ProductId  = new SelectList(productService.GetProducts(), "ProductId", "Name", transaction.ProductId);

            if (service.CreateTransaction(transaction))
            {
                TempData["SaveResult"] = "Transaction record was created.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Transaction record could not be created.");
            return(View(transaction));
        }
Example #3
0
        public bool CreateTransaction(TransactionCreate model)
        {
            var transaction = new Transactions()
            {
                AccountId              = model.AccountId,
                TransactionAmount      = model.TransactionAmount,
                TransactionDate        = DateTimeOffset.UtcNow,
                TransactionDescription = model.TransactionDescription,
                TransactionType        = model.TransactionType
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx
                .Transactions
                .Add(transaction);

                if (ctx.SaveChanges() != 1)
                {
                    return(false);
                }

                var accountService = new AccountService(_userId);

                return
                    (accountService.UpdateAccountBalance(
                         transaction.AccountId,
                         transaction.TransactionAmount));
            }
        }
        // GET: Transaction
        public IActionResult Index()
        {
            var transactions = _transactionService.GetAllTransactions();
            List <TransactionCreate> transactionListView = new List <TransactionCreate>();

            foreach (var item in transactions)
            {
                TransactionCreate model = new TransactionCreate
                {
                    Transaction = item
                };

                if (item.PaymentType == 0)
                {
                    model.NameOfPayment = "Gotówka";
                }
                else
                {
                    model.NameOfPayment = "Karta";
                }

                transactionListView.Add(model);
            }

            return(View(transactionListView));
        }
        public bool CreateTransaction(TransactionCreate model)
        {
            var entity =
                new Transactions()
            {
                BoardId = model.BoardId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #6
0
        //POST Transaction

        public bool CreateTransaction(TransactionCreate model)
        {
            var entity = new Transaction()
            {
                ProductId = model.ProductId,
                IsPaid    = model.IsPaid
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transaction.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public IHttpActionResult Post(TransactionCreate transaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateTransactionService();

            if (!service.CreateTransaction(transaction))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
        public async Task <bool> CreateTransactionAsync(TransactionCreate model)
        {
            var entity =
                new Transaction()
            {
                OrderId = model.OrderId,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(await ctx.SaveChangesAsync() == 1);
            }
        }
        // <summary>
        // Get transaction payload
        // <summary>
        private TransactionCreate GetTransactionPayload()
        {
            if (this.TransactionPayload == null)
            {
                // Line item
                LineItemCreate lineItem1 = new LineItemCreate(
                    name: "Red T-Shirt",
                    uniqueId: "5412",
                    type: LineItemType.PRODUCT,
                    quantity: 1,
                    amountIncludingTax: (decimal)29.95
                    )
                {
                    Sku = "red-t-shirt-123"
                };

                // Customer Billing Address
                AddressCreate billingAddress = new AddressCreate
                {
                    City              = "Winterthur",
                    Country           = "CH",
                    EmailAddress      = "*****@*****.**",
                    FamilyName        = "Customer",
                    GivenName         = "Good",
                    Postcode          = "8400",
                    PostalState       = "ZH",
                    OrganizationName  = "Test GmbH",
                    MobilePhoneNumber = "+41791234567",
                    Salutation        = "Ms"
                };

                this.TransactionPayload = new TransactionCreate(new List <LineItemCreate>()
                {
                    lineItem1
                })
                {
                    Currency = "CHF",
                    AutoConfirmationEnabled = true,
                    BillingAddress          = billingAddress,
                    ShippingAddress         = billingAddress,
                    Language = "en-US",
                    AllowedPaymentMethodConfigurations = new List <long?>()
                    {
                        8656
                    },                                                               // Invoice Payment Method
                    CompletionBehavior = TransactionCompletionBehavior.COMPLETE_DEFERRED
                };
            }
            return(this.TransactionPayload);
        }
        public bool CreateTransaction(TransactionCreate trans)
        {
            var entity = new Transaction()
            {
                Id        = trans.Id,
                Cost      = trans.Cost,
                PersonId  = trans.PersonId,
                ProductId = trans.ProductId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #11
0
        public bool CreateTrans(TransactionCreate model)
        {
            var entity =
                new BBShopTransaction()
            {
                CustomerID = model.CustomerID,
                ProductID  = model.ProductID,
                CreatedUtc = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.BBShopTransactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #12
0
        public int CreateTransaction(TransactionCreate model)
        {
            try
            {
                using (var ctx = new ApplicationDbContext())
                {
                    var entity = new Transaction();
                    //Goes through the list of inputted integers and
                    //a. adds the name of the instrument/accessory associated to a list of integers (like a receipt prints out the names of items purchased
                    //b. adds the price of the item to the subtotal
                    //c. increases the product count of the transaction by 1.
                    List <string> itemList = new List <string>();

                    if (model.AllInstruments != null)
                    {
                        foreach (int number in model.AllInstruments)
                        {
                            Instrument example = ctx.Instruments.Where(e => e.InstrumentId == number).Single();
                            itemList.Add(example.Name);
                            entity.SubTotal     = entity.SubTotal + ctx.Instruments.Where(e => e.InstrumentId == number).Single().Price;
                            entity.ProductCount = entity.ProductCount + 1;
                        }
                    }
                    if (model.AllAccessories != null)
                    {
                        foreach (int number in model.AllAccessories)
                        {
                            Accessory accessory = ctx.Accessories.Where(e => e.AccessoryId == number).Single();
                            itemList.Add(accessory.Name);
                            entity.SubTotal     = entity.SubTotal + ctx.Accessories.Where(e => e.AccessoryId == number).Single().Price;
                            entity.ProductCount = entity.ProductCount + 1;
                        }
                    }


                    entity.ItemsBought       = itemList;
                    entity.CustomerId        = model.CustomerId;
                    entity.DateOfTransaction = DateTime.Now;
                    ctx.Transactions.Add(entity);
                    return(ctx.SaveChanges());
                }
            }
            catch
            {
                return(500);
            }
        }
        // GET: Transaction
        public ActionResult Create()
        {
            TransactionCreate model = new TransactionCreate();

            var products = _db.Products.ToArray();



            model.Products = new SelectList(products, "ProductId", "Name");

            // model.Products = (SelectList) products.Select(p => new SelectListItem() { Value = p.ProductId.ToString(), Text = p.Name });



            model.CustomerId = 1;
            return(View(model));
        }
        public bool CreateTransaction(TransactionCreate model)
        {
            var entity =
                new Transaction()
            {
                VenueID           = model.VenueID,
                DaysRenting       = model.DaysRenting,
                TransactionCost   = model.TransactionCost,
                ApplicationUserID = _userID
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #15
0
        public bool CreateTransaction(TransactionCreate model)
        {
            var entity =
                new Transaction()
            {
                OwnerId           = _userId,
                Price             = model.Price,
                DateOfTransaction = DateTime.Now,
                CustomerId        = model.CustomerId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public bool CreateTransaction(TransactionCreate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = new Transaction()
                {
                    OwnerID         = _userID,
                    ProductID       = model.ProductID,
                    ProductQuantity = model.ProductQuantity,
                    TotalPrice      = ((ctx.Products.Single(e => e.ProductID == model.ProductID)).ProductPrice) * model.ProductQuantity,
                    Purchased       = model.Purchased
                };

                ctx.Transactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #17
0
        public bool CreateTransaction(TransactionCreate model) // Creates a transaction. Nice!
        {
            var entity =
                new Transaction()
            {
                AccountID         = _userID,
                CategoryID        = model.CategoryID,
                Category          = model.Category,
                TransactionAmount = model.TransactionAmount,
                TransactionDate   = model.TransactionDate
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Create(TransactionCreate model)
        {
            if (ModelState.IsValid)
            {
                Transaction transaction = new Transaction()
                {
                    ProductId         = model.ProductId,
                    CustomerId        = model.CustomerId,
                    Quantity          = model.Quantity,
                    DateOfTransaction = DateTimeOffset.Now
                };
                _db.Transactions.Add(transaction);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public bool CreateTransaction(TransactionCreate model)
        {
            var entity =
                new Transaction()
            {
                CreatorId  = _userId,
                ProductId  = model.ProductId,
                Qauntity   = model.Quantity,
                Price      = model.Price,
                CreatedUtc = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public bool CreateTransaction(TransactionCreate transaction)
        {
            var entity =
                new Transaction()
            {
                OwnerId         = _userId,
                Designation     = transaction.Designation,
                CustomerID      = transaction.CustomerId,
                ProductID       = transaction.ProductId,
                IssuerName      = transaction.IssuerName,
                TransactionDate = transaction.TransactionDate
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #21
0
        public async Task <bool> CreateTransaction(TransactionCreate model)
        {
            var entity =
                new Transaction()
            {
                OwnerId        = _userId,
                ItemId         = model.ItemId,
                BorrowerId     = model.BorrowerId,
                LentOutDateUtc = model.LentOutDateUtc,
                ReturnDateUtc  = model.ReturnDateUtc,
                IsReturned     = model.IsReturned
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(await ctx.SaveChangesAsync() == 1);
            }
        }
Example #22
0
        public ActionResult Create(TransactionCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            if (_service.CreateTrans(model))
            {
                TempData["SaveResult"] = "Your transaction was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Transaction could not be created.");

            return(View(model));
        }
        public async Task <ActionResult> Create(TransactionCreate model)
        {
            if (ModelState.IsValid == false)
            {
                return(View(model));
            }

            var transactionService = CreateTransactionService();

            if (await transactionService.CreateTransaction(model))
            {
                TempData["SaveResult"] = "Your transaction was created.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Transaction could not be created");

            return(View(model));
        }
        public ActionResult Create(TransactionCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateTransactionService();

            if (service.CreateTransaction(model))
            {
                TempData["SaveResult"] = "The Transaction you chose was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "The Transaction was not created.");

            return(View(model));
        }
Example #25
0
        public bool CreateTransaction(TransactionCreate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var product = ctx.Products.Single(p => p.ProductId == model.ProductId);

                var transaction = new Transaction()
                {
                    OwnerId   = _userId,
                    ProductId = product.ProductId,
                    Price     = product.Price,
                    Quantity  = model.Quantity,

                    DateOfTransaction = DateTimeOffset.Now
                };
                transaction.OrderCost = product.Price * Convert.ToDecimal(model.Quantity);
                ctx.Transactions.Add(transaction);
                return(ctx.SaveChanges() == 1);
            }
        }
        public bool CreateTransaction(TransactionCreate model)
        {
            var entity =
                new Transaction
            {
                TransactionId   = model.TransactionId,
                ProductId       = model.ProductId,
                CustomerId      = model.CustomerId,
                ProductName     = model.ProductName,
                ProductPrice    = model.ProductPrice,
                ProductQuantity = model.ProductQuantity,
                ProductUpc      = model.ProductUpc,
                TransactionDate = model.TransactionDate
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #27
0
        public bool CreateTransaction(TransactionCreate model)
        {
            var entity = new Transaction()
            {
                TransactionId   = model.TransactionId,
                StoreId         = model.StoreId,
                Store           = model.Store,
                TransactionDate = DateTime.Now,
                DeliveryStreet  = model.DeliveryStreet,
                DeliveryCity    = model.DeliveryCity,
                DeliveryState   = model.DeliveryState,
                DeliveryZip     = model.DeliveryZip,
                OwnerId         = _userId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Transactions.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public async Task <ActionResult> Create(TransactionCreate note)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.CategoryID = await GetTransactionsAsync();

                return(View(note));
            }

            var service = CreateTransactionService();

            if (await service.CreateTransactionAsync(note))
            {
                TempData["SaveResult"] = "Transaction was created.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Transaction could not be created.");
            ViewBag.CategoryID = await GetTransactionsAsync();

            return(View(note));
        }
Example #29
0
        public IHttpActionResult Post(TransactionCreate transaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var prodService = CreateProductService();
            var prodDetail  = prodService.ValidateAuctionStatus(transaction.ProductId);

            if (prodDetail == "Auction is closed")
            {
                var service = CreateTransactionService();

                if (!service.CreateTransaction(transaction))
                {
                    return(InternalServerError());
                }

                return(Ok("Transaction successfully created."));
            }
            return(BadRequest("BadRequest" + prodDetail));
        }
Example #30
0
        public ActionResult Create(TransactionCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateService();

            if (service == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (service.CreateTransaction(model))
            {
                TempData["SaveResult"] = "Your Transaction was created.";
                return(RedirectToAction("Index"));
            }
            ;

            return(View(model));
        }