public HttpResponseMessage DeleteSupplier([FromUri] string supItemId, [FromUri] string supplierId) { using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1()) { try { HttpResponseMessage response = new HttpResponseMessage(); supplier_items itemObj = dbContext.supplier_items.FirstOrDefault(i => i.supItemId == supItemId && i.supplierId == supplierId); if (itemObj == null) { response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Item cannot be found" }); } else { dbContext.supplier_items.Remove(itemObj); dbContext.SaveChanges(); response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Item deleted successfully" }); } return(response); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));; } } }
public HttpResponseMessage GetSupplierItemByKeys([FromUri] string supItemId, [FromUri] string supplierId) { using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1()) { try { HttpResponseMessage response = new HttpResponseMessage(); supplier_items itemObj = dbContext.supplier_items.FirstOrDefault(i => i.supItemId == supItemId && i.supplierId == supplierId); //var itemObj = dbContext.supplier_items.SqlQuery("select * from supplier_items").ToList(); if (itemObj == null) { response = Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = "Item cannot be found" }); } else { response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, data = itemObj }); } return(response); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));; } } }
public HttpResponseMessage PostSupplier([FromBody] supplier_items items) { using (ProcurementDBEntities1 dbContext = new ProcurementDBEntities1()) { try { var result = dbContext.supplier_items.Add(items); dbContext.SaveChanges(); HttpResponseMessage response = new HttpResponseMessage(); response = Request.CreateResponse(HttpStatusCode.OK, new { statusCode = HttpStatusCode.OK, message = "Items Added Succesfully" }); return(response); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.NotFound, new { statusCode = HttpStatusCode.NotFound, message = e.Message }));; } } }