public async Task <IActionResult> Edit(int id, [Bind("UsersId,Company_Name,Purchased_Amount, Amount_Paid")] StockPurchaseEntry stockPurchaseEntry)
        {
            if (id != stockPurchaseEntry.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(stockPurchaseEntry);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StockPurchaseEntryExists(stockPurchaseEntry.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UsersId"] = new SelectList(_context.Users, "Id", "Id", stockPurchaseEntry.UsersId);
            return(View(stockPurchaseEntry));
        }
        //called to send data after user has updated the chart
        public async Task updateUserData(string socketId, string newShares1, string newShares2, string newShares3, string symbol, string symbol2, string symbol3)
        {
            UsersController dbRead = new UsersController(context: _context);


            var user = await _context.Users.SingleOrDefaultAsync(x => x.Id == ApiDataCalls.curId);


            StockPurchaseEntry UserEntry = new StockPurchaseEntry();

            UserEntry.UsersId = ApiDataCalls.curId;

            for (int i = 1; i <= 3; i++)
            {
                if (i == 1)
                {
                    UserEntry.UsersId          = ApiDataCalls.curId;
                    UserEntry.Company_Name     = symbol;
                    UserEntry.Purchased_Amount = Convert.ToInt32(newShares1);
                    UserEntry.Amount_Paid      = 0;

                    _context.Add(UserEntry);
                    await _context.SaveChangesAsync();

                    // _context.SaveChanges();
                }
                else if (i == 2)
                {
                    UserEntry.UsersId          = ApiDataCalls.curId;
                    UserEntry.Company_Name     = symbol;
                    UserEntry.Purchased_Amount = Convert.ToInt32(newShares1);
                    UserEntry.Amount_Paid      = 0;

                    _context.Add(UserEntry);
                    //_context.SaveChanges();
                    await _context.SaveChangesAsync();
                }
                else if (i == 3)
                {
                    UserEntry.UsersId          = ApiDataCalls.curId;
                    UserEntry.Company_Name     = symbol;
                    UserEntry.Purchased_Amount = Convert.ToInt32(newShares1);
                    UserEntry.Amount_Paid      = 0;

                    _context.Add(UserEntry);
                    //_context.SaveChanges();
                    await _context.SaveChangesAsync();
                }
            }

            List <StockPurchaseEntry> list = new List <StockPurchaseEntry>();

            foreach (StockPurchaseEntry entry in ApiDataCalls.itemsToPass)
            {
                entry.Users = null;

                list.Add(entry);
            }

            var rawData = JsonConvert.SerializeObject(list);

            await InvokeClientMethodToAllAsync("ParseValueAndCreateTable", socketId, rawData);
        }
        public async Task <IActionResult> Create([Bind("UsersId,stock1,stock2,stock3")]
                                                 Stocks stock)
        {
            StockPurchaseEntry UserEntry = new StockPurchaseEntry();

            UserEntry.UsersId = stock.UsersId;
            for (int i = 1; i <= 3; i++)
            {
                if (i == 1)
                {
                    UserEntry.Company_Name     = stock.stock1;
                    UserEntry.Purchased_Amount = stocksPurchased(UserEntry.Company_Name, UserEntry.UsersId);
                    UserEntry.Amount_Paid      = intitialBalance(UserEntry.UsersId);

                    _context.Add(UserEntry);
                    await _context.SaveChangesAsync();

                    // _context.SaveChanges();
                }
                else if (i == 2)
                {
                    UserEntry                  = new StockPurchaseEntry();
                    UserEntry.UsersId          = stock.UsersId;
                    UserEntry.Company_Name     = stock.stock2;
                    UserEntry.Purchased_Amount = stocksPurchased(UserEntry.Company_Name, UserEntry.UsersId);
                    UserEntry.Amount_Paid      = intitialBalance(UserEntry.UsersId);

                    _context.Add(UserEntry);
                    //_context.SaveChanges();
                    await _context.SaveChangesAsync();
                }
                else if (i == 3)
                {
                    UserEntry                  = new StockPurchaseEntry();
                    UserEntry.UsersId          = stock.UsersId;
                    UserEntry.Company_Name     = stock.stock3;
                    UserEntry.Purchased_Amount = stocksPurchased(UserEntry.Company_Name, UserEntry.UsersId);
                    UserEntry.Amount_Paid      = intitialBalance(UserEntry.UsersId);

                    _context.Add(UserEntry);
                    //_context.SaveChanges();
                    await _context.SaveChangesAsync();
                }
            }

            /*[Bind("UsersId,Company_Name,Purchased_Amount,Amount_Paid")]
             * StockPurchaseEntry stockPurchaseEntry
             * /*
             * if (ModelState.IsValid)
             * {
             *  _context.Add(stockPurchaseEntry);
             *  await _context.SaveChangesAsync();
             *  return RedirectToAction(nameof(Index));
             * }
             * ViewData["UsersId"] = new SelectList(_context.Users, "Id", "Id", stockPurchaseEntry.UsersId);*/

            Console.WriteLine("This is the User " + stock.UsersId + "Stock 1:" + stock.stock1 + "Stock 2:" + stock.stock2 + "Stock 3:" + stock.stock3);
            //await _context.SaveChangesAsync();
            var user = _context.Users.First(x => x.Id == stock.UsersId);

            return(RedirectToAction("Details", new RouteValueDictionary(
                                        new { controller = "Users", action = "Details", user.Username, user.Pword })));
        }