public IHttpActionResult PutpensionFundModel(int id, pensionFundModel pensionFundModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pensionFundModel.Id) { return(BadRequest()); } db.Entry(pensionFundModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!pensionFundModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// GET: PensionsInfo public async Task <ActionResult> Index() { pensionFundModel pension = new pensionFundModel(); using (var client = new HttpClient()) { setClientSettings(client); //Get list of Unions HttpResponseMessage Res = await client.GetAsync("api/pensionFundModels/"); pension.pensionList = new List <pensionFundModel>(); //Checking the response is successful or not which is sent using HttpClient if (Res.IsSuccessStatusCode) { //Storing the response details recieved from web api var pensionResponse = Res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Employee list pension.pensionList = JsonConvert.DeserializeObject <List <pensionFundModel> >(pensionResponse); } } return(View(pension)); }
public async Task <ActionResult> Index(pensionFundModel pension) { try { if (ModelState.IsValid) { using (var client = new HttpClient()) { setClientSettings(client); //serialize object to Json and create the HttpContent pension.active = true; HttpContent content = new StringContent(JsonConvert.SerializeObject(pension)); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //Sending request to find web api REST service resource GetAllEmployees using HttpClient HttpResponseMessage Res = await client.PostAsync("api/pensionFundModels/", content); //Checking the response is successful or not which is sent using HttpClient if (Res.IsSuccessStatusCode) { //Storing the response details recieved from web api var UnionResponse = Res.Content.ReadAsStringAsync().Result; } ModelState.Clear(); } return(RedirectToAction("Index")); } using (var client = new HttpClient()) { setClientSettings(client); //Get list of Unions HttpResponseMessage Res = await client.GetAsync("api/pensionFundModels"); pension.pensionList = new List <pensionFundModel>(); //Checking the response is successful or not which is sent using HttpClient if (Res.IsSuccessStatusCode) { //Storing the response details recieved from web api var pensionResponse = Res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Employee list pension.pensionList = JsonConvert.DeserializeObject <List <pensionFundModel> >(pensionResponse); } } return(View(pension)); } catch { return(View(pension)); } }
public IHttpActionResult GetpensionFundModel(int id) { pensionFundModel pensionFundModel = db.pensionFundModels.Find(id); if (pensionFundModel == null) { return(NotFound()); } return(Ok(pensionFundModel)); }
public IHttpActionResult PostpensionFundModel(pensionFundModel pensionFundModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.pensionFundModels.Add(pensionFundModel); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = pensionFundModel.Id }, pensionFundModel)); }
public IHttpActionResult DeletepensionFundModel(int id) { pensionFundModel pensionFundModel = db.pensionFundModels.Find(id); if (pensionFundModel == null) { return(NotFound()); } db.pensionFundModels.Remove(pensionFundModel); db.SaveChanges(); return(Ok(pensionFundModel)); }
public async Task <ActionResult> Edit(int id, pensionFundModel pension) { try { if (ModelState.IsValid) { using (var client = new HttpClient()) { setClientSettings(client); //serialize object to Json and create the HttpContent HttpContent content = new StringContent(JsonConvert.SerializeObject(pension)); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //Sending request to find web api REST service resource GetAllEmployees using HttpClient HttpResponseMessage Res = await client.PutAsync("api/pensionFundModels/" + id, content); //Checking the response is successful or not which is sent using HttpClient if (Res.IsSuccessStatusCode) { //Storing the response details recieved from web api var UnionResponse = Res.Content.ReadAsStringAsync().Result; } } ModelState.Clear(); return(RedirectToAction("Index")); } else { return(View(pension)); } } catch { return(RedirectToAction("Index")); } }
public async Task <ActionResult> Edit(int id) { pensionFundModel pensionInfo = new pensionFundModel(); using (var client = new HttpClient()) { setClientSettings(client); //Sending request to find web api REST service resource GetAllEmployees using HttpClient HttpResponseMessage Res = await client.GetAsync("api/pensionFundModels/" + id); //Checking the response is successful or not which is sent using HttpClient if (Res.IsSuccessStatusCode) { //Storing the response details recieved from web api var EmpResponse = Res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Employee list pensionInfo = JsonConvert.DeserializeObject <pensionFundModel>(EmpResponse); } return(View(pensionInfo)); } }