Example #1
0
        private IList <FavoriteLabel> GetFavoriteLabelsAndCheckAuthorization(IList <long> labelIds, int userId)
        {
            if (labelIds == null || labelIds.Count == 0)
            {
                var defaultLabel = m_favoritesRepository.GetDefaultFavoriteLabel(userId);
                return(new List <FavoriteLabel> {
                    defaultLabel
                });
            }

            var labels = m_favoritesRepository.GetFavoriteLabelsById(labelIds);

            if (labels.Any(x => x.User.Id != userId))
            {
                throw new UnauthorizedAccessException();
            }

            if (labels.Count != labelIds.Count)
            {
                throw new ArgumentException("All specified labels were not found");
            }

            return(labels);
        }