I am working on a project and one of the requirements is to be able to list the value stories without using GET method.
I have my controller code here:
// POST api/ValueStories
[ResponseType(typeof(ValueStory))]
public async Task<ValueStory> PostValueStory([FromBody] string value)
{
ValueStory valuestory = await db.ValueStories.FindAsync();
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 valuestory;
}
and this is the code in my model:
namespace WebServicesAPI.Models
{
public class ValueStory
{
[Key]
public int VSId { get; set; }
[Required]
public string ValueStoryName { get; set; }
[Required]
public string Organization { get; set; }
[Required]
public int Industry { get; set; }
[Required]
public string Location { get; set; }
[Required]
public string Currency { get; set; }
[Required]
public double AnnualRevenue { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime ModifiedDate { get; set; }
public string MutualActionPlan { get; set; }
// Foreign Key
public string Id { get; set; }
// Navigation property
public virtual ApplicationUser User { get; set; }
}
}
i tried to test it using Postman by just supplying the ID on the body but I am getting this error [link]https://ibb.co/gn5mZ5
I just started learning C# almost 2 months ago and I am still trying to get myself familiar with it.
Appreciate some help here.