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);
            }
        }
        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.");
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public bool DeleteNewUser(string username)
        {
            NewUser newUser;

            using (var db = new EticketContext())
            {
                newUser = db.NewUsers.SingleOrDefault(s => s.Username == username);
                if (newUser != null)
                {
                    db.NewUsers.Remove(newUser);
                    db.SaveChanges();
                }
                else
                {
                    Console.WriteLine("No users found with this username. Press any key to return");
                    Console.ReadKey();
                }
                newUser = db.NewUsers.SingleOrDefault(s => s.Username == username);
                if (newUser == null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 4
0
        public bool DeleteAdministrator(string username)
        {
            Administrator administrator;

            using (var db = new EticketContext())
            {
                administrator = db.Administrators.SingleOrDefault(s => s.Username == username);
                if (administrator == null)
                {
                    Console.WriteLine("User not found under the specified criteria. Press any key to continue");
                    Console.ReadKey();
                    return(false);
                }
                else
                {
                    db.Administrators.Remove(administrator);
                    db.SaveChanges();
                    administrator = db.Administrators.SingleOrDefault(s => s.Username == username);
                    if (administrator == null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public bool DeleteCSAgent(string username)
        {
            List <CustTicket> deleteCSagentFromTicket = new List <CustTicket>();
            CSAgent           cSAgent;

            using (var db = new EticketContext())
            {
                cSAgent = db.CSAgents.SingleOrDefault(s => s.Username == username);
                if (cSAgent == null)
                {
                    Console.WriteLine("User not found under the specified criteria. Press any key to continue");
                    Console.ReadKey();
                    return(false);
                }
                else
                {
                    deleteCSagentFromTicket = db.CustTickets.Where(x => x.CSAgent == cSAgent.Username).ToList();
                    if (deleteCSagentFromTicket.Count > 0)
                    {
                        for (int i = 0; i < deleteCSagentFromTicket.Count; i++)
                        {
                            deleteCSagentFromTicket[i].CSAgent = null;
                            db.SaveChanges();
                        }
                    }

                    db.CSAgents.Remove(cSAgent);
                    db.SaveChanges();
                    cSAgent = db.CSAgents.SingleOrDefault(s => s.Username == username);
                    if (cSAgent == null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
        //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);
        }
Exemplo n.º 7
0
        public CSAgent updateCSAgentInfo(string username, string password, string name, string phone, string email)
        {
            CSAgent cSAgent;

            using (var db = new EticketContext())
            {
                cSAgent = db.CSAgents.SingleOrDefault(s => s.Username == username);

                cSAgent.Name        = name;
                cSAgent.PhoneNumber = phone;
                cSAgent.Email       = email;
                cSAgent.Password    = password;
                db.SaveChanges();
                cSAgent = db.CSAgents.SingleOrDefault(s => s.Username == username);
            }
            return(cSAgent);
        }
Exemplo n.º 8
0
        public TechSupportUser updateTechSupportUserInfo(string username, string password, string name, string phone, string email)
        {
            TechSupportUser techSupportUser;

            using (var db = new EticketContext())
            {
                techSupportUser = db.TechSupportUsers.SingleOrDefault(s => s.Username == username);

                techSupportUser.Name        = name;
                techSupportUser.PhoneNumber = phone;
                techSupportUser.Email       = email;
                techSupportUser.Password    = password;
                db.SaveChanges();
                techSupportUser = db.TechSupportUsers.SingleOrDefault(s => s.Username == username);
            }
            return(techSupportUser);
        }
Exemplo n.º 9
0
        public Supervisor updateSupervisorInfo(string username, string password, string name, string phone, string email)
        {
            Supervisor supervisor;

            using (var db = new EticketContext())
            {
                supervisor = db.Supervisors.SingleOrDefault(s => s.Username == username);

                supervisor.Name        = name;
                supervisor.PhoneNumber = phone;
                supervisor.Email       = email;
                supervisor.Password    = password;
                db.SaveChanges();
                supervisor = db.Supervisors.SingleOrDefault(s => s.Username == username);
            }
            return(supervisor);
        }
Exemplo n.º 10
0
        public Administrator updateAdministratorInfo(string username, string password, string name, string phone, string email)
        {
            Administrator administrator;

            using (var db = new EticketContext())
            {
                administrator = db.Administrators.SingleOrDefault(s => s.Username == username);


                administrator.Name        = name;
                administrator.PhoneNumber = phone;
                administrator.Email       = email;
                administrator.Password    = password;
                db.SaveChanges();
                administrator = db.Administrators.SingleOrDefault(s => s.Username == username);
            }
            return(administrator);
        }
Exemplo n.º 11
0
        // Administrators CRUD
        #region
        public Administrator CreateAdministrator(string name, string email, string phone, string username, string password)
        {
            Administrator newAdministrator = new Administrator()
            {
                Name        = name,
                Email       = email,
                PhoneNumber = phone,
                Username    = username,
                Password    = password
            };

            using (var db = new EticketContext())
            {
                db.Administrators.Add(newAdministrator);
                db.SaveChanges();
            }
            return(newAdministrator);
        }
Exemplo n.º 12
0
        //TechSupportUsers CRUD
        #region
        public TechSupportUser CreateTechSupportUser(string name, string email, string phone, string username, string password)
        {
            TechSupportUser newTechSupportUser = new TechSupportUser()
            {
                Name        = name,
                Email       = email,
                PhoneNumber = phone,
                Username    = username,
                Password    = password
            };

            using (var db = new EticketContext())
            {
                db.TechSupportUsers.Add(newTechSupportUser);
                db.SaveChanges();
            }
            return(newTechSupportUser);
        }
Exemplo n.º 13
0
        //csAgents CRUD
        #region
        public CSAgent CreateCSAgent(string name, string email, string phone, string username, string password)
        {
            CSAgent newCSAgent = new CSAgent()
            {
                Name        = name,
                Email       = email,
                PhoneNumber = phone,
                Username    = username,
                Password    = password
            };

            using (var db = new EticketContext())
            {
                db.CSAgents.Add(newCSAgent);
                db.SaveChanges();
            }
            return(newCSAgent);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        //UserRegistration
        #region
        static void RegisterMenu()
        {
            HidePassword.Logo();

            NewUser newUser = new NewUser();
            string  name;

            do
            {
                Console.Clear();
                Console.Write("Name (Must have at least 3 characters): ");
                name = Console.ReadLine();
                if (name.Length < 3)
                {
                    Console.WriteLine("Name must have at least 3 characters, press any key to try again.");
                    Console.ReadKey();
                }
            } while (name.Length < 3);
            string email;

            do
            {
                Console.Clear();
                Console.WriteLine($"Name: {name}");
                Console.Write("Email (Must have at least 3 characters): ");
                email = Console.ReadLine();
                if (email.Length < 3)
                {
                    Console.WriteLine("Email must have at least 3 characters, press any key to try again.");
                    Console.ReadKey();
                }
            } while (email.Length < 3);
            Console.Clear();
            Console.WriteLine($"Name: {name}");
            Console.WriteLine($"Email: {email}");
            Console.Write("Phone number: ");
            string phone = Console.ReadLine();

            Console.Clear();
            Console.WriteLine($"Name: {name}");
            Console.WriteLine($"Email: {email}");
            Console.WriteLine($"Phone number: {phone}");
            Console.Write("Specify your role (Administrator, Supervisor, TechSupport User, Customer Service Agent): ");
            string role = Console.ReadLine();

            string username;
            bool   usernameExists;

            do
            {
                Console.Clear();
                Console.WriteLine($"Name: {name}");
                Console.WriteLine($"Email: {email}");
                Console.WriteLine($"Phone number: {phone}");
                Console.WriteLine($"Specify your role (Administrator, Supervisor, TechSupport User, Customer Service Agent): {role} ");
                Console.Write("Username (Must have at least 5 characters): ");
                username = Console.ReadLine();
                if (username.Length < 5)
                {
                    usernameExists = true;
                    Console.WriteLine("Username must have at least 5 characters, press any key to try again.");
                    Console.ReadKey();
                }
                else
                {
                    using (var db = new EticketContext())
                    {
                        if (db.Administrators.Any(x => x.Username == username) || db.CSAgents.Any(x => x.Username == username) || db.Supervisors.Any(x => x.Username == username) || db.TechSupportUsers.Any(x => x.Username == username) || db.NewUsers.Any(x => x.Username == username))
                        {
                            usernameExists = true;
                        }
                        else
                        {
                            usernameExists = false;
                        }
                    }
                    if (usernameExists)
                    {
                        Console.WriteLine("The username you gave is already being used, please provide another. Press any key to continue.");
                        Console.ReadKey();
                    }
                }
            } while (username.Length < 5 || usernameExists);

            string password1;

            do
            {
                Console.Clear();
                Console.WriteLine($"Name: {name}");
                Console.WriteLine($"Email: {email}");
                Console.WriteLine($"Phone number: {phone}");
                Console.WriteLine($"Specify your role (Administrator, Supervisor, TechSupport User, Customer Service Agent): {role} ");
                Console.WriteLine($"Username: {username}");
                Console.Write("Password (Must have exactly 8 characters): ");
                password1 = Console.ReadLine();
                if (password1.Length != 8)
                {
                    Console.WriteLine("Password must have exactly 8 characters, press any key to try again.");
                    Console.ReadKey();
                }
            } while (password1.Length != 8);
            string password2;

            do
            {
                Console.Clear();
                Console.WriteLine($"Name: {name}");
                Console.WriteLine($"Email: {email}");
                Console.WriteLine($"Phone number: {phone}");
                Console.WriteLine($"Specify your role (Administrator, Supervisor, TechSupport User, Customer Service Agent): {role} ");
                Console.WriteLine($"Username: {username}");
                Console.WriteLine($"Password: {password1}");
                Console.Write("Confirm Password: "******"The passwords did not match, press any key to try again.");
                    Console.ReadKey();
                }
            } while (password1 != password2);

            if (password1 == password2)
            {
                newUser.Name        = name;
                newUser.Email       = email;
                newUser.PhoneNumber = phone;
                newUser.Role        = role;
                newUser.Username    = username;
                newUser.Password    = password1;
                using (var db = new EticketContext())
                {
                    db.NewUsers.Add(newUser);
                    db.SaveChanges();
                }
                Console.WriteLine("A message has been sent to your supervisor. You will be notified when your account is active.");
            }

            Console.ReadKey();
        }