Beispiel #1
0
 public List <GameSystem> GetGameSystems()
 {
     using (SBEntities db = new SBEntities())
     {
         return(db.GetGameSystems().ToList());
     }
 }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UserControlShackTags.TargetControlID = TextBoxBio.ClientID;
            if (!IsPostBack)
            {
                using (SBEntities db = new SBEntities())
                {
                    UserSession uc = Helper.GetUserSession();
                    User        u  = db.GetUser(uc.userKey);

                    TextBoxGamerTag.Text  = u.GamerTag;
                    TextBoxPSN.Text       = u.PSNID;
                    TextBoxNintendo.Text  = u.NintendoAccount;
                    TextBoxBattleNet.Text = u.BattleNet;
                    TextBoxSteam.Text     = u.SteamAccount;
                    TextBoxOrigin.Text    = u.OriginAccount;
                    TextBoxBio.Text       = u.Bio;

                    var userBattles = (from b in db.Battles
                                       where b.CreatorKey == uc.userKey
                                       select new { b.Title, b.BattleGUID, b.BattleDate }).Take(10).ToList();


                    RepeaterPreviousBattles.DataSource = userBattles;
                    RepeaterPreviousBattles.DataBind();
                }
            }
        }
Beispiel #3
0
        protected void ButtonSearch_Click(object sender, EventArgs e)
        {
            try
            {
                using (SBEntities db = new SBEntities())
                {
                    int    systemID = int.Parse(DropDownListSystem.SelectedValue);
                    string platform = db.GameSystems.Where(w => w.GameSystemKey == systemID).FirstOrDefault().GameDBPlatformID;
                    string search   = "http://thegamesdb.net/api/GetGamesList.php?name=" + HttpUtility.UrlEncode(TextBoxSearch.Text) + "&platform=" + HttpUtility.UrlEncode(platform);

                    MemoryStream  stream = new MemoryStream();
                    XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
                    XmlDocument   doc    = new XmlDocument();
                    doc.Load(search);

                    List <GameDBGamesListResult> searchResults = new List <GameDBGamesListResult>();
                    XmlNodeList games = doc.SelectNodes("Data/Game");
                    foreach (XmlNode result in games)
                    {
                        GameDBGamesListResult game = new GameDBGamesListResult();
                        game.Title       = result.SelectSingleNode("GameTitle").InnerText;
                        game.ReleaseDate = result.SelectSingleNode("ReleaseDate").InnerText;
                        game.id          = result.SelectSingleNode("id").InnerText;
                        searchResults.Add(game);
                    }
                    RepeaterResults.DataSource = searchResults;
                    RepeaterResults.DataBind();
                }
            }
            catch (Exception ex)
            {
                SetError("There was an error searching GameDb.net.  This happens from time to time, you might want to search again.<br/><br/>" + ex.Message);
            }
        }
Beispiel #4
0
 public List <Game> GetSystemGames(int id)
 {
     using (SBEntities db = new SBEntities())
     {
         return(db.GetSystemGames(id).ToList());
     }
 }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (SBEntities db = new SBEntities())
            {
                UserSession user = Helper.GetUserSession();

                _gameKey = int.Parse(Page.RouteData.Values["id"].ToString());
                _userKey = user.userKey;

                GameDetails gd = db.GetGame(_gameKey);
                LiteralGameName.Text    = gd.Game.GameName;
                LiteralGameDetails.Text = Helper.FormatTextToHtml(gd.Game.OverView);
                try
                {
                    LiteralReleaseDate.Text = ((DateTime)gd.Game.ReleaseDate).ToShortDateString();
                }
                catch
                {
                    LiteralReleaseDate.Text = "Not Set";
                }
                LiteralGameSystemName.Text = gd.GameSystemName;
                _gameImage = gd.Game.CoverImage;

                GameFollowerDetails gfd = db.GetGameFollowerDetails(user.userKey, _gameKey);
                _followCount = gfd.FollowerCount;
                _following   = gfd.UserFollowing;

                RepeaterUpcomingBattles.DataSource = db.GetGameUpcomingBattles(_gameKey, _userKey).ToList();
                RepeaterUpcomingBattles.DataBind();

                RepeaterUpcomingBattles.Visible = RepeaterUpcomingBattles.Items.Count > 0;
                LabelNoBattles.Visible          = RepeaterUpcomingBattles.Items.Count == 0;
            }
        }
Beispiel #6
0
        private int UpdateDbUser(string username)
        {
            try
            {
                using (SBEntities dc = new SBEntities())
                {
                    User u;
                    u = dc.Users.Where(w => w.Username == TextBoxLogin.Text.Trim()).FirstOrDefault();
                    if (u == null)
                    {
                        u             = new User();
                        u.Username    = username;
                        u.DateCreated = DateTime.UtcNow;
                        dc.Users.Add(u);
                    }
                    u.LastLogin = DateTime.UtcNow;
                    dc.SaveChanges();

                    return(u.UserKey);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("There was a failure contacting the ShackBattles database.<br/><br/>" + ex.Message);
            }
        }
Beispiel #7
0
        public static void SendBattleCreation(string to, int battleKey)
        {
            try
            {
                using (SBEntities db = new SBEntities())
                {
                    Battle b = db.Battles.Where(w => w.BattleKey == battleKey).FirstOrDefault();

                    if (b != null)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("Title: " + b.Title);
                        sb.AppendLine("Battle Date: " + b.BattleDate.ToLocalTime().ToString() + " EST");
                        sb.AppendLine("");
                        sb.AppendLine("Share or Your Battle:");
                        sb.AppendLine("http://shackbattl.es/view-battle/" + b.BattleGUID);
                        sb.AppendLine("");
                        sb.AppendLine("Edit your battle:");
                        sb.AppendLine("http://shackbattl.es/edit-battle/" + b.BattleGUID);

                        SendShackMessage(to, "Your ShackBattle Has Been Created!", sb.ToString());
                    }
                }
            }
            catch
            {
                // swallow this error we don't really care if this doesn't work.. kinda..
            }
        }
Beispiel #8
0
        public ApiResult FollowBattle([FromBody] string JSONData)
        {
            JObject json    = JObject.Parse(JSONData);
            int     UserKey = (int)json["userKey"];
            int     GameKey = (int)json["gameKey"];
            bool    follow  = (Boolean)json["follow"];

            using (SBEntities sb = new SBEntities())
            {
                sb.UpdateGameFollow(UserKey, GameKey, follow);
            }

            return(new ApiResult(true, string.Empty, "User is following set to : " + follow.ToString()));
        }
Beispiel #9
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Page.EnableViewState = true;
     if (!IsPostBack)
     {
         using (SBEntities db = new SBEntities())
         {
             DropDownListSystem.DataSource     = db.GetGameSystems();
             DropDownListSystem.DataValueField = "GameSystemKey";
             DropDownListSystem.DataTextField  = "GameSystemName";
             DropDownListSystem.DataBind();
             DropDownListSystem.Items.Insert(0, new ListItem("--- SELECT SYSTEM ---", "0"));
         }
     }
 }
Beispiel #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UserSession us = Helper.GetUserSession();

            _userKey = us.userKey;

            using (SBEntities db = new SBEntities())
            {
                RepeaterUpcomingBattles.DataSource = db.GetUpcomingBattles(_userKey);
                RepeaterUpcomingBattles.DataBind();

                RepeaterGames.DataSource = db.GetAllGames();
                RepeaterGames.DataBind();
            }
        }
Beispiel #11
0
 public static void DeleteShackBattle(string battleGUID)
 {
     using (SBEntities db = new SBEntities())
     {
         Battle b = db.Battles.Where(w => w.BattleGUID == battleGUID).FirstOrDefault();
         if (b != null)
         {
             b.Deleted = true;
             db.SaveChanges();
             User          u  = db.Users.Where(w => w.UserKey == b.CreatorKey).FirstOrDefault();
             StringBuilder sb = new StringBuilder();
             sb.AppendLine("Your ShackBattle titled " + b.Title + " was deleted succesfully.");
             ShackNewsHelper.SendShackMessage(u.Username, "Your ShackBattle was Deleted", sb.ToString());
         }
     }
 }
Beispiel #12
0
        protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            using (SBEntities db = new SBEntities())
            {
                UserSession uc = Helper.GetUserSession();
                User        u  = db.GetUser(uc.userKey);

                u.GamerTag        = TextBoxGamerTag.Text.Trim();
                u.PSNID           = TextBoxPSN.Text.Trim();
                u.NintendoAccount = TextBoxNintendo.Text.Trim();
                u.BattleNet       = TextBoxBattleNet.Text.Trim();
                u.SteamAccount    = TextBoxSteam.Text.Trim();
                u.OriginAccount   = TextBoxOrigin.Text.Trim();
                u.Bio             = TextBoxBio.Text.Trim();

                db.SaveChanges();
            }
        }
Beispiel #13
0
        public List <SearchResult> ShackBattlesSearch(string query)
        {
            using (SBEntities db = new SBEntities())
            {
                List <SearchResult> result = (from g in db.Games
                                              join s in db.GameSystems on g.GameSystemKey equals s.GameSystemKey

                                              orderby g.GameName
                                              where g.GameName.Contains(query)
                                              select new SearchResult
                {
                    name = "GAME - " + g.GameName.ToString() + " [" + s.GameSystemName + "]",
                    url = "",
                    key = g.GameKey,
                    systemName = s.GameSystemName
                }).Take(5).ToList();

                result = result.Union((from u in db.Users
                                       where u.Username.Contains(query)
                                       orderby u.Username
                                       select new SearchResult
                {
                    name = "USER - " + u.Username.ToString(),
                    url = "",
                    key = u.UserKey
                }).ToList().Take(5)).ToList();

                foreach (var r in result)
                {
                    if (!string.IsNullOrEmpty(r.systemName))  // returning a game
                    {
                        r.url = "/game/" + r.key + "/" + Helper.CovertStringToSEO(r.systemName) + "/" + Helper.CovertStringToSEO(r.name);
                    }
                    else
                    {
                        r.url = "/player/" + r.key + "/" + Helper.CovertStringToSEO(r.name);
                    }
                }


                return(result);
            }
        }
Beispiel #14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (SBEntities db = new SBEntities())
            {
                int userKey = int.Parse(Page.RouteData.Values["UserKey"].ToString());

                User u = db.GetUser(userKey);

                LiteralShackName.Text   = u.Username;
                LiteralProfileName.Text = u.Username;
                LiteralMemberSince.Text = u.DateCreated.ToShortDateString();
                LiteralGamerTag.Text    = u.GamerTag;
                LiteralPSNID.Text       = u.PSNID;
                LiteralNintendoID.Text  = u.NintendoAccount;
                LiteralBattleNet.Text   = u.BattleNet;
                LiteralSteam.Text       = u.SteamAccount;
                LiteralOrigin.Text      = u.OriginAccount;
                LabelBio.Text           = u.Bio;
            }
        }
Beispiel #15
0
        public ApiResult JoinBattle(JObject data)
        {
            dynamic json       = data;
            int     UserKey    = (int)json.userKey;
            String  battleGUID = json.battleGUID;
            bool    joinBattle = (bool)json.joinBattle;

            try
            {
                using (SBEntities db = new SBEntities())
                {
                    int        battleKey = db.Battles.Where(w => w.BattleGUID == battleGUID).FirstOrDefault().BattleKey;
                    UserBattle ub        = db.UserBattles.Where(w => w.BattleKey == battleKey && w.UsersKey == UserKey).FirstOrDefault();

                    if (joinBattle && ub == null)
                    {
                        ub           = new UserBattle();
                        ub.BattleKey = battleKey;
                        ub.UsersKey  = UserKey;
                        db.UserBattles.Add(ub);
                        db.SaveChanges();
                        return(new ApiResult(true, string.Empty, "User added to battle " + battleGUID));
                    }
                    else if (!joinBattle && ub != null)
                    {
                        db.UserBattles.Remove(ub);
                        db.SaveChanges();
                        return(new ApiResult(true, string.Empty, "User removed from battle " + battleGUID));
                    }
                }
            }
            catch (Exception ex)
            {
                return(new ApiResult(false, string.Empty, ex.Message));
            }

            return(new ApiResult(false, string.Empty, "No changes where made."));
        }
Beispiel #16
0
        public List <UpcomingBattleResult> GetUpcomingShackBattles()
        {
            using (SBEntities db = new SBEntities())
            {
                string baseURL = Helper.GetSiteBaseURL();

                var result = (from r in db.GetUpcomingBattlesAllUsers()
                              select new UpcomingBattleResult
                {
                    Title = r.Title,
                    BattleGUID = r.BattleGUID,
                    CreatorName = r.CreatorName,
                    GameSystemName = r.GameSystemName,
                    BattleDate = r.BattleDate.ToLocalTime().ToString() + " EST",
                    Registered = int.Parse(r.Registered.ToString()),
                    GameName = r.GameName,
                    RegisterURL = baseURL + "view-battle/" + r.BattleGUID,
                    Details = r.Details
                }).ToList();

                return(result);
            }
        }
Beispiel #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UserSession us = Helper.GetUserSession();

            _userKey = us.userKey;

            string BattleGUID = (string)Page.RouteData.Values["BattleGUID"];

            using (SBEntities db = new SBEntities())
            {
                var battleDetails = (from b in db.Battles
                                     join g in db.Games on b.GameKey equals g.GameKey
                                     where b.BattleGUID == BattleGUID
                                     select new { b.Title, b.BattleDate, b.CreatorKey, b.Details, g.GameName, g.CoverImage, b.BattleGUID }).FirstOrDefault();

                var players = (from u in db.Users
                               join ub in db.UserBattles on u.UserKey equals ub.UsersKey
                               join b in db.Battles on ub.BattleKey equals b.BattleKey
                               where b.BattleGUID == BattleGUID
                               select new { u.Username, b.CreatorKey, u.UserKey }).ToList();


                LiteralBattleTitle.Text    = battleDetails.Title;
                LiteralBattleDateTime.Text = battleDetails.BattleDate.ToLocalTime().ToString();
                LiteralBattleDetails.Text  = battleDetails.Details;
                LiteralBattleLink.Text     = "http://" + HttpContext.Current.Request.Url.Host + "/view-battle/" + BattleGUID;

                _creatorKey = battleDetails.CreatorKey;
                _boxArt     = battleDetails.CoverImage;
                _battleGUID = battleDetails.BattleGUID;
                _joined     = players.Count(w => w.UserKey == _userKey);

                RepeaterEnlisted.DataSource = players;
                RepeaterEnlisted.DataBind();
            }
        }
Beispiel #18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UserSession us = Helper.GetUserSession();

            _userKey = us.userKey;

            using (SBEntities db = new SBEntities())
            {
                RepeaterFollowedGames.DataSource = db.GetUserFollowedGames(us.userKey);
                RepeaterFollowedGames.DataBind();
                LitearlEmptyFollowing.Visible = RepeaterFollowedGames.Items.Count == 0;
                RepeaterFollowedGames.Visible = RepeaterFollowedGames.Items.Count != 0;

                RepeaterUserRegisteredBattles.DataSource = db.GetUpcomingUserBattles(us.userKey);
                RepeaterUserRegisteredBattles.DataBind();
                RepeaterUserRegisteredBattles.Visible = RepeaterUserRegisteredBattles.Items.Count != 0;
                LiteralRegisteredBattles.Visible      = RepeaterUserRegisteredBattles.Items.Count == 0;

                RepeaterUpcomingBattlesYouFollow.DataSource = db.GetUserUpcomingFollowedBattles(us.userKey);
                RepeaterUpcomingBattlesYouFollow.DataBind();
                RepeaterUpcomingBattlesYouFollow.Visible = RepeaterUpcomingBattlesYouFollow.Items.Count != 0;
                LitearlUpcomingBattlesYouFollow.Visible  = RepeaterUpcomingBattlesYouFollow.Items.Count == 0;
            }
        }
Beispiel #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String baseURL = Helper.GetSiteBaseURL();

            Response.ContentType = "text/plain";

            StringBuilder sb = new StringBuilder();

            using (SBEntities db = new SBEntities())
            {
                List <GetUpcomingBattlesAllUsers_Result> upcoming = db.GetUpcomingBattlesAllUsers().ToList();
                if (upcoming.Count > 0)
                {
                    foreach (var battle in upcoming)
                    {
                        sb.AppendLine("b[b{" + battle.Title + "}b]b");
                        sb.AppendLine("Playing y{" + battle.GameName + "}y on the y{" + battle.GameSystemName + "}y at b[" + battle.BattleDate.ToLocalTime().ToString("MM/dd/yyyy h:mm") + " EST]b");
                        sb.AppendLine("Created by g{" + battle.CreatorName + "}g");
                        sb.AppendLine("Details and Enlistment : " + baseURL + "view-battle/" + battle.BattleGUID + "/");
                        sb.AppendLine();
                    }
                }
                else
                {
                    List <string> quotes = new List <string>();
                    quotes.Add("There was never a good war, or a bad peace. - y{Benjamin Franklin}y");
                    quotes.Add("Let him who desires peace prepare for war. - y{Publius Flavius Vegetius Renatus}y");
                    quotes.Add("Know thy self, know thy enemy. A thousand battles, a thousand victories. - y{Sun Tzu}y");
                    quotes.Add("The two most powerful warriors are patience and time. - y{Leo Tolstoy}y");
                    quotes.Add("God created war so that Americans would learn geography. - y{Mark Twain}y");
                    quotes.Add("War is peace. Freedom is slavery. Ignorance is strength. - y{George Orwell}y");
                    quotes.Add("The true soldier fights not because he hates what is in front of him, but because he loves what is behind him. - y{G.K. Chesterton}y");
                    quotes.Add("Only the dead have seen the end of war. - y{Plato}y");
                    quotes.Add("Veni, vidi, vici. - y{Gaius Iulius Caesar}y");
                    quotes.Add("Cry havoc and let slip the dogs of war! - y{General Chang}y");
                    quotes.Add("May God have mercy for my enemies because I won't. - y{George S. Patton Jr.}y");
                    quotes.Add("You cannot simultaneously prevent and prepare for war. - y{Albert Einstein}y");
                    quotes.Add("Sometime they'll give a war and nobody will come. - y{Carl Sandburg}y");
                    quotes.Add("Either war is obsolete or men are. - y{R. Buckminster Fuller}y");
                    quotes.Add("Sometime they'll give a war and nobody will come. - y{Carl Sandburg}y");
                    quotes.Add("It is well that war is so terrible - otherwise we would grow too fond of it. - y{Robert E. Lee}y");
                    quotes.Add("The art of war is simple enough. Find out where your enemy is. Get at him as soon as you can. Strike him as hard as you can, and keep moving on. - y{Ulysses S. Grant}y");
                    quotes.Add("Wars are, of course, as a rule to be avoided; but they are far better than certain kinds of peace. - y{Theodore Roosevelt}y");
                    quotes.Add("You can't say that civilization don't advance, however, for in every war they kill you in a new way. - y{Will Rogers}y");
                    quotes.Add("The real and lasting victories are those of peace and not of war. - y{Ralph Waldo Emerson}y");
                    quotes.Add("Jaw jaw is better than war war. - y{Winston Churchill}y");
                    quotes.Add("In time of war the loudest patriots are the greatest profiteers. - y{August Bebel}y");
                    quotes.Add("We make war that we may live in peace. - y{Aristotle}y");
                    quotes.Add("War is too serious a matter to entrust to military men. - y{Georges Clemenceau}y");
                    quotes.Add("There is nothing so likely to produce peace as to be well prepared to meet the enemy. - y{George Washington}y");
                    quotes.Add("Either war is obsolete or men are. - y{R. Buckminster Fuller}y");
                    quotes.Add("Everyone's a pacifist between wars. It's like being a vegetarian between meals. - y{Colman McCarthy}y");
                    quotes.Add("A soldier will fight long and hard for a bit of colored ribbon. - y{Napoleon}y");
                    quotes.Add("War! that mad game the world so loves to play. - y{Jonathan Swift}y");
                    quotes.Add("War is the only game in which it doesn't pay to have the home-court advantage.  - y{Dick Motta}y");
                    quotes.Add("I destroy my enemies when I make them my friends. - y{Abraham Lincoln}y");
                    quotes.Add("I don't know whether war is an interlude during peace, or peace an interlude during war. - y{Georges Clemenceau}y");

                    int    day   = DateTime.Today.Day;
                    string quote = quotes[day - 1];

                    sb.AppendLine("b[r{===}r NO BATTLES CURRENTLY SCHEDULED r{===}r]b");
                    sb.AppendLine();
                    sb.AppendLine(quote);
                    sb.AppendLine();
                }

                sb.AppendLine("Create your own battles at " + baseURL);
            }

            Response.Write(sb.ToString());
        }
Beispiel #20
0
        protected void AddGame_Command(object sender, CommandEventArgs e)
        {
            int gameID = int.Parse(e.CommandArgument.ToString());

            using (SBEntities db = new SBEntities())
            {
                Game g = db.Games.Where(w => w.GamesDbId == gameID).FirstOrDefault();
                if (g != null)
                {
                    // show error
                    SetError("This game is already in the system.");
                    return;
                }
                else
                {
                    g = new Game();
                }

                // if not call and get game details
                string search = "http://thegamesdb.net/api/GetGame.php?id=" + gameID.ToString();

                MemoryStream  stream = new MemoryStream();
                XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
                XmlDocument   doc    = new XmlDocument();
                doc.Load(search);

                List <GameDBGamesListResult> searchResults = new List <GameDBGamesListResult>();
                XmlNode games = doc.SelectSingleNode("Data/Game");
                g.GameSystemKey = int.Parse(DropDownListSystem.SelectedValue);
                g.GameName      = games.SelectSingleNode("GameTitle").InnerText;

                string boxArtPath = "";
                try
                {
                    g.OverView = games.SelectSingleNode("Overview").InnerText;
                }
                catch { g.OverView = ""; }
                g.GamesDbId = int.Parse(games.SelectSingleNode("id").InnerText);
                try
                {
                    g.ReleaseDate = DateTime.Parse(games.SelectSingleNode("ReleaseDate").InnerText);
                }
                catch
                {
                    g.ReleaseDate = null;
                }
                try
                {
                    XmlNode images = games.SelectSingleNode("Images/boxart[@side='front']");
                    g.CoverImage = Path.GetFileName(images.InnerText);
                    boxArtPath   = images.InnerText;
                }
                catch
                {
                    g.CoverImage = "missing.jpg";
                }

                db.Games.Add(g);
                db.SaveChanges();

                try
                {
                    // download and store cover
                    if (!string.IsNullOrEmpty(g.CoverImage) && !string.IsNullOrEmpty(boxArtPath) && g.CoverImage != "missing.jpg")
                    {
                        using (WebClient wc = new WebClient())
                        {
                            string imageUrl = "http://thegamesdb.net/banners/" + boxArtPath;
                            wc.DownloadFile(imageUrl, Server.MapPath("~") + "images/boxart/" + Path.GetFileName(imageUrl));

                            try
                            {
                                Helper.ResizeImage(Server.MapPath("~") + "images/boxart/" + Path.GetFileName(imageUrl), Server.MapPath("~") + "images/boxart/" + Path.GetFileName(imageUrl), 300, 423, false);
                            }
                            catch { }
                        }
                    }
                }
                catch {
                    // image grab failed
                    g.CoverImage = "missing.jpg";
                    db.SaveChanges();
                }

                // done
                PanelMain.Visible = false;
                PanelDone.Visible = true;
            }
        }
Beispiel #21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UserSession user = Helper.GetUserSession();

            _userKey = user.userKey;

            UserControlShackTags.TargetControlID = TextBoxDetails.ClientID;

            if (!IsPostBack)
            {
                using (SBEntities db = new SBEntities())
                {
                    // set hours
                    DropDownListHours.DataSource = Enumerable.Range(0, 96).Select(i => DateTime.Today.AddHours(0).AddMinutes(-1 * ((i + 1) * 15)).ToString("hh:mm tt")).ToList();
                    DropDownListHours.DataBind();

                    DropDownListSystem.DataSource     = db.GetGameSystems();
                    DropDownListSystem.DataValueField = "GameSystemKey";
                    DropDownListSystem.DataTextField  = "GameSystemName";
                    DropDownListSystem.DataBind();
                    DropDownListSystem.Items.Insert(0, new ListItem("--- SELECT SYSTEM ---", "0"));

                    _battleGUID = (string)Page.RouteData.Values["BattleGUID"];
                    if (!string.IsNullOrEmpty(_battleGUID))
                    {
                        var battleInfo = (from b in db.Battles
                                          join g in db.Games on b.GameKey equals g.GameKey
                                          join gs in db.GameSystems on g.GameSystemKey equals gs.GameSystemKey
                                          where b.BattleGUID == _battleGUID
                                          select new { b.BattleGUID, b.Title, b.Details, b.GameKey, b.CreatorKey, gs.GameSystemKey, b.BattleDate }).FirstOrDefault();

                        if (battleInfo != null)
                        {
                            if (battleInfo.CreatorKey != user.userKey) // shoudl not be editing
                            {
                                Response.Redirect("~/home", true);
                            }

                            if (battleInfo.CreatorKey == _userKey)
                            {
                                ButtonDelete.Visible = true;
                            }
                        }

                        DropDownListSystem.Items.FindByValue(battleInfo.GameSystemKey.ToString()).Selected = true;
                        DropDownListGames.DataSource     = db.Games.Where(w => w.GameSystemKey == battleInfo.GameSystemKey).ToList();
                        DropDownListGames.DataValueField = "GameKey";
                        DropDownListGames.DataTextField  = "GameName";
                        DropDownListGames.DataBind();
                        DropDownListGames.Items.FindByValue(battleInfo.GameKey.ToString()).Selected = true;

                        DateTime battleDate = battleInfo.BattleDate.ToLocalTime();

                        TextBoxDate.Text = battleDate.ToString("MM/dd/yyyy");
                        DropDownListHours.Items.FindByValue(battleDate.ToString("hh:mm tt")).Selected = true;

                        TextBoxTitle.Text   = battleInfo.Title;
                        TextBoxDetails.Text = battleInfo.Details;

                        PanelShareURL.Visible = true;
                        TextBoxShareURL.Text  = "http://" + HttpContext.Current.Request.Url.Host + "/view-battle/" + battleInfo.BattleGUID;
                    }
                }
            }
        }
Beispiel #22
0
        public Battle SaveBattle([FromBody] JObject data)
        {
            using (SBEntities db = new SBEntities())
            {
                dynamic json = data;
                try
                {
                    string battleGUID = (string)json["BattleGUID"];

                    // this should handle DST
                    TimeZoneInfo est        = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
                    DateTime     battleDate = TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse((string)json["BattleDate"]), est);
                    Battle       b;
                    bool         newBattle = false;
                    if (!string.IsNullOrEmpty(battleGUID))
                    {
                        b = db.Battles.Where(w => w.BattleGUID == battleGUID).FirstOrDefault();
                    }
                    else
                    {
                        newBattle     = true;
                        b             = new Battle();
                        b.BattleGUID  = Guid.NewGuid().ToString();
                        b.DateCreated = DateTime.UtcNow;
                        b.Deleted     = false;
                        db.Battles.Add(b);
                    }

                    b.GameKey    = (int)json["GameKey"];
                    b.Title      = (string)json["Title"];
                    b.BattleDate = battleDate;
                    b.Details    = (string)json["Details"];
                    b.CreatorKey = (int)json["CreatorKey"];

                    db.SaveChanges();

                    // The user is added to their own battle
                    if (newBattle)
                    {
                        UserBattle ub = db.UserBattles.Where(w => w.UsersKey == b.CreatorKey && w.BattleKey == b.BattleKey).FirstOrDefault();
                        if (ub == null)
                        {
                            ub           = new UserBattle();
                            ub.UsersKey  = b.CreatorKey;
                            ub.BattleKey = b.BattleKey;
                            db.UserBattles.Add(ub);
                            db.SaveChanges();
                        }
                        try
                        {
                            User u = db.Users.Where(w => w.UserKey == b.CreatorKey).FirstOrDefault();
                            if (u != null)
                            {
                                ShackNewsHelper.SendBattleCreation(u.Username, b.BattleKey);
                            }
                        }
                        catch
                        {
                        }
                    }

                    return(b);
                }
                catch (Exception)
                {
                    // TODO: handle
                }
                return(null);
            }
        }