public ActionResult CustomerDetails([Bind(Include = "CustomerID,Name,CustType,Multi,Number,Email,Address")] CustomerViewModel customerViewModel, Customer customer)
        {
            // returns this view after customer passes regiter view in accounts
            string reciever     = "";
            string customername = "";
            int    Accid        = 0;

            customerViewModel.CustType = "Customer";

            customer.Disabled = false;

            if (TempData.ContainsKey("Username"))
            {
                string name = TempData["Username"].ToString();
                var    user = db.Accounts.Where(x => x.UserName == name).Select(y => y.AccountID).First();
                Accid = Convert.ToInt32(user);
            }

            if (ModelState.IsValid)
            {
                reciever     = customerViewModel.Email;
                customername = customerViewModel.Name;
                // inserts customer info to customer table using corresponding account ID

                customer.CustomerID = customerViewModel.CustomerID;
                customer.AccountID  = Accid;
                customer.Name       = customerViewModel.Name;
                customer.Type       = customerViewModel.CustType;
                customer.Multi      = customerViewModel.Multi;
                customer.Number     = customerViewModel.Number;
                customer.Address    = customerViewModel.Address;

                db.Customers.Add(customer);
                db.SaveChanges();

                AccountsController acc = new AccountsController();
                var subject            = "Farmer's Fresh Produce Registration";
                var body = "Welcome to Farmer's Fresh Produce " + customername + "\r\n Please enjoy our services";
                acc.Confirmation(reciever, customername, subject, body);

                return(RedirectToAction("Store", "Stocks"));
            }
            return(View(customerViewModel));
        }
        public ActionResult CheckOut(CheckoutViewModel checkout)
        {
            DateTime today = DateTime.Now.Date;
            string   name  = User.Identity.Name;

            var getAcctId = (from x in db.Accounts
                             where x.UserName == name
                             select x.AccountID).First();

            int accid = Convert.ToInt16(getAcctId);

            var getCustId = (from x in db.Customers
                             where x.AccountID == accid
                             select x.CustomerID).First();

            int customerID = Convert.ToInt16(getCustId);

            var email = (from x in db.Customers
                         where x.CustomerID == customerID
                         select x.Email).First();
            string custEmail = email.ToString();

            var getCustName = (from x in db.Customers
                               where x.CustomerID == customerID
                               select x.Name).First();
            string custname   = getCustName.ToString();
            var    getOrderid = (from x in db.Orders
                                 where x.CustomerID == customerID
                                 select x.OrderID).First();
            int OrderId = Convert.ToInt16(getOrderid);

            //var orders = db.Orders.Where(a => a.CustomerID == customerID).OrderBy(x => x.Customer.Name).ToList();

            checkout.CustomerID   = customerID;
            checkout.CustomerName = custname;

            Order order = db.Orders.Find(OrderId);

            order.status          = "Processing";
            db.Entry(order).State = EntityState.Modified;
            db.SaveChanges();

            int customerId = Convert.ToInt16(order.CustomerID);
            int orderId    = Convert.ToInt16(order.OrderID);

            statOrderId = Convert.ToInt16(order.OrderID);
            int total = Convert.ToInt16(order.Total);

            Sale sale = new Sale();

            sale.CustomerID = customerId;
            sale.Date       = DateTime.Now.Date;
            sale.Total      = total;
            sale.OrderID    = orderId;

            SalesController sc = new SalesController();

            sc.AddSale(sale);

            string subject = "Order" + orderId + "Confirmation";
            string body    = custname + " your order= " + orderId + " of " + total + " has be successfully placed.";

            AccountsController acc = new AccountsController();

            acc.Confirmation(custEmail, custname, subject, body);


            var stockoid     = db.StockOrders.Where(x => x.OrderID == orderId).Select(y => y.SOID).First();
            int stockorderid = Convert.ToInt16(stockoid);

            StockOrder stockorders = db.StockOrders.Find(stockorderid);

            db.StockOrders.Remove(stockorders);
            db.SaveChanges();

            return(RedirectToAction("OrderHistory", "Orders"));
        }