/// <summary> /// Add a Task to the tasklist /// http://developer.teamwork.com/todolistitems#add_a_task /// </summary> /// <param name="todo">The Task</param> /// <param name="taskListId">Tasklist to add the task to</param> /// <returns>Milestone ID</returns> public async Task <TodoItem> AddTodoItem(TodoItemCreate todo, int taskListId, bool IsSubTask = false, string parentTaskID = "") { var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; string post = JsonConvert.SerializeObject(todo, settings); var requesturi = IsSubTask ? "/tasks/" + parentTaskID + ".json" : "/tasklists/" + taskListId + "/tasks.json"; var newList = await client.HttpClient.PostWithReturnAsync(requesturi, new StringContent("{\"todo-item\": " + post + "}", Encoding.UTF8)); var id = newList.Headers.First(p => p.Key == "id"); if (id.Value != null) { var listresponse = await client.HttpClient.GetAsync <TaskResponse>("/tasks/" + int.Parse(id.Value.First()) + ".json", null, RequestFormat.Json); if (listresponse != null && listresponse.ContentObj != null) { var response = (TaskResponse)listresponse.ContentObj; return(response.TodoItem); } } throw new Exception("Something went wrong whilea dding the task"); }
public async Task <TodoItem> AddTodoItem(TodoItemCreate todo, int taskListId) { var settings = new JsonSerializerSettings() { ContractResolver = new NullToEmptyStringResolver() }; string post = JsonConvert.SerializeObject(todo, settings); var newList = await client.HttpClient.PostWithReturnAsync("/tasklists/" + taskListId + "/tasks.json", new StringContent("{\"todo-item\": " + post + "}", Encoding.UTF8)); var id = newList.Headers.First(p => p.Key == "id"); if (id.Value != null) { var listresponse = await client.HttpClient.GetAsync <TaskResponse>("/tasks/" + int.Parse((string)id.Value.First()) + ".json", null, RequestFormat.Json); if (listresponse != null && listresponse.ContentObj != null) { var response = (TaskResponse)listresponse.ContentObj; return(response.TodoItem); } } return(null); }
public MainWindowViewModel() { this.SignInCommand = new AsyncRelayCommand(SignIn); this.RefreshTodoListCommand = new AsyncRelayCommand(RefreshTodoList, CanRefreshTodoList); this.CreateTodoItemCommand = new AsyncRelayCommand(CreateTodoItem, CanCreateTodoItem); this.TodoItemCreate = new TodoItemCreate(); this.StatusText = "Ready"; }
public async Task <TodoItem> CreateAsync(TodoItemCreate todoItemCreate) { var todoItem = _mapper.Map <TodoItem>(todoItemCreate); var todoItemCreated = _todoItemRepository.Add(todoItem); await _unitOfWork.SaveAsync(); return(todoItemCreated); }
public TodoItem Create(TodoItemCreate todoItemCreate) { var todoItem = _mapper.Map <TodoItem>(todoItemCreate); var todoItemCreated = _todoItemRepository.Add(todoItem); _unitOfWork.Save(); return(todoItemCreated); }
private static async Task CreateTodoItem(TodoItemCreate item) { var client = await GetTodoListClientAsync(false); var newTodoItemRequest = new HttpRequestMessage(HttpMethod.Post, AppConfiguration.TodoListWebApiRootUrl + "api/todolist"); newTodoItemRequest.Content = new JsonContent(item); var newTodoItemResponse = await client.SendAsync(newTodoItemRequest); newTodoItemResponse.EnsureSuccessStatusCode(); }
public async Task <ActionResult> Index(TodoItemCreate model) { if (!string.IsNullOrWhiteSpace(model.Title)) { var client = await GetTodoListClient(this.siteConfiguration, this.User); var newTodoItemRequest = new HttpRequestMessage(HttpMethod.Post, this.siteConfiguration.TodoListWebApiRootUrl + "api/todolist"); newTodoItemRequest.Content = new JsonContent(model); var newTodoItemResponse = await client.SendAsync(newTodoItemRequest); newTodoItemResponse.EnsureSuccessStatusCode(); } return(RedirectToAction("Index")); }
public TodoItemRetrieve Create(TodoItemCreate item) { var now = DateTime.UtcNow; var status = TodoItemStatus.Pending; var objectToCreate = TodoItemMapper.ToDataAccess(item, now, status); var createdThing = _todoItemService.Create(objectToCreate); var history = MakeStatusHistory(createdThing.Id, status, now); return(TodoItemMapper.ToController(createdThing, new List <TodoItemStatusHistoryDataAccess> { history })); }
public async Task <int> AddTodoItemFetchId(TodoItemCreate todo, int taskListId) { var settings = new JsonSerializerSettings() { ContractResolver = new NullToEmptyStringResolver() }; string post = JsonConvert.SerializeObject(todo, settings); var newList = await client.HttpClient.PostWithReturnAsync("/tasklists/" + taskListId + "/tasks.json", new StringContent("{\"todo-item\": " + post + "}", Encoding.UTF8)); var id = newList.Headers.FirstOrDefault(p => p.Key == "id"); return(int.Parse((string)id.Value.FirstOrDefault())); }
public static TodoItemDataAccess ToDataAccess(TodoItemCreate create, DateTime createdDate, TodoItemStatus status = TodoItemStatus.Pending) { if (create == null) { return(null); } return(new TodoItemDataAccess { Title = create.Title, Description = create.Description, Status = status, CreatedDate = createdDate, LastUpdatedDate = createdDate }); }
private async Task RefreshTodoList(object argument) { try { this.StatusText = "Refreshing Todo List..."; var data = await GetTodoListDataAsync(); var categories = data.Item2; this.TodoList = data.Item1.Select(t => new TodoItemViewModel(t, categories.FirstOrDefault(c => string.Equals(c.Id, t.CategoryId, StringComparison.OrdinalIgnoreCase)))).ToList(); this.Categories = categories.Select(c => new CategoryViewModel(c.Id, c.Name, c.IsPrivate)).ToList(); this.TodoItemCreate = new TodoItemCreate { CategoryId = categories.Any() ? categories.First().Id : null }; this.StatusText = string.Format(CultureInfo.CurrentCulture, "Retrieved {0} todo item(s)", this.TodoList.Count); } catch (Exception exc) { ShowException(exc); } }
/// <summary> /// Creates a new todo item for the current user. /// </summary> public async Task <IHttpActionResult> Post(TodoItemCreate value) { if (value == null || string.IsNullOrWhiteSpace(value.Title)) { return(BadRequest("Title is required")); } if (value == null || string.IsNullOrWhiteSpace(value.CategoryId)) { return(BadRequest("CategoryId is required")); } // Create a new category via the Taxonomy Web API if requested. if (!string.IsNullOrWhiteSpace(value.NewCategoryName)) { var client = await CategoryController.GetTaxonomyClient(this.User); var newCategory = new Category { Name = value.NewCategoryName, IsPrivate = value.NewCategoryIsPrivate }; var newCategoryRequest = new HttpRequestMessage(HttpMethod.Post, SiteConfiguration.TaxonomyWebApiRootUrl + "api/category"); newCategoryRequest.Content = new JsonContent(newCategory); var newCategoryResponse = await client.SendAsync(newCategoryRequest); newCategoryResponse.EnsureSuccessStatusCode(); var newCategoryResponseString = await newCategoryResponse.Content.ReadAsStringAsync(); var category = JsonConvert.DeserializeObject <Category>(newCategoryResponseString); value.CategoryId = category.Id; } var userId = this.User.GetUniqueIdentifier(); var data = new TodoItemData(value.Title, value.CategoryId, userId); database.Add(data); return(Ok()); }
public ActionResult <TodoItemRetrieve> Create(TodoItemCreate todoItem) { var createdItem = _itemService.Create(todoItem); return(CreatedAtRoute("GetTodoItem", new { id = createdItem.Id.ToString() }, createdItem)); }
public async Task <ActionResult <TodoItem> > Post(TodoItemCreate todoItemCreate) { var todoItemCreated = await _todoItemService.CreateAsync(todoItemCreate); return(Created("Get", todoItemCreated)); }