Exemple #1
0
        public async Task <IActionResult> EditRPCs(RentalPurchaseContract model)
        {
            if (ModelState.IsValid)
            {
                var rpc = _context.RentalPurchaseContract.Where(p => p.TransactionId == model.TransactionId).FirstOrDefault();

                rpc.PurchaseDate = model.PurchaseDate;
                rpc.MHAmount     = model.MHAmount;
                rpc.UnitPrice    = model.UnitPrice;
                rpc.DiscountCode = model.DiscountCode;
                rpc.Taxrate      = model.Taxrate;
                rpc.PaymentToken = model.PaymentToken;
                rpc.Currency     = model.Currency;

                var user  = _context.AppUsers.Where(p => p.Id == model.AppUser.Id).FirstOrDefault();
                var batch = _context.MiningInventory.Where(p => p.BatchId == model.Batch.BatchId).FirstOrDefault();

                rpc.AppUser = user;
                rpc.Batch   = batch;

                _context.Update(rpc);
                await _context.SaveChangesAsync();

                StatusMessage = "RPC successfully changed"; // wont work unless implemented in view
                return(RedirectToAction(nameof(RPCs)));
            }
            return(View(model));
        }
Exemple #2
0
        public async Task <IActionResult> Checkout(CheckoutViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(Index()));
                }

                var user = await _userManager.GetUserAsync(User);

                if (user == null)
                {
                    throw new ApplicationException($"Unable to load user with ID '{user.Id}'.");
                }

                // explicity load the user Wallet
                _context.Entry(user).Reference(s => s.Wallet).Load();
                var wallet = user.Wallet;

                if (wallet == null && model.WalletPublicKey != null)
                {
                    // user does not have an associated Wallet but will create one now
                    user.Wallet = new UserWallet
                    {
                        Currency  = model.Cryptocurrency,
                        WalletKey = model.WalletPublicKey
                    };
                }

                // pull BatchOrder information from DB
                var batch = _context.MiningInventory.LastOrDefault();
                if (batch == null || batch.Status != BatchStatus.Waiting)
                {
                    var newBatch = new MiningInventory
                    {
                        Currency = model.Cryptocurrency,
                        MHAmount = 0,
                        Status   = BatchStatus.Waiting
                    };

                    _context.Add(newBatch);
                    batch = newBatch;
                    //await _context.SaveChangesAsync();
                    //batch = _context.MiningInventory.LastOrDefault();
                }

                batch.MHAmount += model.MegaHashPurchased;
                if (batch.MHAmount > 1750)
                {
                    // close status of previous batch
                    batch.Status    = BatchStatus.Pending;
                    batch.OrderDate = DateTime.Now;

                    // create new batch
                    var newBatch = new MiningInventory
                    {
                        Currency = Currencies.Ethereum,
                        MHAmount = 0,
                        Status   = BatchStatus.Waiting
                    };
                    _context.Add(newBatch);
                }

                DiscountCode discount = null;
                if (model.DiscountCode != null)
                {
                    var discountCode = _context.DiscountCodes.Where(p => p.Code == model.DiscountCode);
                    discount = discountCode.LastOrDefault();
                    if (discount != null)
                    {
                        ++discount.NumTimesUsed;
                        _context.DiscountCodes.Update(discount);
                    }
                }

                var order = new RentalPurchaseContract
                {
                    AppUser      = user,
                    PurchaseDate = DateTime.Now,
                    MHAmount     = model.MegaHashPurchased,
                    UnitPrice    = model.MegaHashPriceRate,
                    DiscountCode = discount,
                    Taxrate      = (double)model.PurchaseTaxRate,
                    PaymentToken = model.PaymentToken,
                    Currency     = model.Cryptocurrency,
                    Batch        = batch
                };

                _context.Add(order);
                //user.Status = UserStatus.Pending;


                return(Json(new { success = true }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false }));
            }
        }
Exemple #3
0
        public IActionResult EditRPCs(int Id)
        {
            RentalPurchaseContract contract = _context.RentalPurchaseContract.Include(p => p.AppUser).Include(p => p.Batch).FirstOrDefault(u => u.TransactionId == Id);

            return(View(contract));
        }