TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jayraj Goswami
NA
198
12.6k
Insert Emp Data Web Api
Feb 20 2016 4:33 AM
/*CLS*/
ObjectParameter OutputParamValue = new ObjectParameter("output", typeof(string));
public EmpDTO SaveEmployee(EmpDTO obj)
{
using (GeesemedLocalEntities DB = new GeesemedLocalEntities())
{
DB.InsertEmployee(obj.EmpName, obj.Salary, obj.DeptName, obj.Designation, OutputParamValue);
DB.SaveChanges();
obj.Result = Convert.ToInt32(OutputParamValue.Value);
return obj;
}
}
/*API Controller*/
[Route("SaveEmployee")]
public HttpResponseMessage SaveEmployee(EmpDTO obj)
{
obj = EmpRep.SaveEmployee(obj);
var Responce = Request.CreateResponse<EmpDTO>(HttpStatusCode.Created, obj);
Responce.ReasonPhrase = Convert.ToString(obj.Result);
return Responce;
}
MVC CNtl
public ActionResult SaveEmployee(EmpDTO objDTO)
{
if (ModelState.IsValid)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:6198/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = client.PostAsJsonAsync("api/EmpApi/SaveEmployee", objDTO).Result;
if (response.IsSuccessStatusCode)
{
}
}
}
return RedirectToAction("GetEmployee");
/*View*/
@model SampleMapper.EmpDTO
@{
ViewBag.Title = "SaveEmployee";
}
<h2>SaveEmployee</h2>
@using (Html.BeginForm(FormMethod.Post))
{
<table>
@Html.HiddenFor(m => m.EmpNo)
<tr>
<td>
EmpName :
</td>
<td>
@Html.TextBoxFor(m => m.EmpName, new { @class = "form-control SpeCharNot" })
</td>
</tr>
<tr>
<td>
Salary :
</td>
<td>
@Html.TextBoxFor(m => m.Salary, new { @class = "form-control SpeCharNot" })
</td>
</tr>
</table>
<input type="submit" value="Save" class="btn button" formaction="/Emp/SaveEmployee" />
}
Reply
Answers (
2
)
Error: Could not find a part of the path
Making my web app run on all browsers