예제 #1
0
        public async Task <ActionResult <BusinessToShowDto[]> > GetBusinesses([FromQuery] string email = null, [FromQuery] string type = null)
        {
            List <Business> businesses = await _businessService.GetAllBusinesses(email, type);

            if (businesses == null)
            {
                return(NotFound("No businesses found in the database"));
            }
            Business[]          bArray  = businesses.ToArray();
            BusinessToShowDto[] bToShow = new BusinessToShowDto[bArray.GetLength(0)];

            for (int i = 0; i < bArray.GetLength(0); i++)
            {
                bToShow[i] = new BusinessToShowDto();
                foreach (var field in bArray[i].GetType().GetProperties())
                {
                    PropertyInfo pi = bToShow[i].GetType().GetProperty(field.Name);
                    if (pi != null)
                    {
                        pi.SetValue(bToShow[i], field.GetValue(bArray[i]));
                    }
                }
            }
            return(Ok(bToShow));
        }
예제 #2
0
 public HttpResponseMessage GetAllBusinesses(string business_owner)
 {
     try
     {
         List <bussinessDTO> list = BusinessService.GetAllBusinesses(business_owner);
         return(Request.CreateResponse(HttpStatusCode.OK, list));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e));
     }
 }