Exemple #1
0
    private static SelectListItem[] GetRosterSelectList(
        Raven.Client.IDocumentSession session,
        int season,
        string rosterId,
        bool bits,
        Func <Roster, bool> pred)
    {
        IQueryable <Roster> query = session.Query <Roster, RosterSearchTerms>()
                                    .Where(x => x.Season == season)
                                    .Where(x => x.Date < SystemTime.UtcNow)
                                    .Where(x => x.Preliminary == false);

        if (bits)
        {
            query = query.Where(x => x.BitsMatchId != 0);
        }
        else
        {
            query = query.Where(x => x.BitsMatchId == 0);
        }

        SelectListItem[] rosterSelectList = query.OrderBy(x => x.Date)
                                            .ToList()
                                            .Where(x => x.MatchResultId == null || string.IsNullOrEmpty(rosterId) == false)
                                            .Where(pred)
                                            .Select(
            x => new SelectListItem
        {
            Text     = $"{x.Turn}: {x.Team} - {x.Opponent} ({x.Location} {x.Date.ToShortTimeString()})",
            Value    = x.Id,
            Selected = x.Id == rosterId
        })
                                            .ToArray();
        return(rosterSelectList);
    }
Exemple #2
0
    public static SelectListItem[] CreatePlayerSelectList(
        this Raven.Client.IDocumentSession documentSession,
        string player = "",
        Func <Player[]>?getPlayers          = null,
        Func <Player, string>?textFormatter = null)
    {
        List <SelectListItem> playerList = new()
        {
            new SelectListItem
            {
                Text  = "Välj medlem",
                Value = string.Empty
            }
        };

        Player[] query =
            getPlayers != null
                ? getPlayers.Invoke()
                : documentSession.Query <Player, PlayerSearch>()
            .Where(x => x.PlayerStatus == Player.Status.Active)
            .ToArray();

        SelectListItem[] players = query.OrderBy(x => x.Name)
                                   .Select(x => new SelectListItem
        {
            Text     = textFormatter != null ? textFormatter.Invoke(x) : x.Name,
            Value    = x.Id,
            Selected = x.Id == player
        })
                                   .ToArray();
        playerList.AddRange(players);
        return(playerList.ToArray());
    }
Exemple #3
0
 public static int LatestSeasonOrDefault(this Raven.Client.IDocumentSession sess, int def)
 {
     return(sess.Query <Roster, RosterSearchTerms>()
            .OrderByDescending(s => s.Season)
            .Select(r => r.Season)
            .ToList()
            .DefaultIfEmpty(def)
            .First());
 }
Exemple #4
0
 public static User FindUserByEmail(this Raven.Client.IDocumentSession sess, string email)
 {
     return(sess.Query <User, User_ByEmail>()
            .FirstOrDefault(u => u.Email == email));
 }
Exemple #5
0
 public static User FindUserByActivationKey(this Raven.Client.IDocumentSession sess, string key)
 {
     return(sess.Query <User>()
            .FirstOrDefault(u => u.ActivationKey == key));
 }