當前位置: 首頁>>代碼示例>>C#>>正文


C# Category.GetId方法代碼示例

本文整理匯總了C#中ToDoList.Category.GetId方法的典型用法代碼示例。如果您正苦於以下問題:C# Category.GetId方法的具體用法?C# Category.GetId怎麽用?C# Category.GetId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ToDoList.Category的用法示例。


在下文中一共展示了Category.GetId方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Test_Delete_DeletesCategoryFromDatabase

        public void Test_Delete_DeletesCategoryFromDatabase()
        {
            //Arrange
              string name1 = "Home stuff";
              Category testCategory1 = new Category(name1);
              testCategory1.Save();

              string name2 = "Work stuff";
              Category testCategory2 = new Category(name2);
              testCategory2.Save();
              DateTime fakeTime = new DateTime(2016, 1, 1);

              Task testTask1 = new Task("Mow the lawn", testCategory1.GetId(),fakeTime);
              testTask1.Save();
              DateTime fakeTime1 = new DateTime(2016, 1, 1);

              Task testTask2 = new Task("Send emails", testCategory2.GetId(),fakeTime1);
              testTask2.Save();

              //Act
              testCategory1.Delete();
              List<Category> resultCategories = Category.GetAll();
              List<Category> testCategoryList = new List<Category> {testCategory2};

              List<Task> resultTasks = Task.GetAll();
              List<Task> testTaskList = new List<Task> {testTask2};

              //Assert
              Assert.Equal(testCategoryList, resultCategories);
              Assert.Equal(testTaskList, resultTasks);
        }
開發者ID:Rouz1130,項目名稱:Delete-Update-Category,代碼行數:31,代碼來源:CategoryTest.cs

示例2: Test_FindFindsCategoryInDatabase

    public void Test_FindFindsCategoryInDatabase()
    {
      //Arrange
      Category testCategory = new Category("Household chores");
      testCategory.Save();

      //Act
      Category foundCategory = Category.Find(testCategory.GetId());

      //Assert
      Assert.Equal(testCategory, foundCategory);
    }
開發者ID:jmk22,項目名稱:todo_categories_databases_CRUD,代碼行數:12,代碼來源:CategoryTest.cs

示例3: Test_SaveAssignsIdToCategoryObject

    public void Test_SaveAssignsIdToCategoryObject()
    {
      //Arrange
      Category testCategory = new Category("Household chores");
      testCategory.Save();

      //Act
      Category savedCategory = Category.GetAll()[0];

      int result = savedCategory.GetId();
      int testId = testCategory.GetId();

      //Assert
      Assert.Equal(testId, result);
    }
開發者ID:jmk22,項目名稱:todo_categories_databases_CRUD,代碼行數:15,代碼來源:CategoryTest.cs

示例4: Test_GetTasks_RetrievesAllTaskWithCategory

        public void Test_GetTasks_RetrievesAllTaskWithCategory()
        {
            Category testCategory = new Category("Household chores");
              testCategory.Save();

              DateTime fakeTime = new DateTime(2014, 1, 1);
              Task firstTask = new Task ("Mow the lawn", testCategory.GetId(), fakeTime);
              firstTask.Save();
              Task secondTask = new Task("Do the dishes", testCategory.GetId(), fakeTime);
              secondTask.Save();

              List<Task> testTaskList = new List<Task> {firstTask, secondTask};
              List<Task> resultTaskList = testCategory.GetTasks();

              Assert.Equal(testTaskList, resultTaskList);
        }
開發者ID:Rouz1130,項目名稱:Delete-Update-Category,代碼行數:16,代碼來源:CategoryTest.cs

示例5: AddCategory

    public void AddCategory(Category newCategory)
    {
      SqlConnection conn = DB.Connection();
      conn.Open();

      SqlCommand cmd = new SqlCommand("INSERT INTO categories_tasks (category_id, task_id) VALUES (@CategoryId, @TaskId);", conn);

      SqlParameter categoryIdParameter = new SqlParameter();
      categoryIdParameter.ParameterName = "@CategoryId";
      categoryIdParameter.Value = newCategory.GetId();
      cmd.Parameters.Add(categoryIdParameter);

      SqlParameter taskIdParameter = new SqlParameter();
      taskIdParameter.ParameterName = "@TaskId";
      taskIdParameter.Value = this.GetId();
      cmd.Parameters.Add(taskIdParameter);

      cmd.ExecuteNonQuery();

      if (conn != null)
      {
        conn.Close();
      }
    }
開發者ID:jmk22,項目名稱:todo_categories_databasesextended_02,代碼行數:24,代碼來源:Task.cs

示例6: AddCategory

        public void AddCategory(Category newCategory)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlDataReader rdrCheckForDuplicate = null;
              SqlCommand cmdCheckForDuplicate = new SqlCommand("SELECT * FROM categories_tasks WHERE [email protected] AND [email protected]", conn);
              SqlParameter categoryIdParameterCheckForDuplicate = new SqlParameter();
              categoryIdParameterCheckForDuplicate.ParameterName = "@CategoryId";
              categoryIdParameterCheckForDuplicate.Value = newCategory.GetId();
              cmdCheckForDuplicate.Parameters.Add(categoryIdParameterCheckForDuplicate);

              SqlParameter taskIdParameterCheckForDuplicate = new SqlParameter();
              taskIdParameterCheckForDuplicate.ParameterName = "@TaskId";
              taskIdParameterCheckForDuplicate.Value = this.GetId();
              cmdCheckForDuplicate.Parameters.Add(taskIdParameterCheckForDuplicate);

              List<int> matchedJoins = new List<int> {};
              rdrCheckForDuplicate = cmdCheckForDuplicate.ExecuteReader();

              while(rdrCheckForDuplicate.Read())
              {
            matchedJoins.Add(rdrCheckForDuplicate.GetInt32(0));
              }
              if (rdrCheckForDuplicate != null) rdrCheckForDuplicate.Close();

              if (matchedJoins.Count == 0)
              {
            SqlCommand cmd = new SqlCommand("INSERT INTO categories_tasks (category_id, task_id) VALUES (@CategoryId, @TaskId);", conn);

            SqlParameter categoryIdParameter = new SqlParameter();
            categoryIdParameter.ParameterName = "@CategoryId";
            categoryIdParameter.Value = newCategory.GetId();
            cmd.Parameters.Add(categoryIdParameter);

            SqlParameter taskIdParameter = new SqlParameter();
            taskIdParameter.ParameterName = "@TaskId";
            taskIdParameter.Value = this.GetId();
            cmd.Parameters.Add(taskIdParameter);

            cmd.ExecuteNonQuery();
              }

              if (conn != null)
              {
            conn.Close();
              }
        }
開發者ID:CharlesEwel,項目名稱:csharp-todo-week4,代碼行數:48,代碼來源:Task.cs


注:本文中的ToDoList.Category.GetId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。