public void DeleteTaskListItem(int id) { ListBox taskListBox = Application.OpenForms["frmMain"].Controls["taskList"] as ListBox; DataGridView itemsGridView = Application.OpenForms["frmMain"].Controls["ItemsGridView"] as DataGridView; TaskListItem currentItemObject = (TaskListItem)itemsGridView.CurrentRow.DataBoundItem; int taskListId = int.Parse(taskListBox.SelectedValue.ToString()); TaskList taskList = _taskListManager.GetTaskList(taskListId); int itemId = currentItemObject.Id; string text = currentItemObject.Text; bool completed = currentItemObject.IsCompleted; TaskListItem taskListItem = new TaskListItem { Id = itemId, Text = text, IsCompleted = completed, TaskList = taskList }; try { _taskListManager.DeleteTaskListItem(taskListItem); } catch (TaskListItemException e) { MessageBox.Show(e.Message); } catch { MessageBox.Show("There is nothing selected to delete"); } }
public IHttpActionResult DeleteTask(int taskListId, int taskId) { var taskList = _taskListManager.GetTaskList(taskListId); TaskListItem task = new TaskListItem { Id = taskId, TaskList = taskList }; try { _taskListManager.DeleteTaskListItem(task); return(Ok("Task with Id: " + taskId + " deleted")); } catch { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Task not deleted"))); } }
public ActionResult DeleteTaskListItem(int id) { int taskListId = int.Parse(Session["TaskListId"].ToString()); try { TaskList taskList = _taskListManager.GetTaskList(taskListId); TaskListItem task = new TaskListItem { Id = id, TaskList = taskList }; _taskListManager.DeleteTaskListItem(task); TempData["ConfirmationMessage"] = "Task deleted successfully"; return(RedirectToAction("GetTaskListItems", "TaskListItem", new { Id = Session["TaskListId"] })); } catch (Exception e) { ModelState.AddModelError("", e.Message); TempData["ConfirmationMessage"] = "Task not deleted"; return(RedirectToAction("GetTaskListItems", "TaskListItem", new { Id = Session["TaskListId"] })); } //string apiUrl = "http://localhost:51004/TaskList/Tasks/Delete/"; //using (HttpClient client = new HttpClient()) //{ // client.BaseAddress = new Uri(apiUrl); // client.DefaultRequestHeaders.Accept.Clear(); // client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); // var deleteTask = client.DeleteAsync(apiUrl + TaskListId +"/"+ Id); // deleteTask.Wait(); // var result = deleteTask.Result; // if (result.IsSuccessStatusCode) // { // return RedirectToAction("GetTaskListItems", "TaskListItem", new { Id = Session["TaskListId"] }); // } // return RedirectToAction("GetTaskListItems", "TaskListItem", new { Id = Session["TaskListId"] }); //} }
public void DeleteTaskListItem() { Console.WriteLine("Write an ID of Task Item you want to delete"); int id = Int32.Parse(Console.ReadLine()); TaskList taskList = _taskListManager.GetTaskList(ACTUAL_TASK_LIST_ID); TaskListItem taskListItem = new TaskListItem { Id = id, TaskList = taskList }; try { _taskListManager.DeleteTaskListItem(taskListItem); Console.WriteLine("Done"); } catch { Console.WriteLine("There is no such a Task List Item"); } System.Threading.Thread.Sleep(1000); ListTaskListItems(); }