public void UpdateTaskListItem()
        {
            Console.WriteLine("Write an ID of Task Item you want to update");
            int id = Int32.Parse(Console.ReadLine());

            Console.WriteLine("Write a new text for your Task List");
            string text = Console.ReadLine();

            Console.WriteLine("Is it Completed? Write yes or no");
            string       textCompleted = Console.ReadLine();
            bool         Completed     = textCompleted.Equals("yes") ? true : false;
            TaskList     taskList      = _taskListManager.GetTaskList(ACTUAL_TASK_LIST_ID);
            TaskListItem taskListItem  = new TaskListItem
            {
                Id          = id,
                Text        = text,
                IsCompleted = Completed,
                TaskList    = taskList
            };

            try
            {
                _taskListManager.UpdateTaskListItem(taskListItem);
                Console.WriteLine("Done");
            }
            catch
            {
                Console.WriteLine("There is no such a Task List Item");
            }
            System.Threading.Thread.Sleep(1000);
            ListTaskListItems();
        }
示例#2
0
        public void UpdateTaskListItem(int id)
        {
            TextBox      nameBox       = Application.OpenForms["frmMain"].Controls["ItemNewName"] as TextBox;
            CheckBox     checkBox      = Application.OpenForms["frmMain"].Controls["ItemIsCompletedUpdate"] as CheckBox;
            ListBox      taskListBox   = Application.OpenForms["frmMain"].Controls["taskList"] as ListBox;
            DataGridView itemsGridView = Application.OpenForms["frmMain"].Controls["ItemsGridView"] as DataGridView;
            TaskListItem currentObject = (TaskListItem)itemsGridView.CurrentRow.DataBoundItem;

            if (nameBox.Text != "")
            {
                int      TaskListId = int.Parse(taskListBox.SelectedValue.ToString());
                TaskList taskList   = _taskListManager.GetTaskList(TaskListId);

                int          ItemId       = currentObject.Id;
                TaskListItem taskListItem = new TaskListItem {
                    Id = ItemId, Text = nameBox.Text, IsCompleted = checkBox.Checked, TaskList = taskList
                };
                try
                {
                    _taskListManager.UpdateTaskListItem(taskListItem);
                }
                catch (TaskListItemException e)
                {
                    MessageBox.Show(e.Message);
                }
                catch
                {
                    MessageBox.Show("There is nothing selected to update");
                }
            }
            else
            {
                MessageBox.Show("Don't add a blank Item");
            }
        }
示例#3
0
        public ActionResult EditTaskListItem(int id, string text, bool isCompleted)
        {
            TaskListItem emptyTaskListItem = null;
            int          taskListId        = int.Parse(Session["TaskListId"].ToString());
            TaskList     taskList          = _taskListManager.GetTaskList(taskListId);
            TaskListItem taskListItem      = new TaskListItem {
                Id = id, Text = text, IsCompleted = isCompleted, TaskList = taskList
            };

            try
            {
                _taskListManager.UpdateTaskListItem(taskListItem);
                TempData["ConfirmationMessage"] = "Task edited successfully";
                return(RedirectToAction("GetTaskListItems", "TaskListItem", new { Id = Session["TaskListId"] }));
            }
            catch (TaskListItemException e)
            {
                ModelState.AddModelError("", e.Message);
                TempData["ConfirmationMessage"] = "Task not edited";
                return(View(emptyTaskListItem));
            }


            //string apiUrl = "http://localhost:51004/TaskList/Tasks/Update/";
            //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 parameters = new Dictionary<string, string> { { "id", Id }, { "text", text }, { "isCompleted", _isCompleted} };
            //    var encodedContent = new FormUrlEncodedContent(parameters);

            //    var putTask = client.PutAsJsonAsync(apiUrl + TaskListId +"/" +Id + "/" + text + "/" + _isCompleted, parameters);

            //    putTask.Wait();
            //    var result = putTask.Result;
            //    if (result.IsSuccessStatusCode)
            //    {
            //        return RedirectToAction("GetTaskListItems", "TaskListItem", new { Id = Session["TaskListId"] });
            //    }

            //    return View(taskListItem);
            //}
        }
 public IHttpActionResult PutTask(int taskListId, int taskId, string text, bool isCompleted)
 {
     try
     {
         var          taskList = _taskListManager.GetTaskList(taskListId);
         TaskListItem task     = new TaskListItem {
             Id = taskId, Text = text, IsCompleted = isCompleted, TaskList = taskList
         };
         try
         {
             _taskListManager.UpdateTaskListItem(task);
             return(Ok("Task Id: " + taskId + " text: " + text + " Is it compelted: " + isCompleted + " updated"));
         }
         catch
         {
             return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Task not updated")));
         }
     }
     catch (TaskListNotFoundException e)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, e.Message)));
     }
 }