private async void createProject(ProjectViewModel project) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string token = Properties.Settings.Default.ApiToken; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); string serialized = new JavaScriptSerializer().Serialize(project); var response = await client.PostAsync(ServiceURI + "/api/project/CreateProject", new StringContent(serialized, Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { throw new Exception(); } } }
private async void createProjectButton_Click(object sender, EventArgs e) { await getProfile(); listOfFriendsToProject.Add(user.Id); listOfFriendsToProject = listOfFriendsToProject.Distinct().ToList<int>(); DateTime startDate = DateTime.Now; ProjectViewModel project = new ProjectViewModel(1, titleTextBox.Text, descriptionTextBox.Text, DateTime.Now, dateTimePicker1.Value, listOfFriendsToProject); createProject(project); }