public async Task <IHttpActionResult> PostDepartment(DepartmentDTO value) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DbContext.Departments.Add(DepartmentTX.ReadFromDTO(new Department(), value)); await DbContext.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { DepartmentId = value.DepartmentId }, value)); } catch (Exception ex) { Log.Error("Department.Post: " + ex); throw; } }
public async Task <IHttpActionResult> GetDepartment(short departmentId) { try { DepartmentDTO found = await Task.Run(() => { return(DepartmentTX.WriteToDTO(DbContext.Departments .AsEnumerable().FirstOrDefault(e => e.DepartmentId == departmentId))); }); if (found == null) { return(NotFound()); } return(Ok(found)); } catch (Exception ex) { Log.Error("Department.Get: " + ex); throw; } }