public async Task <IHttpActionResult> Get(int id = 0) { string methodNameStr = $"InternShipController().Get({id})"; try { logger.Log(LogLevel.Info, $"{MakeLogStr4Entry(methodNameStr)}."); using (var context = new SampDB()) { var repos = new GenericDataRepository(context); var res = await repos.GetAsync <InternShip>(id); if (res != null) { logger.Log(LogLevel.Info, $"{MakeLogStr4Exit(methodNameStr)} {res}"); return(Content(HttpStatusCode.OK, res)); } else { logger.Log(LogLevel.Info, $"{MakeLogStr4Exit(methodNameStr)} No content returned by repository."); return(Content(HttpStatusCode.NotFound, HttpStatusCode.NotFound)); } } } catch (Exception e) { logger.Log(LogLevel.Error, $"{MakeLogStr4Exit(methodNameStr)}:\r\n{e}"); return(Content(HttpStatusCode.InternalServerError, HttpStatusCode.InternalServerError.ToString())); } }
public async Task <IHttpActionResult> Get(int id = 0) { string methodNameStr = $"StudentController().Get({id})"; try { logger.Log(LogLevel.Info, $"{MakeLogStr4Entry(methodNameStr)}."); using (var context = new SampDB()) { var repos = new GenericDataRepository(context); var res = await repos.GetAsync <Student>(id); if (res != null) { var reslist = new List <StudentDTO>(); foreach (var record in res) { List <dynamic[]> tmpCourseIds = (List <dynamic[]>) await repos.GetPKs4EntityManyAsync <Student, Course>(record); var CourseIds = Convert2DTo1D(tmpCourseIds); reslist.Add(MakeStudentDTO(record, CourseIds)); } logger.Log(LogLevel.Info, $"{MakeLogStr4Exit(methodNameStr)} {reslist}"); return(Content(HttpStatusCode.OK, reslist)); } else { logger.Log(LogLevel.Info, $"{MakeLogStr4Exit(methodNameStr)} No content returned by repository."); return(Content(HttpStatusCode.NotFound, HttpStatusCode.NotFound)); } } } catch (Exception e) { logger.Log(LogLevel.Error, $"{MakeLogStr4Exit(methodNameStr)}:\r\n{e}"); return(Content(HttpStatusCode.InternalServerError, HttpStatusCode.InternalServerError.ToString())); } }