Im using EF WEB API in ASP to interact with my SQL Database.
The API works well but id like to change the field my [HttpGet("id")] call queries - so rather returning where id =X , it returns based on another field (eg 'User')
My Model:
namespace CapabilityTrackerAPI.Models
{
public partial class Score
{
public int Id { get; set; } \\this is the primary key
public int User { get; set; }
public int SubmissionPeriod { get; set; }
public int Capability { get; set; }
public byte Score1 { get; set; }
}
}
My Controller Code:
[HttpGet("{id}")]
public async Task<ActionResult<Score>> GetScore(int id)
{
var score = await _context.Scores.FindAsync(id);
if (score == null)
{
return NotFound();
}
return score;
}
However rather than return the results corresponding to id - id like to retun values that match the 'User'
Any help or guidance would be very much appreciated
thanks
What I have tried:
[HttpGet("{User}")]
public async Task<ActionResult<Score>> GetScore(int UserId)
{
var score = await _context.Scores.FindAsync(UserId);
if (score == null)
{
return NotFound();
}
return score;
}
But that didn't work - annoyingly
Im not sure if its possible to return based on anything else other than id\Primary Key