public IHttpActionResult PostSupplyRequest([FromBody] SupplyRequestJson supplyRequestJson) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Add Supply Request SupplyRequest request = new SupplyRequest() { tenantId = supplyRequestJson.TenantId, active = true }; db.SupplyRequests.Add(request); // Add Supply Request Maps foreach (var item in supplyRequestJson.RequestSuppliesMaps) { RequestSuppliesMap map = new RequestSuppliesMap { suppliesRequestId = request.supplyRequestId, supplyId = item.SupplyId }; db.RequestSuppliesMaps.Add(map); } db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = request.supplyRequestId }, request)); }
public IHttpActionResult PutRequestSuppliesMap(int id, [FromBody] RequestSuppliesMap requestSuppliesMap) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != requestSuppliesMap.requestSupplyMapId) { return(BadRequest()); } db.Entry(requestSuppliesMap).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RequestSuppliesMapExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostRequestSuppliesMap([FromBody] RequestSuppliesMap requestSuppliesMap) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.RequestSuppliesMaps.Add(requestSuppliesMap); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = requestSuppliesMap.requestSupplyMapId }, requestSuppliesMap)); }
public IHttpActionResult DeleteRequestSuppliesMap(int id) { RequestSuppliesMap requestSuppliesMap = db.RequestSuppliesMaps.Find(id); if (requestSuppliesMap == null) { return(NotFound()); } db.RequestSuppliesMaps.Remove(requestSuppliesMap); db.SaveChanges(); return(Ok(requestSuppliesMap)); }
// Get one basic table // DEFAULT CRUD public RequestSuppliesMapMapper GetRequestSuppliesMap(int requestSupplyMapId) { RequestSuppliesMap content = db.RequestSuppliesMaps.FirstOrDefault(j => j.requestSupplyMapId == requestSupplyMapId); if (content == null) { return(null); } else { RequestSuppliesMapMapper map = new RequestSuppliesMapMapper() { RequestSupplyMapId = content.requestSupplyMapId, SuppliesRequestId = content.suppliesRequestId ?? default(int), SupplyId = content.supplyId ?? default(int) }; return(map); } }