コード例 #1
0
ファイル: GolferService.cs プロジェクト: rer145/fantasy-golf
        public static void Save(string firstName, string lastName, int tourId)
        {
            //TODO: need to handle spelling updates by passing in ID #

            using (var db = new FantasyGolfContext())
            {
                var query = from x in db.Golfer
                            where x.FirstName == firstName && x.LastName == lastName && x.TourId == tourId
                            select x;

                var golfer = query.FirstOrDefault();

                if (golfer == null)
                {
                    golfer = new Golfer();
                    db.Golfer.Add(golfer);
                }
                else
                {
                    db.Entry(golfer).State = System.Data.Entity.EntityState.Modified;
                }

                golfer.FirstName    = firstName;
                golfer.LastName     = lastName;
                golfer.TourId       = tourId;
                golfer.CreatedOn    = DateTime.Now;
                golfer.LastSyncedOn = null;
                golfer.IsActive     = true;

                db.SaveChanges();

                var cache = new CacheService();
                cache.Remove("fg.golfers");
            }
        }
コード例 #2
0
        public static void SaveResult(int tournamentId, int golferId, int place, decimal winnings, bool isCut, bool isTied, bool isWithdrawn, bool isDisqualified, bool isPlayoff)
        {
            using (var db = new FantasyGolfContext())
            {
                var query = from x in db.TournamentResult
                            where x.TournamentId == tournamentId && x.GolferId == golferId
                            select x;

                var result = query.FirstOrDefault();
                if (result == null)
                {
                    result = new TournamentResult();
                    db.TournamentResult.Add(result);
                }
                else
                {
                    db.Entry(result).State = System.Data.Entity.EntityState.Modified;
                }

                result.TournamentId   = tournamentId;
                result.GolferId       = golferId;
                result.Place          = place;
                result.Winnings       = winnings;
                result.IsCut          = isCut;
                result.IsTied         = isTied;
                result.IsWithdrawn    = isWithdrawn;
                result.IsDisqualified = isDisqualified;
                result.IsPlayoff      = isPlayoff;

                db.SaveChanges();
            }
        }
コード例 #3
0
        public static User GetByAspNetUserId(string aspNetUserId)
        {
            using (var db = new FantasyGolfContext())
            {
                var result = from x in db.User
                             where x.AspNetUserId == aspNetUserId && x.IsActive == true
                             select x;

                return(result.Count <User>() == 0 ? null : result.First());
            }
        }
コード例 #4
0
        public static User Get(string email)
        {
            //var cache = new CacheService();
            //return cache.Get("fg.user-" + email, 60, () =>
            //{
            using (var db = new FantasyGolfContext())
            {
                var result = from x in db.User
                             where x.Email == email && x.IsActive == true
                             select x;

                return(result.FirstOrDefault());
            }
            //});
        }
コード例 #5
0
        public static League Get(int id)
        {
            var cache = new CacheService();

            return(cache.Get("fg.league-" + id.ToString(), 60, () =>
            {
                using (var db = new FantasyGolfContext())
                {
                    var result = from x in db.League
                                 where x.Id == id
                                 select x;

                    return result.FirstOrDefault();
                }
            }));
        }
コード例 #6
0
        public static Tournament Get(int id)
        {
            var cache = new CacheService();

            return(cache.Get("fg.tournament-" + id.ToString(), 60, () =>
            {
                using (var db = new FantasyGolfContext())
                {
                    var result = from x in db.Tournament
                                 where x.Id == id && x.IsActive == true
                                 select x;

                    return result.FirstOrDefault();
                }
            }));
        }
コード例 #7
0
        public static UserPick Get(int userId, int tournamentId)
        {
            var cache = new CacheService();

            return(cache.Get("fg.userpick-" + userId.ToString() + "-" + tournamentId.ToString(), 60, () =>
            {
                using (var db = new FantasyGolfContext())
                {
                    var result = from x in db.UserPick
                                 where x.UserId == userId && x.TournamentId == tournamentId
                                 select x;

                    return result.FirstOrDefault();
                }
            }));
        }
コード例 #8
0
ファイル: GolferService.cs プロジェクト: rer145/fantasy-golf
        public static IList <Golfer> ListActive()
        {
            var cache = new CacheService();

            return(cache.Get("fg.golfers", 60, () =>
            {
                using (var db = new FantasyGolfContext())
                {
                    var result = from x in db.Golfer
                                 where x.IsActive == true
                                 orderby x.LastName, x.FirstName
                    select x;

                    return result.ToList();
                }
            }));
        }
コード例 #9
0
        public static IList <Tournament> List(int leagueId)
        {
            var cache = new CacheService();

            return(cache.Get("fg.tournaments-" + leagueId.ToString(), 60, () =>
            {
                using (var db = new FantasyGolfContext())
                {
                    var result = from lt in db.LeagueTournament
                                 where lt.LeagueId == leagueId && lt.IsActive == true
                                 orderby lt.Tournament.BeginsOn
                                 select lt.Tournament;

                    return result.ToList();
                }
            }));
        }
コード例 #10
0
        public static IList <UserPick> List(int userId)
        {
            var cache = new CacheService();

            return(cache.Get("fg.userpicks-" + userId.ToString(), 60, () =>
            {
                using (var db = new FantasyGolfContext())
                {
                    var result = from x in db.UserPick
                                 where x.UserId == userId
                                 orderby x.Tournament.BeginsOn
                                 select x;

                    return result.ToList();
                }
            }));
        }
コード例 #11
0
        public static IList <User> List(int leagueId)
        {
            var cache = new CacheService();

            return(cache.Get("fg.users-" + leagueId.ToString(), 60, () =>
            {
                using (var db = new FantasyGolfContext())
                {
                    var result = from lu in db.LeagueUser
                                 where lu.LeagueId == leagueId && lu.IsActive == true
                                 orderby lu.User.LastName, lu.User.FirstName
                    select lu.User;

                    return result.ToList();
                }
            }));
        }
コード例 #12
0
        public static League SaveResult(int id, string name, int tourId, int season)
        {
            League result = null;

            using (var db = new FantasyGolfContext())
            {
                if (id > 0)
                {
                    var query = from x in db.League
                                where x.Id == id
                                select x;

                    var temp = query.FirstOrDefault();
                    if (temp == null)
                    {
                        result = new League();
                        db.League.Add(result);
                    }
                    else
                    {
                        result = temp;
                        db.Entry(result).State = System.Data.Entity.EntityState.Modified;
                    }
                }
                else
                {
                    result = new League();
                    db.League.Add(result);
                }

                result.Name                  = name;
                result.TourId                = tourId;
                result.Season                = season;
                result.ManagerId             = 1;
                result.PlayoffFormatId       = 1;
                result.RegularSeasonFormatId = 1;
                result.BeginsOn              = null;
                result.EndsOn                = null;
                result.IsActive              = true;
                result.CreatedOn             = DateTime.Now;

                db.SaveChanges();
            }

            return(result);
        }
コード例 #13
0
        public static IList <League> GetActiveLeagues()
        {
            var cache = new CacheService();

            return(cache.Get("fg.leagues", 60, () =>
            {
                using (var db = new FantasyGolfContext())
                {
                    var result = from x in db.League
                                 where x.IsActive == true
                                 orderby x.Season descending
                                 select x;

                    return result.ToList();
                }
            }));
        }
コード例 #14
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         if (base.IsLeagueSelected)
         {
             using (var db = new FantasyGolfContext())
             {
                 var tournaments = TournamentService.List(this.CurrentLeagueId);
                 tournament_list.DataSource = tournaments;
                 tournament_list.DataBind();
                 tournament_list.Items.Insert(0, "");
                 tournament_list.SelectedIndex = 0;
             }
         }
         message_label_panel.Visible = false;
     }
 }
コード例 #15
0
        public static IList <TournamentGrouping> ListTournamentGroupings(int leagueId)
        {
            var cache = new CacheService();

            return(cache.Get("fg.league-tournament-groupings-" + leagueId.ToString(), 60, () =>
            {
                using (var db = new FantasyGolfContext())
                {
                    var result = from ltg in db.LeagueTournamentGrouping
                                 join tg in db.TournamentGrouping on ltg.TournamentGroupingId equals tg.Id
                                 where ltg.IsActive == true && tg.IsActive == true && tg.LeagueId == leagueId
                                 orderby ltg.TournamentGrouping.Name
                                 select ltg.TournamentGrouping;

                    return result.ToList();
                }
            }));
        }
コード例 #16
0
ファイル: GolferService.cs プロジェクト: rer145/fantasy-golf
        public static IList <Golfer> ListActive(int tournamentId)
        {
            var cache = new CacheService();

            return(cache.Get("fg.golfers-" + tournamentId.ToString(), 60, () =>
            {
                using (var db = new FantasyGolfContext())
                {
                    var result = from x in db.Golfer
                                 join up in db.UserPick on x.Id equals up.GolferId
                                 where x.IsActive == true && up.TournamentId == tournamentId
                                 orderby x.LastName, x.FirstName
                    select x;

                    return result.ToList();
                }
            }));
        }
コード例 #17
0
ファイル: golfers.aspx.cs プロジェクト: rer145/fantasy-golf
        protected void BindData()
        {
            var golfers = GolferService.ListActive();

            golfer_grid.DataSource = golfers;
            golfer_grid.DataBind();

            using (var db = new FantasyGolfContext())
            {
                var tours = from x in db.Tour
                            where x.IsActive == true
                            orderby x.Name
                            select x;

                tour_list.DataSource = tours.ToList();
                tour_list.DataBind();
                tour_list.Items.Insert(0, "");
                tour_list.SelectedIndex = 0;
            }
        }
コード例 #18
0
        public static User Create(string email, string firstName, string lastName, string aspNetUserId)
        {
            User user = new User
            {
                FirstName    = firstName,
                LastName     = lastName,
                Email        = email,
                AspNetUserId = aspNetUserId,
                IsActive     = true,
                CreatedOn    = DateTime.Now
            };

            using (var db = new FantasyGolfContext())
            {
                db.User.Add(user);
                db.SaveChanges();
            }

            return(user);
        }
コード例 #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                _id = Convert.ToInt32(Request.QueryString["id"]);
            }

            if (!Page.IsPostBack)
            {
                league_user_panel.Visible       = (_id > 0);
                league_tournament_panel.Visible = (_id > 0);

                if (_id > 0)
                {
                    League league = LeagueService.Get(_id);
                    name_textbox.Text       = league.Name;
                    tour_list.SelectedValue = league.TourId.ToString();
                    season_textbox.Text     = league.Season.ToString();
                }
                else
                {
                    season_textbox.Text = DateTime.Now.Year.ToString();
                }

                using (var db = new FantasyGolfContext())
                {
                    var tours = from x in db.Tour
                                where x.IsActive == true
                                orderby x.Name
                                select x;

                    tour_list.DataSource = tours.ToList();
                    tour_list.DataBind();
                    tour_list.Items.Insert(0, "");
                    tour_list.SelectedIndex = 0;
                }
            }
        }
コード例 #20
0
        public static void Save(int userId, int tournamentId, int golferId)
        {
            using (var db = new FantasyGolfContext())
            {
                var query = from up in db.UserPick
                            where up.UserId == userId && up.TournamentId == tournamentId
                            select up;

                var pick = query.FirstOrDefault();

                if (pick == null)
                {
                    pick = new UserPick();
                    db.UserPick.Add(pick);
                }
                else
                {
                    db.Entry(pick).State = System.Data.Entity.EntityState.Modified;
                }

                pick.UserId       = userId;
                pick.TournamentId = tournamentId;
                pick.GolferId     = golferId;
                pick.CreatedOn    = DateTime.Now;

                var pickChange = new UserPickChangeLog
                {
                    UserId       = userId,
                    TournamentId = tournamentId,
                    GolferId     = golferId,
                    CreatedOn    = DateTime.Now
                };

                db.UserPickChangeLog.Add(pickChange);
                db.SaveChanges();
            }
        }
コード例 #21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (base.IsLeagueSelected)
                {
                    //load up values
                    //SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ConnectionString);
                    //connection.Open();

                    //var tournaments = connection.Query<Tournament>("Tournament_List", new { LeagueId = base.CurrentLeague }, commandType: CommandType.StoredProcedure);
                    using (var db = new FantasyGolfContext())
                    {
                        var tournaments = TournamentService.List(this.CurrentLeagueId);
                        tournament_list.DataSource = tournaments;
                        tournament_list.DataBind();
                        tournament_list.Items.Insert(0, "");
                        tournament_list.SelectedIndex = 0;

                        //var users = connection.Query<RonsHouse.FantasyGolf.Model.User>("LeagueUser_List", new { LeagueId = base.CurrentLeague }, commandType: CommandType.StoredProcedure);
                        var users = UserService.List(this.CurrentLeagueId);
                        user_list.DataSource = users;
                        user_list.DataBind();
                        user_list.Items.Insert(0, "");
                        user_list.SelectedIndex = 0;

                        //var golfers = connection.Query<Golfer>("select *, LastName + ', ' + FirstName as Name from Golfer order by LastName");
                        var golfers = GolferService.ListActive();
                        golfer_list.DataSource = golfers;
                        golfer_list.DataBind();
                        golfer_list.Items.Insert(0, "");
                        golfer_list.SelectedIndex = 0;
                    }
                }
                message_label_panel.Visible = false;
            }
        }