public async Task <IHttpActionResult> PostEntity(EntityDTO value) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DbContext.Entities.Add(EntityTX.ReadFromDTO(new Entity(), value)); await DbContext.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { EntityId = value.EntityId }, value)); } catch (Exception ex) { Log.Error("Entity.Post: " + ex); throw; } }
public async Task <IHttpActionResult> GetEntity(int entityId) { try { EntityDTO found = await Task.Run(() => { return(EntityTX.WriteToDTO(DbContext.Entities .AsEnumerable().FirstOrDefault(e => e.EntityId == entityId))); }); if (found == null) { return(NotFound()); } return(Ok(found)); } catch (Exception ex) { Log.Error("Entity.Get: " + ex); throw; } }