entity framework - List Data from DB using POST method in C# Web API EF -
i working on project , 1 of requirements able list value stories without using method.
i have 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 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 code in 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 test using postman supplying id on body getting error [link]https://ibb.co/gn5mz5
i started learning c# 2 months ago , still trying myself familiar it.
appreciate here.
i managed working changing controller code to:
// post api/uservaluestories [responsetype(typeof(valuestory))] [route("api/uservaluestories")] [httppost] public list<valuestory> uservaluestories([frombody] valuestory valuestory) //public void uservaluestories([frombody] valuestory id) { var valuestoryname = (from vs in db.valuestories 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(); }
Comments
Post a Comment