public void DeleteTicket(int ticketID)
        {
            CustTicket ticket = new CustTicket();

            using (var db = new EticketContext())
            {
                ticket = db.CustTickets.FirstOrDefault(x => x.TicketID == ticketID && x.Closed == true);

                if (ticket == null)
                {
                    Console.WriteLine("Ticket not found under the specified criteria. Press any key to continue");
                    Console.ReadKey();
                }
                else
                {
                    Console.Write($"Are you sure you want to delete Customer Ticket with ID- {ticket.TicketID}? (Y/N) ");
                    string selection = Console.ReadLine();
                    if (selection == "Y" || selection == "y")
                    {
                        db.CustTickets.Remove(ticket);
                        db.SaveChanges();
                        ticket = db.CustTickets.SingleOrDefault(s => s.TicketID == ticketID);
                        if (ticket == null)
                        {
                            Console.WriteLine("Ticket deleted.");
                        }
                        else
                        {
                            Console.WriteLine("Ticket couldn't be deleted.");
                        }
                    }
                }
            }
        }
        public void assignUsersToTicket(int ticketID)
        {
            CustTicketForm form   = new CustTicketForm();
            CustTicket     ticket = new CustTicket();

            using (var db = new EticketContext())
            {
                ticket = db.CustTickets.FirstOrDefault(x => x.TicketID == ticketID);
            }
            if (ticket == null)
            {
                Console.WriteLine("Ticket couldn't be found. Press any key to return.");
                Console.ReadKey();
            }
            else
            {
                CustTicket updatedTicket = form.CustTicketFormAssignUsers(ticket);
                using (var db = new EticketContext())
                {
                    ticket             = db.CustTickets.SingleOrDefault(s => s.TicketID == ticket.TicketID);
                    ticket.CSAgent     = updatedTicket.CSAgent;
                    ticket.TechSupport = updatedTicket.TechSupport;
                    ticket.Closed      = updatedTicket.Closed;
                    db.SaveChanges();
                }
                string updatedTicketToText = ($" Date: {updatedTicket.Date}  - CustomerName: {updatedTicket.CustomerName} - Customer Email: {updatedTicket.CustomerEmail} - Customer Phone: {updatedTicket.CustomerPhone} - Description: {updatedTicket.Description} - TicketID: {updatedTicket.TicketID} \n");
                File.AppendAllText("CustTicketArchive.txt", updatedTicketToText);
            }
        }
        //CRUD for Customer Tickets
        #region
        public void SubmitNewTicket(string username)
        {
            CustTicketForm form      = new CustTicketForm();
            CustTicket     newTicket = new CustTicket();

            newTicket = form.CustTicketFormEmpty(username);
            using (var db = new EticketContext())
            {
                db.CustTickets.Add(newTicket);
                db.SaveChanges();
            }
            string newTicketToText = ($" Date: {newTicket.Date}  - CustomerName: {newTicket.CustomerName} - Customer Email: {newTicket.CustomerEmail} - Customer Phone: {newTicket.CustomerPhone} - Description: {newTicket.Description} - TicketID: {newTicket.TicketID}\n");

            File.AppendAllText("CustTicketArchive.txt", newTicketToText);
        }
        public void CustTicketFormFilled(CustTicket ticket)
        {
            string status = ticket.Closed ? "Closed" : "Active";

            Console.Write(" Customer Name: ");
            ColourInput(ticket.CustomerName);
            Console.Write("\n Customer Email: ");
            ColourInput(ticket.CustomerEmail);
            Console.Write("\n Customer Phone:");
            ColourInput(ticket.CustomerPhone);
            Console.WriteLine("\n Description: ");
            ColourInput(ticket.Description);
            Console.Write("\n Submission Date: ");
            ColourInput($"{ticket.Date}");
            Console.Write("\n Ticket Status: ");
            ColourInput(status);
            Console.Write("\n Receiver: ");
            ColourInput(ticket.CSAgent);
            Console.Write("\n Handler: ");
            ColourInput(ticket.TechSupport);
            Console.Write("\n TicketID: ");
            ColourInput($"{ticket.TicketID} \n");
        }
        public CustTicket CustTicketFormAssignUsers(CustTicket ticket)
        {
            Console.Clear();

            CustTicketFormFilled(ticket);

            if (ticket.Closed == true)
            {
                Console.Write("Ticket is closed, do you want to reopen case? (Y/N)");
                string submit = Console.ReadLine();
                if (submit != "N" || submit != "n")
                {
                    ticket.Closed = false;
                }
            }

            Console.Write("\n Assign new Receiver Username (press enter if you don't want to assign a new receiver): ");
            string csagent = Console.ReadLine();
            bool   csagentExists;

            if (csagent == "")
            {
                csagent       = ticket.CSAgent;
                csagentExists = true;
            }
            else
            {
                using (var db = new EticketContext())
                {
                    if (db.CSAgents.Any(x => x.Username == csagent))
                    {
                        csagentExists = true;
                    }
                    else
                    {
                        csagentExists = false;
                    }
                }
            }
            if (csagentExists && csagent != ticket.CSAgent)
            {
                Console.Write($"\n Do you want to change the receiver from ");
                ColourInput(ticket.CSAgent);
                Console.Write("to ");
                ColourInput(csagent);
                Console.Write(" ? (Y/N) \n");
                string submit = Console.ReadLine();
                if (submit != "N" || submit != "n")
                {
                    ticket.CSAgent = csagent;
                }
            }
            else if (!csagentExists)
            {
                Console.WriteLine("The username you provided does not exist in the Customer Service Agents database. Press any key to continue");
                Console.ReadKey();
            }
            Console.Write($" Assign new Handler Username (press enter if you don't want to assign a new handler): ");
            string techsupport       = Console.ReadLine();
            bool   techsupportExists = false;

            if (techsupport == "")
            {
                techsupport       = ticket.TechSupport;
                techsupportExists = true;
            }
            else
            {
                using (var db = new EticketContext())
                {
                    if (db.TechSupportUsers.Any(x => x.Username == techsupport))
                    {
                        techsupportExists = true;
                    }
                    else
                    {
                        techsupportExists = false;
                    }
                }
            }
            if (techsupportExists && techsupport != ticket.TechSupport)
            {
                Console.Write($"\n Do you want to change the handler from ");
                ColourInput(ticket.TechSupport);
                Console.Write("to ");
                ColourInput(techsupport);
                Console.Write(" ? (Y/N) \n");
                string submit = Console.ReadLine();
                if (submit != "N" || submit != "n")
                {
                    ticket.TechSupport = techsupport;
                }
            }
            else if (!techsupportExists)
            {
                Console.WriteLine("The username you provided does not exist in the Technical Support Users database. Press any key to continue");
                Console.ReadKey();
            }
            return(ticket);
        }
        public CustTicket CustTicketFormEmpty(string username)
        {
            CustTicket Ticket = new CustTicket();

            Console.Clear();
            Console.Write(" Customer Name: ");
            string name = Console.ReadLine();

            Console.Clear();

            Console.Write($" Customer Name: ");
            ColourInput(name);
            Console.Write("\n Customer Email: ");
            string email = Console.ReadLine();

            Console.Clear();

            Console.Write($" Customer Name: ");
            ColourInput(name);
            Console.Write("\n Customer Email: ");
            ColourInput(email);
            Console.Write("\n Customer Phone: ");
            string phone = Console.ReadLine();

            Console.Clear();

            Console.Write($" Customer Name: ");
            ColourInput(name);
            Console.Write("\n Customer Email: ");
            ColourInput(email);
            Console.Write("\n Customer Phone: ");
            ColourInput(phone);
            Console.WriteLine("\n Description: ");
            string description = Console.ReadLine();

            Console.Clear();

            Console.Write($" Customer Name: ");
            ColourInput(name);
            Console.Write("\n Customer Email: ");
            ColourInput(email);
            Console.Write("\n Customer Phone: ");
            ColourInput(phone);
            Console.WriteLine("\n Description: ");
            ColourInput(description);


            Console.WriteLine("\nSubmit ticket? (Y/N) ");
            string selection = Console.ReadLine();

            if (selection != "N" && selection != "n")
            {
                Ticket.CustomerName  = name;
                Ticket.CustomerEmail = email;
                Ticket.CustomerPhone = phone;
                Ticket.Description   = description;
                Ticket.Date          = DateTime.Now;
                Ticket.Closed        = false;
                Ticket.CSAgent       = username;
                return(Ticket);
            }
            else
            {
                Ticket.CustomerName  = name;
                Ticket.CustomerEmail = email;
                Ticket.CustomerPhone = phone;
                Ticket.Description   = ($" INVALID TICKET \n {description}");
                Ticket.Date          = DateTime.Now;
                Ticket.Closed        = true;
                Ticket.CSAgent       = username;
                return(Ticket);
            }
        }
        public CustTicket CustTicketFormUpdate(CustTicket ticket)
        {
            Console.Clear();

            Console.Write(" Customer Name: ");
            ColourInput(ticket.CustomerName);
            string name = Console.ReadLine();

            if (name == "")
            {
                name = ticket.CustomerName;
            }
            Console.Clear();

            Console.Write(" Customer Name: ");
            ColourInput(ticket.CustomerName);
            Console.Write("\n Customer Email: ");
            ColourInput(ticket.CustomerEmail);
            string email = Console.ReadLine();

            if (email == "")
            {
                email = ticket.CustomerEmail;
            }
            Console.Clear();

            Console.Write(" Customer Name: ");
            ColourInput(ticket.CustomerName);
            Console.Write("\n Customer Email: ");
            ColourInput(ticket.CustomerEmail);
            Console.Write("\n Customer Phone:");
            ColourInput(ticket.CustomerPhone);
            string phone = Console.ReadLine();

            if (phone == "")
            {
                phone = ticket.CustomerPhone;
            }
            Console.Clear();

            Console.Write(" Customer Name: ");
            ColourInput(ticket.CustomerName);
            Console.Write("\n Customer Email: ");
            ColourInput(ticket.CustomerEmail);
            Console.Write("\n Customer Phone:");
            ColourInput(ticket.CustomerPhone);
            Console.WriteLine("\n Description: ");
            ColourInput(ticket.Description);
            Console.WriteLine("\n Added comments: ");
            string description    = Console.ReadLine();
            string newDescription = ($"{ticket.Description} \n {DateTime.Now} -Added comments- \n {description}");

            Console.Clear();
            Console.Write(" Customer Name: ");
            ColourInput(ticket.CustomerName);
            Console.Write("\n Customer Email: ");
            ColourInput(ticket.CustomerEmail);
            Console.Write("\n Customer Phone:");
            ColourInput(ticket.CustomerPhone);
            Console.WriteLine("\n Description: ");
            ColourInput(ticket.Description);
            Console.WriteLine("\n Added comments: ");
            ColourInput(description);
            Console.WriteLine("\n Do you want to close this ticket? (Y/N)");
            string closeTicket = Console.ReadLine();
            bool   close;

            if (closeTicket == "y" || closeTicket == "Y")
            {
                close = true;
            }
            else
            {
                close = ticket.Closed;
            }


            Console.WriteLine("\n Submit updated ticket? (Y/N) ");
            string selection = Console.ReadLine();


            if (selection != "N" || selection != "n")
            {
                ticket.CustomerName  = name;
                ticket.CustomerEmail = email;
                ticket.CustomerPhone = phone;
                ticket.Description   = newDescription;
                ticket.Closed        = close;
                Console.WriteLine("Ticket Updated.");
                Console.ReadKey();
                return(ticket);
            }
            else
            {
                Console.WriteLine("Couldn't update ticket.");
                Console.ReadKey();
                return(ticket);
            }
        }
Esempio n. 8
0
        public TechSupportUserMenu(TechSupportUser user)
        {
            bool logout = false;

            do
            {
                Console.Clear();
                HidePassword.Logo();

                Console.Write("Select a function: \n 1. Get new Customer Ticket \n 2. Search for a Customer Ticket \n 3. Update Customer Ticket \n 4. See all your tickets \n 5. Logout \n");
                string selection = Console.ReadLine();
                switch (selection)
                {
                case "1":
                    Console.Clear();
                    CustTicketManager getTicket = new CustTicketManager();
                    CustTicketForm    form      = new CustTicketForm();
                    CustTicket        ticket    = new CustTicket();
                    using (var db = new EticketContext())
                    {
                        ticket = db.CustTickets.FirstOrDefault(x => x.TechSupport == null && x.Closed == false);
                    }
                    CustTicket updatedTicket = form.CustTicketFormUpdate(ticket);
                    using (var db = new EticketContext())
                    {
                        ticket = db.CustTickets.SingleOrDefault(s => s.TicketID == ticket.TicketID);
                        ticket.CustomerName  = updatedTicket.CustomerName;
                        ticket.CustomerEmail = updatedTicket.CustomerEmail;
                        ticket.CustomerPhone = updatedTicket.CustomerPhone;
                        ticket.Description   = updatedTicket.Description;
                        ticket.TechSupport   = user.Username;
                        db.SaveChanges();
                    }

                    break;

                case "2":
                    Console.Clear();
                    Console.Write("Select a function: \n 1. Search all Tickets \n 2. Search only Open Tickets \n 3.Go Back \n");
                    string selection1 = Console.ReadLine();
                    switch (selection1)
                    {
                    case "1":

                        Console.Clear();
                        Console.Write("Search by: 1. Customer Name, 2. Customer Email, 3. Go Back \n");
                        string            selection2    = Console.ReadLine();
                        CustTicketForm    resultForm    = new CustTicketForm();
                        List <CustTicket> resultTickets = new List <CustTicket>();
                        CustTicketManager resultManager = new CustTicketManager();
                        switch (selection1)
                        {
                        case "1":
                            Console.Write("What is the Customer's Name? \n");
                            string customerName = Console.ReadLine();
                            resultManager.SearchAllTicketsByName(customerName);
                            PressAnyKey();
                            break;

                        case "2":
                            Console.Write("What is the Customer's Email? \n");
                            string customerEmail = Console.ReadLine();
                            resultManager.SearchAllTicketsByEmail(customerEmail);
                            PressAnyKey();
                            break;

                        case "3":
                            break;

                        default:
                            InvalidSelection();
                            break;
                        }
                        break;

                    case "2":
                        Console.Clear();
                        Console.Write("Search by: 1. Customer Name, 2. Customer Email, 3. Go Back \n");
                        string            selection3     = Console.ReadLine();
                        CustTicketForm    resultForm2    = new CustTicketForm();
                        List <CustTicket> resultTickets2 = new List <CustTicket>();
                        CustTicketManager resultManager2 = new CustTicketManager();
                        switch (selection1)
                        {
                        case "1":
                            Console.Write("What is the Customer's Name? \n");
                            string customerName = Console.ReadLine();
                            resultManager2.FindOpenTicketsByName(customerName);
                            PressAnyKey();
                            break;

                        case "2":
                            Console.Write("What is the Customer's Email? \n");
                            string customerEmail = Console.ReadLine();
                            resultManager2.FindOpenTicketsByEmail(customerEmail);
                            PressAnyKey();
                            break;

                        case "3":
                            break;

                        default:
                            InvalidSelection();
                            break;
                        }
                        break;

                    case "3":
                        break;

                    default:
                        InvalidSelection();
                        break;
                    }
                    break;

                case "3":
                    Console.Clear();
                    Console.Write("What is the TicketID of the Customer Ticket you want to update: ");
                    if (int.TryParse(Console.ReadLine(), out int ticketID))
                    {
                        CustTicketManager updateManager = new CustTicketManager();
                        updateManager.UpdateTicket(ticketID);
                    }
                    else
                    {
                        Console.Write("Invalid TicketID, all ticket IDs are numerals.");
                    }
                    PressAnyKey();
                    break;



                case "4":
                    CustTicketForm    form1     = new CustTicketForm();
                    List <CustTicket> myTickets = new List <CustTicket>();
                    using (var db = new EticketContext())
                    {
                        myTickets = db.CustTickets.Where(x => x.TechSupport == user.Username && x.Closed == false).ToList();
                    }
                    foreach (var item in myTickets)
                    {
                        form1.CustTicketFormFilled(item);
                    }
                    Console.ReadKey();
                    break;

                case "5":
                    logout = true;
                    break;

                default:
                    InvalidSelection();
                    break;
                }
            } while (!logout);
        }