public async Task <IHttpActionResult> PutSettingsPause(int id, SettingsPause settingsPause) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != settingsPause.Id) { return(BadRequest()); } db.Entry(settingsPause).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SettingsPauseExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetSettingsPause(int id) { SettingsPause settingsPause = await db.SettingsPauses.FindAsync(id); if (settingsPause == null) { return(NotFound()); } return(Ok(settingsPause)); }
public async Task <IHttpActionResult> PostSettingsPause(SettingsPause settingsPause) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.SettingsPauses.Add(settingsPause); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = settingsPause.Id }, settingsPause)); }
public async Task <bool> RegisterSettingsPause(SettingsPause pause) { var json = JsonConvert.SerializeObject(pause); var httpClient = new HttpClient(); var content = new StringContent(json, Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Settings.Accesstoken); var settingsApiUrl = "http://calendaradhd.azurewebsites.net/api/SettingsPauses/PostSettingsPause"; var response = await httpClient.PostAsync(settingsApiUrl, content); return(response.IsSuccessStatusCode); }
public async Task Test_Add_SettingsPause_Async() { ApiServices apiServices = new ApiServices(); var pause = new SettingsPause() { MinPauseBeforeActivity = 10, CalendarUserEmail = "*****@*****.**" }; bool response = await apiServices.RegisterSettingsPause(pause); Assert.IsNotNull(response); }
public async Task <IHttpActionResult> DeleteSettingsPause(int id) { SettingsPause settingsPause = await db.SettingsPauses.FindAsync(id); if (settingsPause == null) { return(NotFound()); } db.SettingsPauses.Remove(settingsPause); await db.SaveChangesAsync(); return(Ok(settingsPause)); }
private async void BtnSignUp_OnClicked(object sender, EventArgs e) { ApiServices apiServices = new ApiServices(); var pause = new SettingsPause() { MinPauseBeforeActivity = Convert.ToInt32(EntMin.Text), CalendarUserEmail = _email }; bool response = await apiServices.RegisterSettingsPause(pause); if (response == true) { await DisplayAlert("Hej", "Tid för vila registrerat!", "Ok"); await Navigation.PopToRootAsync(); } else { await DisplayAlert("Oops", "Något gick fel!", "Ok"); await Navigation.PopToRootAsync(); } }