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)); } }
public async Task <ActionResult <User> > EditPersonaldata(KundenDto kunde) { 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 kundes = _context.Kunde.Where(w => w.K_Nr == user.U_Kunde_Nr).FirstOrDefault(); kundes.K_Vorname = kunde.Vorname; kundes.K_Zuname = kunde.Zuname; kundes.K_Geschlecht = kunde.Geschlecht; kundes.K_Groesse = Encoding.ASCII.GetBytes(kunde.Groesse); kundes.K_Gewicht = Encoding.ASCII.GetBytes(kunde.Gewicht); kundes.K_GebDatum = Encoding.ASCII.GetBytes(kunde.GebDatum); kundes.K_Trainingslevel = _context.Trainingslevel.Where(w => w.tr_levelname == kunde.Trainingslevel).Select(s => s.tr_levelNr).FirstOrDefault(); _context.SaveChanges(); return(Ok(kunde)); }