public IHttpActionResult PutLoanTool(int id, LoanTool loanTool) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != loanTool.LoanToolID) { return(BadRequest()); } db.Entry(loanTool).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LoanToolExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// Add Loaned Tool - Get public ActionResult AddLoanedTool(int loanID) { var loanTool = new LoanTool(); var tools = GetAvailableTools(); loanTool.LoanID = loanID; loanTool.AvailableTools = tools; return(View(loanTool)); }
public IHttpActionResult GetLoanTool(int id) { LoanTool loanTool = db.LoanTools.Find(id); if (loanTool == null) { return(NotFound()); } return(Ok(loanTool)); }
public IHttpActionResult PostLoanTool(LoanTool loanTool) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.LoanTools.Add(loanTool); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = loanTool.LoanToolID }, loanTool)); }
public ActionResult RemoveLoanedTool(int id, LoanTool loanTool) { try { HttpResponseMessage response = WebClient.ApiClient.DeleteAsync($"LoanTool/{id}").Result; TempData["SuccessMessageEdit"] = "Loan Tool removed sucseefully."; var loanToolDeleted = response.Content.ReadAsAsync <LoanTool>().Result; return(RedirectToAction("Edit", new { id = loanToolDeleted.LoanID })); } catch (Exception e) { return(View()); } }
public IHttpActionResult DeleteLoanTool(int id) { LoanTool loanTool = db.LoanTools.Find(id); if (loanTool == null) { return(NotFound()); } db.LoanTools.Remove(loanTool); db.SaveChanges(); return(Ok(loanTool)); }
public ActionResult AddLoanedTool(LoanTool loanTool) { try { int id = loanTool.LoanID; HttpResponseMessage response = WebClient.ApiClient.PostAsJsonAsync("LoanTool", loanTool).Result; TempData["SuccessMessageEdit"] = "Loan Tool added sucseefully."; return(RedirectToAction("Edit", new { id })); } catch { // TODO - Update response message return(View("No record found...")); } }