public ActionResult <IEnumerable <UserGroup> > GetByUserID(string ID) { try { List <UserGroupVM> result = new List <UserGroupVM>(); var data = _userGroupService.GetByUserID(ID); if (data.Count() == 0) { return(NotFound("List empty")); } foreach (var item in data) { result.Add(_mapper.Map <UserGroupVM>(item)); } return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }