public ActionResult Create([Bind(Include = "UserId,UserName,Password,Email")] UserInfo userInfo) { if (ModelState.IsValid) { db.UserInfoes.Add(userInfo); db.SaveChanges(); return(RedirectToAction("Index", "TodoTables")); } return(View(userInfo)); }
public ActionResult Create([Bind(Include = "TodoId,Subject,Body,Date,UserId")] TodoTable todoTable) { if (ModelState.IsValid) { db.TodoTables.Add(todoTable); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.UserInfoes, "UserId", "UserName", todoTable.UserId); return(View(todoTable)); }
protected void OnBtnAddCategory_Click(object sender, EventArgs e) { var dbContext = new TodoListDbEntities(); using (dbContext) { string categoryName = this.TextBoxCategoryName.Text.ToLower(); var existingCategory = dbContext.Categories .FirstOrDefault(cat => cat.Name.ToLower() == categoryName); if (existingCategory != null) { this.TextBoxCategoryName.Text = "This category already exists"; } else { var newCategory = new Category() { Name = categoryName }; dbContext.Categories.Add(newCategory); dbContext.SaveChanges(); this.TextBoxCategoryName.Text = ""; this.BindCategories(); } } }
protected void IsDoneCheckBox_CheckedChanged(object sender, EventArgs e) { var dbContext = new TodoListDbEntities(); using (dbContext) { var checkBox = (CheckBox)sender; var todoListItem = checkBox.Parent; var childControls = todoListItem.Controls; for (int i = 0; i < childControls.Count; i++) { if (childControls[i] is Label && childControls[i].Visible == false) { int todoId = int.Parse((childControls[i] as Label).Text); var todo = dbContext.Todos.Find(todoId); if (todo != null) { todo.IsDone = !todo.IsDone; todo.DateOfLastChange = DateTime.Now; dbContext.SaveChanges(); this.BindTodosForCurrentCategory(); } break; } } } }
protected void OnBtnDeleteTodo_Click(object sender, EventArgs e) { var dbContext = new TodoListDbEntities(); using (dbContext) { var button = (Button)sender; var todoListItem = button.Parent; var childControls = todoListItem.Controls; for (int i = 0; i < childControls.Count; i++) { if (childControls[i] is Label && childControls[i].Visible == false) { int todoId = int.Parse((childControls[i] as Label).Text); var todo = dbContext.Todos.Find(todoId); if (todo != null) { dbContext.Todos.Remove(todo); dbContext.SaveChanges(); this.BindTodosForCurrentCategory(); } break; } } } }
protected void OnBtnDeleteCategory_Click(object sender, EventArgs e) { var dbContext = new TodoListDbEntities(); using (dbContext) { int categoryId = int.Parse(this.DropDownListCategories.SelectedValue); var category = dbContext.Categories.Find(categoryId); if (category != null) { dbContext.Categories.Remove(category); dbContext.SaveChanges(); this.BindCategories(); } } }
protected void OnBtnAddTodo_Click(object sender, EventArgs e) { var dbContext = new TodoListDbEntities(); using (dbContext) { int selectedCategoryId = int.Parse(this.ListBoxCategories.SelectedValue); var selectedCategory = dbContext.Categories.Find(selectedCategoryId); if (selectedCategory != null) { string todoBody = this.TextBoxTodoBody.Text; var existingTodo = selectedCategory.Todos.FirstOrDefault(todo => todo.Body.ToLower() == todoBody.ToLower()); if (existingTodo != null) { this.TextBoxTodoBody.Text = "This todo already exisits"; } else { var newTodo = new Todo() { Body = todoBody, Category = selectedCategory, DateOfLastChange = DateTime.Now, IsDone = false }; dbContext.Todos.Add(newTodo); dbContext.SaveChanges(); this.TextBoxTodoBody.Text = ""; this.BindTodosForCurrentCategory(); } } } }