private object GetSortingValue(ToDoDBModel.TodoItem item, string sortExpression) { switch (sortExpression) { case "Description": return(item.Description); case "WasDone": return(item.WasDone); case "AddedAt": return(item.AddedAt); case "AddedBy": return(this.GetUserName(item.AddedBy)); } return(string.Empty); }
protected void Button_Save_Click(object sender, EventArgs e) { DateTime?wasDoneDateTime = null; byte wasDone = 0; if (CheckBox_WasDone.Checked) { wasDoneDateTime = DateTime.Now; wasDone = 1; } using (var ctx = new ToDoDBModel.ToDoDBEntities()) { string itemIdValue = ItemIdField.Value; ToDoDBModel.TodoItem item = null; if (!String.IsNullOrEmpty(itemIdValue)) { int editingItemId = Int32.Parse(itemIdValue); item = ctx.TodoItems.Where(x => x.Id == editingItemId).First(); if (item != null) { item.Description = TextBox_Decription.Text; if (item.WasDone != wasDone) { if (wasDone == 1) { item.WasDoneAt = wasDoneDateTime; } else { item.WasDoneAt = null; } } item.WasDone = wasDone; item.DueDate = GetDueDate(); } } if (item == null) { item = new ToDoDBModel.TodoItem { Description = TextBox_Decription.Text, AddedAt = DateTime.Now, AddedBy = User.Identity.GetUserId(), WasDone = wasDone, WasDoneAt = wasDoneDateTime, DueDate = GetDueDate() }; ctx.TodoItems.Add(item); } ctx.SaveChanges(); } Response.Redirect("Default.aspx"); }