/// <summary>
        /// Gets a list of clubs based on a query
        /// </summary>
        /// <returns>A list of <see cref="Club"/> objects. An empty list if no clubs are found.</returns>
        public async Task <List <Club> > ReadClubs(ClubFilter filter)
        {
            filter = filter ?? new ClubFilter();

            if (filter.TeamIds.Any())
            {
                return(await SelectClubsWhere($"c.ClubId IN (SELECT ClubId FROM {Tables.Team} WHERE TeamId IN @TeamIds)", new { filter.TeamIds }).ConfigureAwait(false));
            }
            else
            {
                return(await SelectClubsWhere("1=1", null).ConfigureAwait(false));
            }
        }
Ejemplo n.º 2
0
 public IActionResult GetClubsList([FromBody] ClubFilter filter)
 {
     try
     {
         var email = User.Claims.SingleOrDefault(c => c.Type == "email")?.Value;
         if (string.IsNullOrEmpty(email))
         {
             return(BadRequest("Authorization failed."));
         }
         return(Ok(_service.GetClubs(filter, email)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 3
0
        public void TestClubFilter()
        {
            const string filter = "1000, d; 1100 - 1500, 3414 4551";

            Assert.IsFalse(ClubFilter.IsMatch(filter, null));
            Assert.IsFalse(ClubFilter.IsMatch(filter, -1));
            Assert.IsTrue(ClubFilter.IsMatch(filter, 1000));
            Assert.IsFalse(ClubFilter.IsMatch(filter, 1001));
            Assert.IsFalse(ClubFilter.IsMatch(filter, 1009));
            Assert.IsTrue(ClubFilter.IsMatch(filter, 1100));
            Assert.IsTrue(ClubFilter.IsMatch(filter, 1300));
            Assert.IsTrue(ClubFilter.IsMatch(filter, 1500));
            Assert.IsFalse(ClubFilter.IsMatch(filter, 1501));
            Assert.IsTrue(ClubFilter.IsMatch(filter, 3414));
            Assert.IsTrue(ClubFilter.IsMatch(filter, 4551));
            Assert.IsFalse(ClubFilter.IsMatch(filter, 4552));
        }
Ejemplo n.º 4
0
 public Page <ClubSummaryDto> GetClubs(ClubFilter filter, string email)
 {
     try
     {
         var currentUser = _unitOfWork.Users.Get(t => t.Email == email).FirstOrDefault();
         if (currentUser == null)
         {
             throw new ArgumentException("Internal error happened. Please try a bit later");
         }
         Func <Club, bool> searchCriteria =
             t => (!filter.IsActive.HasValue || t.IsActive == filter.IsActive.Value) &&
             (!filter.IsFiim.HasValue || t.IsFiim == filter.IsFiim.Value) &&
             (string.IsNullOrEmpty(filter.Country) || string.Equals(t.Country, filter.Country, StringComparison.CurrentCultureIgnoreCase)) &&
             (string.IsNullOrEmpty(filter.City) || string.Equals(t.City, filter.City, StringComparison.CurrentCultureIgnoreCase)) &&
             (string.IsNullOrEmpty(filter.Title) || t.Title.ToLower().StartsWith(filter.Title.ToLower())) &&
             (!filter.CreatorId.HasValue || t.CreatorId == filter.CreatorId.Value) &&
             (filter.Status == ClubStatus.ActiveAndPending ? (t.Status == ClubStatus.Active || t.Status == ClubStatus.PendingActivation) : t.Status == filter.Status);
         var skip         = filter.Page == 0 ? 0 : (filter.Page - 1) * (filter.PageSize ?? 25);
         var take         = filter.PageSize ?? 25;
         var orderByField = string.IsNullOrEmpty(filter.OrderBy) ? nameof(Club.LastUpdate) : filter.OrderBy;
         var allClubs     =
             _unitOfWork.Clubs.GetAsQueryable(t => searchCriteria(t))
             .Include(t => t.Administrators)
             .ThenInclude(t => t.User)
             .Include(t => t.Players)
             .ThenInclude(t => t.User);
         var slice = (filter.Asc ?
                      allClubs.OrderBy(t => typeof(Club).GetProperty(orderByField).GetValue(t)) :
                      allClubs.OrderByDescending(t => typeof(Club).GetProperty(orderByField).GetValue(t)))
                     .Skip(skip)
                     .Take(take);
         var allCount = allClubs.Select(t => t.Id).Count();
         var page     = new Page <ClubSummaryDto>(filter.Page, filter.PageSize ?? 25, allCount, slice.Select(t => t.ToSummaryDto(currentUser.Id)));
         return(page);
     }
     catch (ArgumentException)
     {
         throw;
     }
     catch (Exception e)
     {
         _logger.LogError(e.Message);
         throw new Exception("Error while fetching list of clubs. Please try a bit later");
     }
 }