c# - WEB API With database Post Method -


i need make api post method insert data database.

the database has 3 fields: 1 field has default values given database, 1 have insert new guid.newguid() method, , 1 inserted user.

how can this? never seen in tutorial.

if can give me example appreciate.

i'm new in web apis , have seen bunch of tutorials since wednesday , can't reach solution.

edit: here code:

public httpresponsemessage post(company value) { try { if(modelstate.isvalid) { bd.companies.add(value); bd.savechanges(); return request.createresponse(httpstatuscode.ok); } else { return request.createresponse(httpstatuscode.internalservererror, "invalid model"); } } catch (exception ex ) { return request.createresponse(httpstatuscode.internalservererror, ex.message); } }

how can put guid.newguid()in code give value 1 of fields?

edit2: class receive values post

public class companypostviewmodel : company { public static guid guid.newguid(); -->how can this? public string name { get; set; } public datetime? createddate { get; set; } }

if looking example, goes front-end, using web api [post], writing database, please see following site. should provide enough context complete trying accomplish. if insufficient, please post current code, , having issues.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -