I have a POST method which will return the list of items from the user and since I am very new to c# web api, I am having a hardtime putting the right condition and response if the Id is null, empty or invalid. I've tried similar response and it doesn't work mainly because those examples are using iHttpActionResult instead of List<>
here is the code in my controller which I am not sure what to place on the comments I provided:
[HttpPost]
public List<ValueStory> UserValueStories ([FromBody] ValueStory valuestory)
//public void UserValueStories([FromBody] ValueStory Id)
{
if (valuestory.Id == "" || valuestory.Id == null)
{
//what code to add to change status code to 400 and to display error message?
}
//what code to put if the id is not valid, what status code and what message?
var valueStoryName = (from vs in db.ValueStories
where vs.Id == valuestory.Id
select vs).ToList();
List<ValueStory> vs1 = new List<ValueStory>();
foreach (var v in valueStoryName)
{
vs1.Add(new ValueStory()
{
Id = v.Id,
ValueStoryName = v.ValueStoryName,
Organization = v.Organization,
Industry = v.Industry,
Location = v.Location,
AnnualRevenue = v.AnnualRevenue,
CreatedDate = v.CreatedDate,
ModifiedDate = v.ModifiedDate,
MutualActionPlan = v.MutualActionPlan,
Currency = v.Currency,
VSId = v.VSId
});
}
return vs1.ToList();
}
Appreciate some help and some directions on how to do this correctly.