Esempio n. 1
0
        public static void RemoveDataFromDatabase()
        {
            using (var db = new TodoListEntities())
            {
                Console.Write("\nDo you want to remove any Task? y/n ");
                ConsoleKeyInfo keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.Y)
                {
                    Console.Write("\nPlease enter TaskID to remove it --> ");
                    int taskId = int.Parse(Console.ReadLine());

                    var taskDelete = db.Tasks.Find(taskId);
                    if (taskDelete != null)
                    {
                        db.Tasks.Remove(taskDelete);
                        db.SaveChanges();
                        Console.WriteLine("Task removed successfully");
                    }
                    else
                    {
                        Console.WriteLine("Task with this Id can't find");
                    }
                }
                else if (keyInfo.Key == ConsoleKey.N)
                {
                }
                else
                {
                    Console.WriteLine("\nThis Key is not valid");
                }
            }
        }
Esempio n. 2
0
        public static void DisplayAllData()
        {
            using (var db = new TodoListEntities())
            {
                Console.WriteLine("All Tasks in the database:\n");
                Console.WriteLine("TaskID | Task");
                Console.WriteLine("-------|------------------");

                foreach (var item in db.Tasks
                         .OrderBy(t => t.TaskID))
                {
                    Console.WriteLine(string.Format("{0, -6} | {1}", item.TaskID, item.Context));
                }
            }
        }
        public static void AddDataToDatabase()
        {
            using (var db = new TodoListEntities())
            {
                Console.WriteLine("enter a Chore or Task:");
                var userEnter = Console.ReadLine();

                var task = new Tasks {
                    Context = userEnter
                };

                while (!string.IsNullOrWhiteSpace(task.Context))
                {
                    db.Tasks.Add(task);
                    db.SaveChanges();

                    Console.WriteLine("enter a Chore or Task:");
                    userEnter = Console.ReadLine();
                    task      = new Tasks {
                        Context = userEnter
                    };
                }
            }
        }