public HttpResponseMessage Get() { var dataReader = new ReadCSVData(WebConfigurationManager.AppSettings["CSVPath"]); var president = dataReader.ReadAll(); var rec2 = MapperHelper.CSVMapping(president); return(Request.CreateResponse(HttpStatusCode.OK, rec2)); }
public HttpResponseMessage Get(bool byBDate, bool isAsc = true) { try { var dataReader = new ReadCSVData(WebConfigurationManager.AppSettings["CSVPath"]); var president = dataReader.ReadAll(); var rec2 = MapperHelper.CSVMapping(president); if (byBDate) { if (isAsc) { var result = rec2.OrderBy(x => x.BirthDate).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, result)); } else { var result = rec2.OrderByDescending(x => x.BirthDate).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, result)); } } else { var deathPresidents = rec2.Where(x => x.DeathDate != null).ToList(); var alivePresidents = rec2.Where(x => x.DeathDate == null).ToList(); if (isAsc) { var orderedList = deathPresidents.OrderBy(x => x.DeathDate).ToList(); orderedList.AddRange(alivePresidents); return(Request.CreateResponse(HttpStatusCode.OK, orderedList)); } else { var orderedList = deathPresidents.OrderByDescending(x => x.DeathDate).ToList(); orderedList.AddRange(alivePresidents); return(Request.CreateResponse(HttpStatusCode.OK, orderedList)); } } } catch (Exception ex) { HttpError err = new HttpError(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, err)); } }
public HttpResponseMessage Get(string q) { if (q == null) { HttpError err = new HttpError("q should not be empty"); return(Request.CreateResponse(HttpStatusCode.BadRequest, err)); } try { var dataReader = new ReadCSVData(WebConfigurationManager.AppSettings["CSVPath"]); var president = dataReader.ReadAll(); var rec2 = MapperHelper.CSVMapping(president); var result = rec2.Where(x => x.PresidentName.ToLower().Contains(q.ToLower())).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { HttpError err = new HttpError(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, err)); } }