Beispiel #1
0
        public ActionResult GetOrderDetails(invoice_table model)
        {
            // Remove associated orders first
            // Put into a list, then go through the list (cannot delete each item at once as a thread will still be accessing them)
            List <orders_table> orderTempList = new List <orders_table>();

            foreach (orders_table orderItem in storeDB.orders_table)
            {
                if (orderItem.invoice_num == model.invoice_num)
                {
                    orderTempList.Add(orderItem);
                }
            }

            // Run through and delete the list of orders
            foreach (orders_table orderItem in orderTempList)
            {
                storeDB.orders_table.Remove(orderItem);
                storeDB.SaveChanges();
            }

            orderTempList.Clear();

            var removeInvoice = storeDB.invoice_table.FirstOrDefault(inv_table => inv_table.invoice_num == model.invoice_num);

            storeDB.invoice_table.Remove(removeInvoice);
            storeDB.SaveChanges();
            return(RedirectToAction("Account", "Account"));
        }
        public ActionResult Confirmation(ViewModels.CartViewModel viewModel)
        {
            var invoice = new invoice_table();

            TryUpdateModel(invoice);

            try
            {
                // Get user num
                int usernum = 0;
                foreach (var users in storeDB.users_table)
                {
                    if (users.username == HttpContext.User.Identity.Name)
                    {
                        usernum = users.user_num;
                    }
                }

                invoice.user_num       = usernum;
                invoice.invoice_date   = DateTime.Now;
                invoice.invoice_filled = "Pending";

                storeDB.invoice_table.Add(invoice);
                storeDB.SaveChanges();

                var cart = UserShoppingCart.GetCart(this.HttpContext);
                cart.CreateOrder(invoice);

                List <parts_table> tempPartsTable = new List <parts_table>();

                // Subtract stock from how much the user ordered
                foreach (var orderItem in storeDB.orders_table)
                {
                    if (orderItem.invoice_num == invoice.invoice_num)
                    {
                        var currentPart = storeDB.parts_table.FirstOrDefault(part_table => part_table.part_number == orderItem.part_num);
                        currentPart.part_stock = currentPart.part_stock - orderItem.quantity;
                        tempPartsTable.Add(currentPart);
                    }
                }

                // Run through and modify the stock of parts
                foreach (parts_table partItem in tempPartsTable)
                {
                    storeDB.Entry(partItem).State = System.Data.EntityState.Modified;
                    storeDB.SaveChanges();
                }

                return(RedirectToAction("Finished", new { id = invoice.invoice_num }));
            }
            catch (Exception)
            {
                return(View(viewModel));
            }
        }
        public ActionResult ChangeOrderStatus(int id)
        {
            invoice_table currentInvoice = new invoice_table();

            foreach (var invoiceItem in storeDB.invoice_table)
            {
                if (invoiceItem.invoice_num == id)
                {
                    currentInvoice = invoiceItem;
                }
            }
            return(View("Index", currentInvoice));
        }
        public ActionResult ChangeOrderStatus(invoice_table model)
        {
            var changeInvoice = storeDB.invoice_table.FirstOrDefault(inv_table => inv_table.invoice_num == model.invoice_num);
            int invoiceUser   = (int)changeInvoice.user_num;

            changeInvoice.invoice_filled = "Ready";

            storeDB.Entry(changeInvoice).State = System.Data.EntityState.Modified;
            storeDB.SaveChanges();

            // Send email to user that the order is ready
            MailMessage mail = new MailMessage();

            SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");

            smtpServer.Credentials = new System.Net.NetworkCredential("stevecoautoparts", "******");
            smtpServer.Port        = 587; // Gmail works on this port

            string userEmail = "";

            foreach (var userItem in storeDB.users_table)
            {
                if (userItem.user_num == invoiceUser)
                {
                    userEmail = userItem.user_email;
                }
            }

            // Send the message that the store owner created
            mail.From = new MailAddress("*****@*****.**");
            mail.To.Add(userEmail);
            mail.Subject = "Order update";
            mail.Body    = "Your order is now ready for pickup! Amount due: $" + changeInvoice.invoice_total;

            smtpServer.EnableSsl = true;
            smtpServer.Send(mail);

            return(RedirectToAction("Account", "Account"));
        }