public IActionResult putAthlete(string username, [FromBody] Athlete athlete) { try { string attribsToModify = "username = '******', password = '******', full_name = '" + athlete.full_name; } } if (athlete.nationality != null) { if (!((athlete.nationality).Equals(""))) { attribsToModify = attribsToModify + "', nationality = '" + athlete.nationality; } } if (athlete.photo != null) { if (!((athlete.photo).Equals(""))) { attribsToModify = attribsToModify + "', photo = '" + athlete.photo; } } if (athlete.birth_date != DateTime.MinValue) { athlete.setAge(); attribsToModify = attribsToModify + "', birth_date = '" + athlete.birth_date + "', age = " + athlete.getAge();; } dataBaseHandler.updateDataBase(DataBaseConstants.athlete, attribsToModify, "username = '******'"); return(Ok()); } else { return(BadRequest()); } } catch //(Exception e) { return(BadRequest()); } }
public IActionResult postAthlete([FromBody] Athlete athlete) { if (ModelState.IsValid) { if (athlete.username == null) { return(BadRequest()); } if (athlete.birth_date != DateTime.MinValue) { athlete.setAge(); } if (athlete.password == null) { return(BadRequest()); } if (athlete.full_name == null) { return(BadRequest()); } dataBaseHandler.insertDataBase(DataBaseConstants.athlete, "username, password, full_name, nationality, birth_date, photo, age", athlete.username + "','" + athlete.password + "','" + athlete.full_name + "','" + athlete.nationality + "','" + athlete.birth_date + "','" + athlete.photo + "'," + athlete.getAge()); return(Ok()); } else { return(BadRequest()); } }