public async Task <IHttpActionResult> PostRole(RoleDTO value) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DbContext.Roles.Add(RoleTX.ReadFromDTO(new Role(), value)); await DbContext.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { RoleId = value.RoleId }, value)); } catch (Exception ex) { Log.Error("Role.Post: " + ex); throw; } }
public async Task <IHttpActionResult> GetRole(int roleId) { try { RoleDTO found = await Task.Run(() => { return(RoleTX.WriteToDTO(DbContext.Roles .AsEnumerable().FirstOrDefault(e => e.RoleId == roleId))); }); if (found == null) { return(NotFound()); } return(Ok(found)); } catch (Exception ex) { Log.Error("Role.Get: " + ex); throw; } }