public async Task <IHttpActionResult> Puttbl_Requirements(int id, tbl_Requirements tbl_Requirements) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tbl_Requirements.col_RequirementID) { return(BadRequest()); } db.Entry(tbl_Requirements).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!tbl_RequirementsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> Posttbl_Requirements(tbl_Requirements tbl_Requirements) { LogApi.Log(User.Identity.GetUserId(), "PostRequirement " + User.Identity.GetUserName()); var id = User.Identity.GetUserId(); tbl_Requirements.col_PostedBy = id; tbl_Requirements.col_RequirementPostedDate = DateTime.Now; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.tbl_Requirements.Add(tbl_Requirements); await db.SaveChangesAsync(); try { var tokens = db.tbl_DeviceIds; foreach (var d in tokens) { Notifications.NotifyAsync(d.col_DeviceToken, "Requirement", "New Requirement: " + tbl_Requirements.col_RequirementCategory + "#" + tbl_Requirements.col_RequirementDescription + "#" + id); } } catch (Exception ex) { return(Ok("Failed")); } return(Ok("Posted")); }
public async Task <IHttpActionResult> Gettbl_Requirements(int id) { tbl_Requirements tbl_Requirements = await db.tbl_Requirements.FindAsync(id); if (tbl_Requirements == null) { return(NotFound()); } return(Ok(tbl_Requirements)); }
public async Task <IHttpActionResult> Deletetbl_Requirements(int id) { LogApi.Log(User.Identity.GetUserId(), "DeleteRequirement " + User.Identity.GetUserName()); tbl_Requirements tbl_Requirements = await db.tbl_Requirements.FindAsync(id); if (tbl_Requirements == null) { return(NotFound()); } db.tbl_Requirements.Remove(tbl_Requirements); await db.SaveChangesAsync(); return(Ok("Deleted")); }