public IActionResult AddNewPurchase(Purchase c)
        {
            c.Tdate = DateTime.Today.Date;

            Products p = dbContext.Products.Where(pp => pp.ProductCode == c.ProductCode).FirstOrDefault();
            Vendors  v = dbContext.Vendors.Where(cc => cc.VendorCode == c.VendorCode).FirstOrDefault();


            if (p.Quantity == null)
            {
                p.Quantity = 0;
            }


            p.Quantity = p.Quantity + c.Quantity;

            dbContext.Products.Update(p);
            dbContext.Purchase.AddAsync(c);
            dbContext.SaveChanges();



            string msgBody = "<p>New Purchase From " + v + " <br/> " +
                             "Item=" + c.ProductCodeNavigation.ProductName + " <br/> " +
                             "Quantity =" + c.Quantity + " <br/> " +
                             "Total Amount=" + c.LineTotal + " </p>";

            EmailSending ES = new EmailSending();

            ES.SendEmail("New Purchase on" + DateTime.Now, msgBody, "");

            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult AddNewSale(Sale s)
        {
            Products  p = dbContext.Products.Where(pp => pp.ProductCode == s.ProductCode).FirstOrDefault();
            Customers c = dbContext.Customers.Where(cc => cc.CustomerCode == s.CustomerCode).FirstOrDefault();

            if (s != null)
            {
                if (p.Quantity == null || p.Quantity == 0 || (p.Quantity < s.Quantity))
                {
                    ViewBag.ErrorMessage = "Quantity is Greater Than Existing Stock";
                    return(View());
                }
                p.Quantity = p.Quantity - s.Quantity;

                dbContext.Products.Update(p);

                dbContext.Sale.AddAsync(s);
                dbContext.SaveChanges();
            }

            string msgBody = "<p>Thanks From Your Visit " + c.CustomerName + " <br/> " +
                             "Item=" + p.ProductName + " <br/> " +
                             "Quantity =" + s.Quantity + " <br/> " +
                             "Total Amount=" + s.LineTotal + " </p>";

            EmailSending ES = new EmailSending();

            ES.SendEmail("Sale on" + DateTime.Now, msgBody, c.Email);

            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult AddNewUser(Users c)
        {
            c.Tdate = DateTime.Today.Date;
            dbContext.Users.Add(c);
            dbContext.SaveChanges();

            string msgBody = "<p>New User Created by User Id <br/>" + c.UserName + "</p>";

            EmailSending ES = new EmailSending();

            ES.SendEmail("New User Creation Confirmation", msgBody, c.UserName);

            return(RedirectToAction(nameof(UserLogin)));
        }