本文整理汇总了C#中ToDoList.Category类的典型用法代码示例。如果您正苦于以下问题:C# Category类的具体用法?C# Category怎么用?C# Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Category类属于ToDoList命名空间,在下文中一共展示了Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Find
public static Category Find(int id)
{
SqlConnection conn = DB.Connection();
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM categories WHERE id = @CategoryId;", conn);
SqlParameter categoryIdParameter = new SqlParameter();
categoryIdParameter.ParameterName = "@CategoryId";
categoryIdParameter.Value = id.ToString();
cmd.Parameters.Add(categoryIdParameter);
SqlDataReader rdr = cmd.ExecuteReader();
int foundCategoryId = 0;
string foundCategoryDescription = null;
while(rdr.Read())
{
foundCategoryId = rdr.GetInt32(0);
foundCategoryDescription = rdr.GetString(1);
}
Category foundCategory = new Category(foundCategoryDescription, foundCategoryId);
if (rdr != null)
{
rdr.Close();
}
if (conn != null)
{
conn.Close();
}
return foundCategory;
}
示例2: 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);
}
示例3: GetAll
public static List<Category> GetAll()
{
List<Category> allCategories = new List<Category>{};
SqlConnection conn = DB.Connection();
SqlDataReader rdr = null;
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM categories;", conn);
rdr = cmd.ExecuteReader();
while(rdr.Read())
{
int categoryId = rdr.GetInt32(0);
string categoryName = rdr.GetString(1);
Category newCategory = new Category(categoryName, categoryId);
allCategories.Add(newCategory);
}
if (rdr != null)
{
rdr.Close();
}
if (conn != null)
{
conn.Close();
}
return allCategories;
}
示例4: HomeModule
public HomeModule()
{
Get["/"] = _ => {
return View["index.cshtml"];
};
Get["/tasks"] = _ => {
var AllTasks = Task.All();
return View["tasks.cshtml", AllTasks];
};
Get["/tasks/new"] = _ => {
return View["task_form.cshtml"];
};
Get["/tasks/{id}"] = parameters => {
var SelectedTask = Task.Find(parameters.id);
return View["/task.cshtml", SelectedTask];
};
Get["/categories"] = _ => {
var AllCategories = Category.All();
return View["categories.cshtml", AllCategories];
};
Get["/categories/new"] = _ => {
return View["category_form.cshtml"];
};
Post["/categories"] = _ => {
var NewCategory = new Category(Request.Form["category-name"]);
var AllCategories = Category.All();
return View["categories.cshtml", AllCategories];
};
Get["/categories/{id}"] = parameters => {
Dictionary<string, object> model = new Dictionary<string, object>();
var SelectedCategory = Category.Find(parameters.id);
var CategoryTasks = SelectedCategory.GetTasks();
model.Add("category", SelectedCategory);
model.Add("tasks", CategoryTasks);
return View["/category.cshtml", model];
};
Get["/categories/{id}/tasks/new"] = parameters => {
Dictionary<string, object> model = new Dictionary<string, object>();
Category SelectedCategory = Category.Find(parameters.id);
List<Task> AllTasks = SelectedCategory.GetTasks();
model.Add("category", SelectedCategory);
model.Add("tasks", AllTasks);
return View["/category_tasks_form.cshtml", model];
};
Post["/tasks"] = _ => {
Dictionary<string, object> model = new Dictionary<string, object>();
Category SelectedCategory = Category.Find(Request.Form["category-id"]);
List<Task> CategoryTasks = SelectedCategory.GetTasks();
string TaskDescription = Request.Form["task-description"];
Task NewTask = new Task(TaskDescription);
CategoryTasks.Add(NewTask);
model.Add("tasks", CategoryTasks);
model.Add("category", SelectedCategory);
return View["/category.cshtml", model];
};
}
示例5: T2_Equal_ReturnsTrueForSameName
public void T2_Equal_ReturnsTrueForSameName()
{
// Arrange, act
Category firstCategory = new Category("Household chores");
Category secondCategory = new Category("Household chores");
// Assert
Assert.Equal(firstCategory, secondCategory);
}
示例6: Test_CategoryEqualOverrideTrueForSameName
public void Test_CategoryEqualOverrideTrueForSameName()
{
//Arrange, Act
Category firstCategory = new Category("Household chores");
Category secondCategory = new Category("Household chores");
//Assert
Assert.Equal(firstCategory, secondCategory);
}
示例7: LinkButtonSaveCategory_Click
protected void LinkButtonSaveCategory_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
ToDoListEntities context = new ToDoListEntities();
Category Category = new Category();
Category.Name = this.TextBoxCategoryName.Text;
context.Categories.Add(Category);
context.SaveChanges();
Response.Redirect("~/ManageCategories.aspx");
}
}
示例8: 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);
}
示例9: T3_Save_SavesCategoryToDatabase
public void T3_Save_SavesCategoryToDatabase()
{
// Arrange
Category testCategory = new Category("Household chores");
testCategory.Save();
// Act
List<Category> result = Category.GetAll();
List<Category> testList = new List<Category>{testCategory};
// Assert
Assert.Equal(testList, result);
}
示例10: HomeModule
public HomeModule()
{
//Index
Get["/"] = _ => {
List<Category> AllCategories = Category.GetAll();
return View["index.cshtml", AllCategories];
};
//Get: Lists
Get["/tasks"] = _ => {
List<Task> AllTasks = Task.GetAll();
return View["tasks.cshtml", AllTasks];
};
Get["/categories"] = _ => {
List<Category> AllCategories = Category.GetAll();
return View["categories.cshtml", AllCategories];
};
Get["/categories/new"] = _ => {
return View["categories_form.cshtml"];
};
Post["/categories/new"] = _ => {
Category newCategory = new Category(Request.Form["category-name"]);
newCategory.Save();
return View["success.cshtml"];
};
Get["/tasks/new"] = _ => {
List<Category> AllCategories = Category.GetAll();
return View["tasks_form.cshtml", AllCategories];
};
Post["/tasks/new"] = _ => {
Task newTask = new Task(Request.Form["task-description"], Request.Form["category-id"]);
newTask.Save();
return View["success.cshtml"];
};
Post["/tasks/delete"] = _ => {
Task.DeleteAll();
return View["cleared.cshtml"];
};
Get["categories/{id}"] = parameters => {
Dictionary<string, object> model = new Dictionary<string, object>();
var SelectedCategory = Category.Find(parameters.id);
var CategoryTasks = SelectedCategory.GetTasks();
model.Add("category", SelectedCategory);
model.Add("tasks", CategoryTasks);
return View["/category.cshtml", model];
};
}
示例11: 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);
}
示例12: Test_GetTasks_RetrievesAllTasksWithCategory
public void Test_GetTasks_RetrievesAllTasksWithCategory()
{
Category testCategory = new Category("Household chores");
testCategory.Save();
Task firstTask = new Task("Mow the lawn", testCategory.GetId());
firstTask.Save();
Task secondTask = new Task("Do the dishes", testCategory.GetId());
secondTask.Save();
List<Task> testTaskList = new List<Task> {firstTask, secondTask};
List<Task> resultTaskList = testCategory.GetTasks();
Assert.Equal(testTaskList, resultTaskList);
}
示例13: Test_AddCategory_AddsCategoryToTask
public void Test_AddCategory_AddsCategoryToTask()
{
//Arrange
Task testTask = new Task("Mow the lawn", new DateTime(2016, 2, 2), false);
testTask.Save();
Category testCategory = new Category("Home stuff");
testCategory.Save();
//Act
testTask.AddCategory(testCategory);
List<Category> result = testTask.GetCategories();
List<Category> testList = new List<Category>{testCategory};
//Assert
Assert.Equal(testList, result);
}
示例14: Test18_GetCategories_ReturnsAllTaskCategories
public void Test18_GetCategories_ReturnsAllTaskCategories()
{
DateTime testTime = new DateTime(2016, 1, 1);
Task testTask = new Task("Mow the lawn",testTime);
testTask.Save();
Category testCategory1 = new Category("Home Stuff");
testCategory1.Save();
Category testCategory2 = new Category("Work Stuff");
testCategory2.Save();
testTask.AddCategory(testCategory1);
List<Category> result = testTask.GetCategories();
List<Category> testList= new List<Category>{testCategory1};
Assert.Equal(testList,result);
}
示例15: Test_Delete_DeletesCategoryAssociationsFromDatabase
public void Test_Delete_DeletesCategoryAssociationsFromDatabase()
{
//Arrange
Task testTask = new Task("Mow the lawn", false);
testTask.Save();
string testName = "Home stuff";
Category testCategory = new Category(testName);
testCategory.Save();
//Act
testCategory.AddTask(testTask);
testCategory.Delete();
List<Category> resultTaskCategories = testTask.GetCategories();
List<Category> testTaskCategories = new List<Category> {};
//Assert
Assert.Equal(testTaskCategories, resultTaskCategories);
}