コード例 #1
0
 private void DisplayDeveloper(Developer dev)
 {
     Console.WriteLine($"ID: {dev.ID,-5}Name: {dev.Name,-20}Access: {dev.PluralsightAccess,5}");
 }
コード例 #2
0
        private bool ModifyDeveloper()
        {
            Console.Clear();
            Developer dev       = FindDeveloper();
            int       oldId     = dev.ID;
            string    oldName   = dev.Name;
            bool      oldAccess = dev.PluralsightAccess;


            if (dev != null)
            {
                int    newId      = 0;
                string newName    = "";
                bool   newAccess  = false;
                bool   loopExiter = true;
                string response   = null;
                if (dev == null)
                {
                    return(false);
                }
                DisplayDeveloper(dev);
                while (loopExiter)
                {
                    Console.WriteLine("New ID (n for no change):");
                    response = Console.ReadLine().ToLower();
                    if (response != "n")
                    {
                        try
                        {
                            newId      = int.Parse(response);
                            loopExiter = false;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Invalid Response");
                        }
                    }
                    else
                    {
                        newId = oldId;
                    }
                    loopExiter = false;
                }
                loopExiter = true;
                Console.Clear();
                DisplayDeveloper(dev);
                while (loopExiter)
                {
                    Console.WriteLine("New name (n for no change):");
                    response = Console.ReadLine().ToLower();
                    if (response != "n")
                    {
                        try
                        {
                            newName    = response;
                            loopExiter = false;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Invalid Response");
                        }
                    }
                    else
                    {
                        newName = oldName;
                    }
                    loopExiter = false;
                }
                loopExiter = true;
                Console.Clear();
                DisplayDeveloper(dev);
                while (loopExiter)
                {
                    Console.WriteLine("New Access (t/f) (n for no change):");
                    response = Console.ReadLine().ToLower();
                    if (response != "n")
                    {
                        try
                        {
                            if (response.ToLower() == "t")
                            {
                                newAccess = true;
                            }
                            else if (response.ToLower() == "f")
                            {
                                newAccess = false;
                            }
                            loopExiter = false;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Invalid Response");
                        }
                    }
                    else
                    {
                        newAccess = oldAccess;
                    }
                    loopExiter = false;
                }
                DisplayDeveloper(newId, newName, newAccess);
                Console.WriteLine("Is this correct? (y/n)");
                string answer = Console.ReadLine().ToLower();
                if (answer == "y")
                {
                    developerRepo.UpdateExistingDeveloper(oldId, new Developer()
                    {
                        Name = newName, ID = newId, PluralsightAccess = newAccess
                    });
                }
                else if (answer == "n")
                {
                    ModifyDeveloper();
                }
            }
            return(false);
        }
コード例 #3
0
 //C
 public void AddDeveloper(Developer dev)
 {
     devList.Add(dev);
 }