public async Task <ActionResult <BusinessToShowDto[]> > getOwnersBusinesses([FromQuery] string email) { List <Business> result = await _businessService.GetOwnerBusiness(email); if (result == null) { return(NotFound("No businesses for business owner")); } Business[] businessesArray = result.ToArray(); BusinessToShowDto[] businessDtoArray = new BusinessToShowDto[businessesArray.GetLength(0)]; for (int i = 0; i < businessesArray.GetLength(0); i++) { businessDtoArray[i] = new BusinessToShowDto(); foreach (var field in businessesArray[i].GetType().GetProperties()) { PropertyInfo pi = businessDtoArray[i].GetType().GetProperty(field.Name); if (pi != null) { pi.SetValue(businessDtoArray[i], field.GetValue(businessesArray[i])); } } } return(Ok(businessDtoArray)); }
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)); }
//////////////////////////////////// //geting one business //////////////////////////////////// public async Task <ActionResult <BusinessToShowDto> > GetByName([FromQuery] string name) { BusinessToShowDto business = new BusinessToShowDto(); Business b = await _businessService.TryGetBusiness(name); if (b == null) { return(NotFound("No business found")); } foreach (var field in b.GetType().GetProperties()) { PropertyInfo pi = business.GetType().GetProperty(field.Name); if (pi != null) { pi.SetValue(business, field.GetValue(b)); } } return(Ok(business)); }