Exemple #1
0
        // GET api/samples
        public HttpResponseMessage Get()
        {
            try
            {
                var users      = _usersRepository.GetUsers();
                var statuses   = _statusesRepository.GetStatuses();
                var sampleDtos = from s in _samplesRepository.GetSamples()
                                 join u in users on s.CreatedBy equals u.UserId
                                 join st in statuses on s.StatusId equals st.StatusId
                                 select new SampleDto
                {
                    SampleId           = s.SampleId,
                    Barcode            = s.Barcode,
                    CreatedAt          = s.CreatedAt,
                    CreatedById        = s.CreatedBy,
                    CreatedByFirstName = u.FirstName,
                    CreatedByLastName  = u.LastName,
                    StatusId           = s.StatusId,
                    Status             = st.Status1
                };

                var pairs = Request.GetQueryNameValuePairs();
                if (pairs.Any())
                {
                    sampleDtos = filterSampleDtos(sampleDtos, pairs);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, sampleDtos.ToList()));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError,
                                              "There was a problem getting you that data."));
            }
        }
 // GET api/statuses
 public HttpResponseMessage Get()
 {
     try
     {
         var statuses = _statusesRepository.GetStatuses();
         return(Request.CreateResponse(HttpStatusCode.OK, statuses));
     }
     catch (Exception e)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
     }
 }