public async Task <ActionResult <FitnessHistoryDto> > addWorkout([FromBody] FitnessHistoryDto fitnessHistoryDto) { try { string username = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value ?? ""; User user = _context.User.Where(d => username.ToLower() == d.U_Name.ToLower()).FirstOrDefault(); Kunde kunde = _context.Kunde.Find(user.U_Kunde_Nr); Fitness_history history = new Fitness_history { FH_Date = Encoding.ASCII.GetBytes(fitnessHistoryDto.Date), FH_Bewertung = Encoding.ASCII.GetBytes(fitnessHistoryDto.Bewertung), FH_Kunde_Nr = long.Parse("" + kunde.K_Nr), FH_Fitness_Uebungen_Nr = fitnessHistoryDto.UebungsNr }; _context.Fitness_history.Add(history); _context.SaveChanges(); return(Ok(fitnessHistoryDto)); } catch (DbUpdateException) { return(BadRequest()); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
private async Task finishedAsync() { //string result = await DisplayPromptAsync("Workout rating","-How do you feel-", maxLength: 1, keyboard: Keyboard.Numeric); try { FitnessHistoryDto w = new FitnessHistoryDto { Date = DateTime.Now + "", Bewertung = "3.67", UebungsNr = (long)Convert.ToDouble(Nr.Text) }; await RestService.Instance.SendAsync <FitnessHistoryDto>(HttpMethod.Post, "fitness/addWorkout", "", w); NavigationPage newNavigation = new NavigationPage(); await newNavigation.PushAsync(new DashboardPage()); Application.Current.MainPage = new MainPage(newNavigation); } catch (Exception ex) { await DisplayAlert("Warning", "Did not save changes!", "OK"); } }