コード例 #1
0
        void AddTask()
        {
            //Console.WriteLine("Enter a Name Category for Task :");
            //string _NameForTask = Console.ReadLine();
            Category categoryName = AddCategory();

            Console.WriteLine("Enter a Name Task :");
            string _Name = Console.ReadLine();

            //Console.WriteLine("Enter  Task isDone :");
            //string _isDone = Console.ReadLine();
            Console.WriteLine("Enter  Deadline :");
            string _Deadline = Console.ReadLine();

            Console.WriteLine("Enter  Priority :");
            string _Priority = Console.ReadLine();

            using (CheckListContext db = new CheckListContext())
            {
                Task task = new Task {
                    Name = _Name, isDone = false, category = db.Categories.Where(p => p.Name == categoryName.Name).First <Category>(), Deadline = _Deadline, Priority = _Priority
                };
                db.Tasks.Add(task);
                db.SaveChanges();
            }
        }
コード例 #2
0
        public Category AddCategory()
        {
            Console.WriteLine("Enter a Name Category :");
            string _Name = Console.ReadLine();

            using (CheckListContext db = new CheckListContext())
            {
                foreach (Category categor in db.Categories)
                {
                    if (categor.Name == _Name)
                    {
                        Console.WriteLine(" Category existing ");
                        return(categor);
                    }
                }
                Category category = new Category {
                    Name = _Name
                };
                db.Categories.Add(category);
                db.SaveChanges();
                Console.WriteLine(" Category add ");
                return(category);
            }
        }