Exemple #1
0
        public IHttpActionResult DeleteTaskList(int id)
        {
            TaskList taskList = new TaskList {
                Id = id
            };

            try
            {
                _taskListManager.DeleteTaskList(taskList);
                return(Ok("Task List with Id: " + id + " deleted"));
            }
            catch (TaskListNotFoundException e)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, e.Message)));
            }
        }
        public void DeleteTaskList(int id)
        {
            ListBox  taskListBox = Application.OpenForms["frmMain"].Controls["taskList"] as ListBox;
            int?     userid      = _securityManager.GetLoggedUserId();
            TaskList taskList    = _taskListManager.GetTaskList(id);

            try
            {
                _taskListManager.DeleteTaskList(taskList);
                ShowTaskList();
            }
            catch (TaskListException)
            {
                MessageBox.Show("You did not select anything");
            }
            catch
            {
                MessageBox.Show("You did not select anything");
            }
        }
        //  [HttpDelete] //not working with
        public ActionResult DeleteTaskList(int id)
        {
            User     user     = _securityManager.GetLoggedUser();
            TaskList taskList = _taskListManager.GetTaskList(id);

            try
            {
                _taskListManager.DeleteTaskList(taskList);
                TempData["ConfirmationMessage"] = "Task List deleted successfully";
                return(RedirectToAction("GetTaskLists", "TaskList", new { currentPageIndex = 1 }));
            }
            catch (TaskListException e)
            {
                ModelState.AddModelError("", e.Message);
                TempData["ConfirmationMessage"] = "Task List not deleted";
                return(RedirectToAction("GetTaskLists", "TaskList", new { currentPageIndex = 1 }));
            }


            //string apiUrl = "http://localhost:51004/Tasklists/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 + Id);

            //    deleteTask.Wait();
            //    var result = deleteTask.Result;
            //    if (result.IsSuccessStatusCode)
            //    {
            //        return RedirectToAction("GetTaskLists", "TaskList");
            //    }

            //    return RedirectToAction("GetTaskLists", "TaskList");
            //}
        }
        public void DeleteTaskList()
        {
            Console.WriteLine("Write an ID of Task List you want to delete");
            int      id       = Int32.Parse(Console.ReadLine());
            TaskList taskList = new TaskList
            {
                Id   = id,
                User = _securityManager.GetLoggedUser()
            };

            try
            {
                _taskListManager.DeleteTaskList(taskList);
                Console.WriteLine("Done");
            }
            catch
            {
                Console.WriteLine("There is no such a Task List ");
            }
            System.Threading.Thread.Sleep(1000);
            ListTaskLists();
        }