Ejemplo n.º 1
0
        public void DeleteTopic()
        {
            TopicDal a   = new TopicDal(connectionString);
            var      res = a.Delete(3);

            Assert.IsTrue(res != -1);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.Default;

            //string connStr = ConfigurationManager.ConnectionStrings["ManagerNews"].ConnectionString;

            string connectionString = "Data Source=localhost;Initial Catalog=ManagerNews;Integrated Security=True";

            topicDal   = new TopicDal(connectionString);
            userDal    = new UserDal(connectionString);
            commentDal = new CommentDal(connectionString);

            uint isLogIn = LogIn();

            while (isLogIn != 0)
            {
                //Console.Clear();
                Console.WriteLine("\n\n What do you want to DO?");
                Console.WriteLine("\ntype 'l' to get List of entities");
                Console.WriteLine("type 's' to Sort entity");
                Console.WriteLine("type 'f' to Find entity");
                if (isLogIn == 2)
                {
                    Console.WriteLine("type 'a' to Add entity");
                    Console.WriteLine("type 'r' to Remove entity");
                }
                //...
                Console.WriteLine("type 'o' to logOut");
                Console.WriteLine("type 'q' to Quit");
                try
                {
                    char c = char.Parse(Console.ReadLine());

                    switch (c)
                    {
                    case 'l':     //show list of entities
                    {
                        Console.WriteLine("\nList of all entity:");
                        PrintAll();
                    }
                    break;

                    case 's':     //
                    {
                        Console.WriteLine("\nSorted by Title:");
                        PrintSorted();
                    }
                    break;

                    case 'a':     //create new entity
                    {
                        Console.WriteLine("Add:");
                        AddUser();
                    }
                    break;

                    case 'r':     //remove entity
                    {
                        Console.WriteLine("If you are the Owner or Administrator you can delete the user.\nEnter ID:");
                        if (isLogIn == 2)
                        {
                            int id = int.Parse(Console.ReadLine());
                            topicDal.Delete(id);
                        }
                        else
                        {
                            throw new Exception("Not permission");
                        }
                    }
                    break;

                    case 'f':
                    {
                        Console.WriteLine("Please, enter a word or letters or a price: ");         // find by Title
                        string ttl = Console.ReadLine().ToString();
                        Find(ttl);
                    }
                    break;

                    case 'o':
                    {
                        isLogIn = LogIn();
                    }
                    break;

                    case 'q':
                        return;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }