public async Task <ActionResult> GetMemberships([FromHeader] string Authentication, [FromQuery] string groupId) { if (SessionManager.GetSessionState(Authentication) != SessionManager.SessionState.Authorized) { return(Unauthorized()); } SessionInfo sessionInfo = SessionManager.GetSessionInfo(Authentication); if (sessionInfo == null) { return(Unauthorized()); } using (UnitOfWork uow = new UnitOfWork()) { MembershipRepository membershipsRepo = new MembershipRepository(uow); IEnumerable <MembershipDTO> memberships = null; int groupIdInt = 0; if (string.IsNullOrEmpty(groupId) || !int.TryParse(groupId, out groupIdInt) || groupIdInt <= 0) { //get by user memberships = await membershipsRepo.GetAllByUserId(sessionInfo.UserId); } else { //get by group memberships = await membershipsRepo.GetAllByGroupId(groupIdInt); } return(Ok(memberships)); } }