Exemple #1
0
        public async Task <int> GetTotal()
        {
            var shouldHide = await HideFromOtherUsers();

            if (shouldHide.Hide)
            {
                return(await MusicRepository.GetWithUser(shouldHide.UserId).CountAsync());
            }
            else
            {
                return(await MusicRepository.GetWithUser().CountAsync());
            }
        }
        public async Task <RequestsViewModel <AlbumRequest> > GetRequests(int count, int position, string sortProperty, string sortOrder)
        {
            var shouldHide = await HideFromOtherUsers();

            IQueryable <AlbumRequest> allRequests;

            if (shouldHide.Hide)
            {
                allRequests =
                    MusicRepository.GetWithUser(shouldHide
                                                .UserId);
            }
            else
            {
                allRequests =
                    MusicRepository
                    .GetWithUser();
            }

            var prop = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find(sortProperty, true);

            if (sortProperty.Contains('.'))
            {
                // This is a navigation property currently not supported
                prop = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find("RequestedDate", true);
                //var properties = sortProperty.Split(new []{'.'}, StringSplitOptions.RemoveEmptyEntries);
                //var firstProp = TypeDescriptor.GetProperties(typeof(MovieRequests)).Find(properties[0], true);
                //var propType = firstProp.PropertyType;
                //var secondProp = TypeDescriptor.GetProperties(propType).Find(properties[1], true);
            }

            // TODO fix this so we execute this on the server
            var requests = sortOrder.Equals("asc", StringComparison.InvariantCultureIgnoreCase)
                ? allRequests.ToList().OrderBy(x => x.RequestedDate).ToList()
                : allRequests.ToList().OrderByDescending(x => prop.GetValue(x)).ToList();
            var total = requests.Count();

            requests = requests.Skip(position).Take(count).ToList();

            await CheckForSubscription(shouldHide, requests);

            return(new RequestsViewModel <AlbumRequest>
            {
                Collection = requests,
                Total = total
            });
        }
Exemple #3
0
        /// <summary>
        /// Gets the requests.
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <AlbumRequest> > GetRequests()
        {
            var shouldHide = await HideFromOtherUsers();

            List <AlbumRequest> allRequests;

            if (shouldHide.Hide)
            {
                allRequests = await MusicRepository.GetWithUser(shouldHide.UserId).ToListAsync();
            }
            else
            {
                allRequests = await MusicRepository.GetWithUser().ToListAsync();
            }

            allRequests.ForEach(async x =>
            {
                await CheckForSubscription(shouldHide, x);
            });
            return(allRequests);
        }
Exemple #4
0
        /// <summary>
        /// Searches the album request.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <returns></returns>
        public async Task <IEnumerable <AlbumRequest> > SearchAlbumRequest(string search)
        {
            var shouldHide = await HideFromOtherUsers();

            List <AlbumRequest> allRequests;

            if (shouldHide.Hide)
            {
                allRequests = await MusicRepository.GetWithUser(shouldHide.UserId).ToListAsync();
            }
            else
            {
                allRequests = await MusicRepository.GetWithUser().ToListAsync();
            }

            var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList();

            results.ForEach(async x =>
            {
                await CheckForSubscription(shouldHide, x);
            });
            return(results);
        }
Exemple #5
0
        /// <summary>
        /// Gets the requests.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="position">The position.</param>
        /// <param name="orderFilter">The order/filter type.</param>
        /// <returns></returns>
        public async Task <RequestsViewModel <AlbumRequest> > GetRequests(int count, int position,
                                                                          OrderFilterModel orderFilter)
        {
            var shouldHide = await HideFromOtherUsers();

            IQueryable <AlbumRequest> allRequests;

            if (shouldHide.Hide)
            {
                allRequests =
                    MusicRepository.GetWithUser(shouldHide
                                                .UserId); //.Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync();
            }
            else
            {
                allRequests =
                    MusicRepository
                    .GetWithUser();     //.Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync();
            }

            switch (orderFilter.AvailabilityFilter)
            {
            case FilterType.None:
                break;

            case FilterType.Available:
                allRequests = allRequests.Where(x => x.Available);
                break;

            case FilterType.NotAvailable:
                allRequests = allRequests.Where(x => !x.Available);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            switch (orderFilter.StatusFilter)
            {
            case FilterType.None:
                break;

            case FilterType.Approved:
                allRequests = allRequests.Where(x => x.Approved);
                break;

            case FilterType.Processing:
                allRequests = allRequests.Where(x => x.Approved && !x.Available);
                break;

            case FilterType.PendingApproval:
                allRequests = allRequests.Where(x => !x.Approved && !x.Available && !(x.Denied ?? false));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var total = allRequests.Count();

            var requests = await(OrderAlbums(allRequests, orderFilter.OrderType)).Skip(position).Take(count)
                           .ToListAsync();

            requests.ForEach(async x =>
            {
                await CheckForSubscription(shouldHide, x);
            });
            return(new RequestsViewModel <AlbumRequest>
            {
                Collection = requests,
                Total = total
            });
        }