public IHttpActionResult PostNewTask(int taskListId, string text, bool isCompleted) { try { var taskList = _taskListManager.GetTaskList(taskListId); TaskListItem task = new TaskListItem { Text = text, IsCompleted = isCompleted, TaskList = taskList }; _taskListManager.CreateTaskListItem(task); return(Ok("Task: " + text + " IsCompleted: " + isCompleted + " created")); } catch (TaskListNotFoundException e) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, e.Message))); } }
public ActionResult CreateTaskListItem(string text, bool isCompleted) { int id = int.Parse(Session["TaskListId"].ToString()); try { TaskList taskList = _taskListManager.GetTaskList(id); TaskListItem taskListItem = new TaskListItem { Text = text, IsCompleted = isCompleted, TaskList = taskList }; _taskListManager.CreateTaskListItem(taskListItem); TempData["ConfirmationMessage"] = "Task created successfully"; return(RedirectToAction("CreateTaskListItemView", "TaskListItem")); } catch (TaskListItemException e) { ModelState.AddModelError("", e.Message); TempData["ConfirmationMessage"] = "Task not created"; return(RedirectToAction("CreateTaskListItemView", "TaskListItem")); } //string apiUrl = "http://localhost:51004/TaskList/Tasks/Add/"; //using (HttpClient client = new HttpClient()) //{ // string _isCompleted = isCompleted.ToString(); // 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> { { "name", text }, { "isCompleted", _isCompleted } }; // var encodedContent = new FormUrlEncodedContent(parameters); // var postTask = client.PostAsJsonAsync(apiUrl + id + "/"+ text + "/" + isCompleted, parameters); // postTask.Wait(); // var result = postTask.Result; // if (result.IsSuccessStatusCode) // { // return RedirectToAction("CreateTaskListItemView", "TaskListItem"); // } // return RedirectToAction("CreateTaskListItemView", "TaskListItem"); //} }
public void CreateTaskListItem() { Console.WriteLine("Write a name for your Task List Item"); 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 { Text = text, IsCompleted = Completed, TaskList = taskList }; _taskListManager.CreateTaskListItem(taskListItem); Console.WriteLine("Done"); ListTaskListItems(); }
public void AddTaskListItem() { ListView taskListItemView = Application.OpenForms["frmMain"].Controls["taskListItemList"] as ListView; TextBox nameBox = Application.OpenForms["frmMain"].Controls["ItemName"] as TextBox; CheckBox checkBox = Application.OpenForms["frmMain"].Controls["ItemIsCompletedAdd"] as CheckBox; ListBox taskListBox = Application.OpenForms["frmMain"].Controls["taskList"] as ListBox; if (nameBox.Text != "") { int taskListId = int.Parse(taskListBox.SelectedValue.ToString()); TaskList taskList = _taskListManager.GetTaskList(taskListId); TaskListItem taskListItem = new TaskListItem { Text = nameBox.Text, IsCompleted = checkBox.Checked, TaskList = taskList }; _taskListManager.CreateTaskListItem(taskListItem); } else { MessageBox.Show("Don't add a blank Item"); } int tListId = int.Parse(taskListBox.SelectedValue.ToString()); ShowTaskListItems(tListId); }