public void CreateTeamWithTooManyDefenders() { Player p1 = new Player() { PlayerFirstname = "Shay", PlayerSurname = "Given", DateOfBirth = DateTime.Parse("1982-03-10"), PlayerValue = 4.5, Position = Position.GoalKeeper, NationCode = "IRE", PlayerID = 001, GoalWeight = .002 }; Player p2 = new Player { PlayerFirstname = "Seamus", PlayerSurname = "Coleman", DateOfBirth = DateTime.Parse("1984-04-10"), PlayerValue = 4.5, Position = Position.Defender, NationCode = "IRE", PlayerID = 002, GoalWeight = .07 }; Player p3 = new Player { PlayerFirstname = "John", PlayerSurname = "O'Shea", DateOfBirth = DateTime.Parse("1984-08-10"), PlayerValue = 4.4, Position = Position.Defender, NationCode = "IRE", PlayerID = 003, GoalWeight = .07 }; Player p4 = new Player { PlayerFirstname = "Ciaran", PlayerSurname = "Clarke", DateOfBirth = DateTime.Parse("1988-04-10"), PlayerValue = 4.5, Position = Position.Defender, NationCode = "IRE", PlayerID = 004, GoalWeight = .07 }; Player p5 = new Player { PlayerFirstname = "James", PlayerSurname = "McClean", DateOfBirth = DateTime.Parse("1987-04-10"), PlayerValue = 4.3, Position = Position.Defender, NationCode = "IRE", PlayerID = 005, GoalWeight = .06 }; Player p6 = new Player { PlayerFirstname = "Jonas", PlayerSurname = "Olsson", DateOfBirth = DateTime.Parse("1981-03-12"), PlayerValue = 5.2, Position = Position.Defender, NationCode = "SWE", PlayerID = 015, GoalWeight = .07 }; FantasyTeam myTeam = new FantasyTeam() { TeamName = "manCity" }; myTeam.Players = new List <Player>(); myTeam.AddPlayer(p2); myTeam.AddPlayer(p3); myTeam.AddPlayer(p4); myTeam.AddPlayer(p5); myTeam.AddPlayer(p6); }
//UpdateFantasyPlayers checks to see if the checked player has already been added. If not this player is then added to team private void UpdateFantasyPlayers(string[] selectedPlayers, FantasyTeam fantasyTeamToUpdate) { if (selectedPlayers == null) { fantasyTeamToUpdate.Players = new List <Player>(); return; } var selectedPlayersHS = new HashSet <string>(selectedPlayers); var fantasyPlayers = new HashSet <int> (fantasyTeamToUpdate.Players.Select(p => p.PlayerID)); foreach (var player in db.Players) { try { if (selectedPlayersHS.Contains(player.PlayerID.ToString())) { if (!fantasyPlayers.Contains(player.PlayerID)) { fantasyTeamToUpdate.AddPlayer(player); } } else { if (fantasyPlayers.Contains(player.PlayerID)) { fantasyTeamToUpdate.Players.Remove(player); } } } catch (Exception e) { e.ToString(); } } db.SaveChanges(); }
public void CreateTeamWithTooManyMidfielders() { Player p10 = new Player { PlayerFirstname = "Glen", PlayerSurname = "Whealen", DateOfBirth = DateTime.Parse("1984-03-10"), PlayerValue = 4.8, Position = Position.Midfielder, NationCode = "IRE", PlayerID = 007, GoalWeight = .1 }; Player p11 = new Player { PlayerFirstname = "Wes", PlayerSurname = "Houlihan", DateOfBirth = DateTime.Parse("1981-04-10"), PlayerValue = 4.9, Position = Position.Midfielder, NationCode = "IRE", PlayerID = 008, GoalWeight = .1 }; Player p8 = new Player { PlayerFirstname = "Robbie", PlayerSurname = "Brady", DateOfBirth = DateTime.Parse("1987-03-10"), PlayerValue = 5.5, Position = Position.Midfielder, NationCode = "IRE", PlayerID = 006, GoalWeight = .11 }; Player p19 = new Player { PlayerFirstname = "Albin", PlayerSurname = "Ekdal", DateOfBirth = DateTime.Parse("1991-03-12"), PlayerValue = 5.4, Position = Position.Midfielder, NationCode = "SWE", PlayerID = 019, GoalWeight = .09 }; Player p20 = new Player { PlayerFirstname = "Kim", PlayerSurname = "Kallstrom", DateOfBirth = DateTime.Parse("1990-03-12"), PlayerValue = 5.6, Position = Position.Midfielder, NationCode = "SWE", PlayerID = 020, GoalWeight = .09 }; FantasyTeam myTeam = new FantasyTeam() { TeamName = "manCity" }; myTeam.Players = new List <Player>(); myTeam.AddPlayer(p10); myTeam.AddPlayer(p11); myTeam.AddPlayer(p8); myTeam.AddPlayer(p19); myTeam.AddPlayer(p20); }
//all players in database are shown in view under the following categories - goalkeeper, defender, midfielder and forward private void PopulateTeam(FantasyTeam fantasyTeam) { var goalkeepers = db.Players.ToList().Where(p => p.Position == Position.GoalKeeper); var defenders = db.Players.ToList().Where(p => p.Position == Position.Defender); var midfielders = db.Players.ToList().Where(p => p.Position == Position.Midfielder); var forwards = db.Players.ToList().Where(p => p.Position == Position.Forward); var fantasyPlayers = new HashSet <int>(fantasyTeam.Players.Select(p => p.PlayerID)); var viewModelDef = new List <ViewPlayers>(); var viewModelMid = new List <ViewPlayers>(); var viewModelGk = new List <ViewPlayers>(); var viewModelFwd = new List <ViewPlayers>(); foreach (var player in goalkeepers) { viewModelGk.Add(new ViewPlayers { playerId = player.PlayerID, playerName = player.PlayerFirstname + " " + player.PlayerSurname + " " + player.NationCode + " " + player.Position + " " + player.PlayerValue + " ", PlayerValue = player.PlayerValue, added = fantasyPlayers.Contains(player.PlayerID) }); } foreach (var player in defenders) { viewModelDef.Add(new ViewPlayers { playerId = player.PlayerID, playerName = player.PlayerFirstname + " " + player.PlayerSurname + " " + player.NationCode + " " + player.Position + " " + player.PlayerValue + " ", PlayerValue = player.PlayerValue, added = fantasyPlayers.Contains(player.PlayerID) }); } foreach (var player in midfielders) { viewModelMid.Add(new ViewPlayers { playerId = player.PlayerID, playerName = player.PlayerFirstname + " " + player.PlayerSurname + " " + player.NationCode + " " + player.Position + " " + player.PlayerValue + " ", PlayerValue = player.PlayerValue, added = fantasyPlayers.Contains(player.PlayerID) }); } foreach (var player in forwards) { viewModelFwd.Add(new ViewPlayers { playerId = player.PlayerID, playerName = player.PlayerFirstname + " " + player.PlayerSurname + " " + player.NationCode + " " + player.Position + " " + player.PlayerValue + " ", PlayerValue = player.PlayerValue, added = fantasyPlayers.Contains(player.PlayerID) }); } ViewBag.Forwards = viewModelFwd; ViewBag.Goalkeepers = viewModelGk; ViewBag.Defenders = viewModelDef; ViewBag.Midfielders = viewModelMid; }
public ActionResult DeleteConfirmed(int id) { FantasyTeam fantasyTeam = db.FantasyTeams.Find(id); db.FantasyTeams.Remove(fantasyTeam); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task UpdateDb(int FantasyTeamId, int playerId) { Player DraftedPlayer = _context.Players.SingleOrDefault(p => p.PlayerId == playerId); FantasyTeam PickingTeam = _context.FantasyTeams.SingleOrDefault(f => f.FantasyTeamId == FantasyTeamId); PickingTeam.Players.Add(DraftedPlayer); _context.SaveChanges(); await Clients.All.SendAsync("ReceiveDb", FantasyTeamId, playerId); }
void InsertDataIntoUIComponents(FantasyTeam fantasyTeam, TextView teamDetailsTextView, TextView teamPriceTextView, ListView teamPlayersListView) { teamDetailsTextView.Text = NameTeamTextFormatting.FormatNameAndTeam(fantasyTeam.ManagerFirstname, fantasyTeam.ManagerSurname, fantasyTeam.FantasyTeamName); List <Player> fantasyTeamPlayers = playerRepository.GetAllPlayersOfAFantasyTeam(fantasyTeam.FantasyTeamID); teamPriceTextView.Text = "£" + CalculateTotalFantasyTeamCost(fantasyTeamPlayers).ToString() + " million"; teamPlayersListView.Adapter = new PlayerAdapter(this, fantasyTeamPlayers, Android.Resource.Layout.SimpleListItem2); }
public ActionResult Create([Bind(Include = "TeamID,TeamName,UserId,FantasyLeagueID")] FantasyTeam fantasyTeam) { if (ModelState.IsValid) { db.FantasyTeams.Add(fantasyTeam); db.SaveChanges(); return(RedirectToAction("AddTeam", new { TeamID = fantasyTeam.TeamID })); } ViewBag.FantasyLeagueID = new SelectList(db.FantasyLeagues, "FantasyLeagueId", "FantasyLeagueName", fantasyTeam.FantasyLeagueID); return(View(fantasyTeam)); }
// GET: FantasyTeam/Delete/5 public ActionResult Delete(int?TeamID) { if (TeamID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FantasyTeam fantasyTeam = db.FantasyTeams.Find(TeamID); if (fantasyTeam == null) { return(HttpNotFound()); } return(View(fantasyTeam)); }
// GET: FantasyTeam/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FantasyTeam fantasyTeam = db.FantasyTeams.Find(id); if (fantasyTeam == null) { return(HttpNotFound()); } return(View(fantasyTeam)); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.RegisterTeam); // Get UI resources on this view EditText managerFirstNameEditText = FindViewById <EditText>(Resource.Id.managerFirstNameEditText); EditText managerSurnameEditText = FindViewById <EditText>(Resource.Id.managerSurnameEditText); EditText fantasyTeamEditText = FindViewById <EditText>(Resource.Id.fantasyTeamEditText); Button saveButton = FindViewById <Button>(Resource.Id.registerTeamSaveButton); Button cancelButton = FindViewById <Button>(Resource.Id.registerTeamCancelButton); // Assuming valid data from user, when save button is clicked, add fantasy team to DB and return user to main menu saveButton.Click += (sender, args) => { // Validate user input Boolean validUserInput = true; FantasyTeam newTeam = null; string managerFirstName = managerFirstNameEditText.Text; string managerSurname = managerSurnameEditText.Text; string fantasyTeamName = fantasyTeamEditText.Text; try { newTeam = new FantasyTeam(managerFirstName, managerSurname, fantasyTeamName); } catch (ArgumentOutOfRangeException) { Toast.MakeText(this, Resource.String.invalid_register_fantasy_team_input, ToastLength.Long).Show(); validUserInput = false; } if (validUserInput is true && newTeam != null) { // Insert team to DB fantasyTeamRepository.AddFantasyTeam(newTeam); Finish(); } }; // When cancel button is clicked, return to the main menu cancelButton.Click += (sender, args) => { Finish(); }; }
// GET: FantasyTeam/Create public ActionResult Create(string CustomerID) { if (CustomerID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var fantasyTeam = new FantasyTeam(); fantasyTeam.Players = new List <Player>(); fantasyTeam.IsConfirmed = false; fantasyTeam.UserId = db.Users.Where(c => c.Id == CustomerID).Single().Id; ViewBag.FantasyLeagueID = new SelectList(db.FantasyLeagues, "FantasyLeagueId", "FantasyLeagueName"); return(View(fantasyTeam)); }
public IActionResult DraftPage(string TeamName, int TeamId) { System.Console.WriteLine("TeamName in Process: " + TeamName); List <Player> ListPlayers = _context.Players.ToList(); List <FantasyTeam> ListTeams = _context.FantasyTeams.Where(t => t.FantasyTeamId != TeamId).ToList(); FantasyTeam YourTeam = _context.FantasyTeams.Include(p => p.Players).SingleOrDefault(p => p.FantasyTeamId == TeamId); ViewBag.ListTeams = YourTeam; ViewBag.TeamName = TeamName; ViewBag.TeamId = TeamId; ViewBag.YourTeam = YourTeam; ViewBag.FantasyTeams = ListTeams; return(View(ListPlayers)); }
// GET: FantasyTeam/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FantasyTeam fantasyTeam = db.FantasyTeams.Include(i => i.Players).Where(i => i.TeamID == id).Single(); PopulateTeam(fantasyTeam); if (fantasyTeam == null) { return(HttpNotFound()); } return(View(fantasyTeam)); }
public ActionResult CreateTeam(FormCollection fc, HttpPostedFileBase FantasyTeamLogo) { try { //Initialize classes FantasyTeam model = new FantasyTeam(); //Get connection dbconAPP = GetConnection(); dbconAPP.Open(); //save logo if (FantasyTeamLogo != null && FantasyTeamLogo.ContentLength > 0) { var fileName = Path.GetFileName(FantasyTeamLogo.FileName); var path = Path.Combine(Server.MapPath("~/Images/TeamLogos"), fileName); FantasyTeamLogo.SaveAs(path); model.Logo = fileName; } else { model.Logo = "defaultTeamLogo.png"; } //Add fantasy team model.UserID = Convert.ToInt32(fc["FantasyTeamUserID"].ToString()); model.LeagueID = Convert.ToInt32(fc["FantasyTeamLeagueID"].ToString()); model.Name = fc["FantasyTeamName"].ToString(); model.Slogan = fc["FantasyTeamSlogan"].ToString(); model.CreateNewFantasyTeam(dbconAPP, model); } catch (Exception ex) { return(Content("ERROR: " + ex.Message + " (League.CreateTeam[POST]).")); } finally { if (dbconAPP != null && dbconAPP.State == System.Data.ConnectionState.Open) { dbconAPP.Close(); } } return(RedirectToAction("Index", "Home")); }
public void CreateTeamWithTooManyGoalkeepers() { Player p23 = new Player() { PlayerFirstname = "Andreas", PlayerSurname = "Isaksson", DateOfBirth = DateTime.Parse("1987-08-10"), PlayerValue = 5.0, Position = Position.GoalKeeper, NationCode = "SWE", PlayerID = 012, GoalWeight = .002 }; Player p1 = new Player() { PlayerFirstname = "Shay", PlayerSurname = "Given", DateOfBirth = DateTime.Parse("1982-03-10"), PlayerValue = 4.5, Position = Position.GoalKeeper, NationCode = "IRE", PlayerID = 001, GoalWeight = .002 }; FantasyTeam myTeam = new FantasyTeam() { TeamName = "manCity" }; myTeam.Players = new List <Player>(); myTeam.AddPlayer(p23); myTeam.AddPlayer(p1); }
public IActionResult ProcessTeamSetup(FantasyTeam newTeam) { System.Console.WriteLine("in process team setup"); System.Console.WriteLine("model state: " + ModelState.IsValid); System.Console.WriteLine(newTeam.TeamName); if (ModelState.IsValid) { _context.FantasyTeams.Add(newTeam); _context.SaveChanges(); System.Console.WriteLine("going to Index"); return(RedirectToAction("DraftPage", new { TeamName = newTeam.TeamName, TeamId = newTeam.FantasyTeamId })); } else { System.Console.WriteLine("returning to teamCreate"); return(View("TeamCreate")); } }
public void CreateTeamWithTooManyForwards() { Player p21 = new Player { PlayerFirstname = "Ivo", PlayerSurname = "Toivonen", DateOfBirth = DateTime.Parse("1989-03-12"), PlayerValue = 5.9, Position = Position.Forward, NationCode = "SWE", PlayerID = 021, GoalWeight = .1 }; Player p22 = new Player { PlayerFirstname = "Zlatan", PlayerSurname = "Ibrahimovic", DateOfBirth = DateTime.Parse("1984-03-12"), PlayerValue = 7.0, Position = Position.Forward, NationCode = "SWE", PlayerID = 022, GoalWeight = .318 }; Player p12 = new Player { PlayerFirstname = "John", PlayerSurname = "Walters", DateOfBirth = DateTime.Parse("1984-09-10"), PlayerValue = 5.1, Position = Position.Forward, NationCode = "IRE", PlayerID = 010, GoalWeight = .179 }; FantasyTeam myTeam = new FantasyTeam() { TeamName = "manCity" }; myTeam.Players = new List <Player>(); myTeam.AddPlayer(p21); myTeam.AddPlayer(p22); myTeam.AddPlayer(p12); }
public ActionResult SaveTeamInfo(string teamName, string teamSlogan, int teamID, HttpPostedFileBase TeamImage) { string saveFile = ""; try { //Get connection dbconAPP = GetConnection(); dbconAPP.Open(); //Save logo file if (TeamImage != null && TeamImage.ContentLength > 0) { var fileName = Path.GetFileName(TeamImage.FileName); var path = Path.Combine(Server.MapPath("~/Images/TeamLogos"), fileName); TeamImage.SaveAs(path); saveFile = fileName; } //Save fantasy team info FantasyTeam model = new FantasyTeam(); model.UpdateFantasyTeamInfo(dbconAPP, teamID, teamName, teamSlogan, saveFile); } catch (Exception ex) { return(Content("ERROR: " + ex.Message + " (League.SaveTeamInfo[POST]).")); } finally { if (dbconAPP != null && dbconAPP.State == System.Data.ConnectionState.Open) { dbconAPP.Close(); } } return(Content("/Images/TeamLogos/" + saveFile)); }
public async Task SendPick(int FantasyTeamId, string player) { FantasyTeam YourTeam = _context.FantasyTeams.SingleOrDefault(t => t.FantasyTeamId == FantasyTeamId); await Clients.All.SendAsync("ReceivePick", YourTeam.TeamName, player); }
public ActionResult Create(_League model, FormCollection fc) { Return cR = new Return(); FantasyTeam modelFantasyTeam = new FantasyTeam(); string errMsg = ""; string leagueType = "public"; string errType = "League"; int rowNum = 0; try { //Get connection dbconAPP = GetConnection(); dbconAPP.Open(); //Get league public or private type ViewBag.LeaguePrivate = "false"; var test = fc["isPrivate"].ToString(); if (fc["isPrivate"].ToString() == "false") { ViewBag.LeaguePrivate = "false"; model.cLeague.isPublic = true; leagueType = "public"; } else { ViewBag.LeaguePrivate = "true"; model.cLeague.isPublic = false; leagueType = "private"; } //Assign password model.cLeague.Password = fc["lPwd"].ToString(); //Get all league stat types and their values //need to think of a solution for when a user enters //a comma within the input value List <string> listStatName = new List <string>(); listStatName = fc["StatTypeName"].Split(',').ToList(); List <string> listStatCode = new List <string>(); listStatCode = fc["StatTypeCode"].Split(',').ToList(); List <string> listStatID = new List <string>(); listStatID = fc["StatTypeID"].Split(',').ToList(); List <string> listStatDesc = new List <string>(); listStatDesc = fc["StatTypeDesc"].Split(',').ToList(); List <string> listStatValue = new List <string>(); listStatValue = fc["StatTypeValue"].Split(',').ToList(); rowNum = listStatID.Count; model.list_cStatType = new List <StatType>(); for (int i = 0; i < rowNum; i++) { StatType temp = new StatType(); temp.cStatTypeValue = new StatTypeValue(); temp.StatTypeID = Convert.ToInt32(listStatID[i]); temp.Name = listStatName[i]; temp.NameCode = listStatCode[i]; temp.Description = listStatDesc[i]; temp.cStatTypeValue.StatValue = Convert.ToDouble(listStatValue[i]); model.list_cStatType.Add(temp); } //Create the league cR = model.CreateNewLeague(dbconAPP, model); if (cR.ReturnFlag == false) { errMsg += cR.ReturnMsg; return(RedirectToAction("CreateLeague", new { leagueType = leagueType, errMsg = errMsg })); } //Get Fantasy Team info errType = "FantasyTeam"; modelFantasyTeam.UserID = model.cUser.UserID; modelFantasyTeam.LeagueID = model.cLeague.LeagueID; modelFantasyTeam.LeagueName = model.cLeague.LeagueName; } catch (Exception ex) { return(Content("ERROR: " + ex.Message + " (League.Create[POST]).")); } finally { if (dbconAPP != null && dbconAPP.State == System.Data.ConnectionState.Open) { dbconAPP.Close(); } } //if (model.cLeague.isPublic) //{ // //return RedirectToAction("JoinPublicLeague", "Home", new { leagueID = model.cLeague.LeagueID, userID = model.cUser.UserID }); // ViewBag.LeagueType = "public"; //} //else //{ // //return RedirectToAction("JoinPrivateLeague", "Home", new { leagueID = model.cLeague.LeagueID, userID = model.cUser.UserID }); // ViewBag.LeagueType = "private"; //} return(PartialView("_JoinLeague", modelFantasyTeam)); }
public int AddFantasyTeam(FantasyTeam team) { return(dbConnection.Insert(team)); }
public PartialViewResult RosterUpdate(int FantasyTeamId) { FantasyTeam YourTeam = _context.FantasyTeams.Include(t => t.Players).SingleOrDefault(p => p.FantasyTeamId == FantasyTeamId); return(PartialView("~/Views/Shared/RosterPartialAjax.cshtml", YourTeam)); }
public async Task NewTeam(int TeamId) { FantasyTeam team = _context.FantasyTeams.SingleOrDefault(t => t.FantasyTeamId == TeamId); string FantasyTeamName = team.TeamName; await Clients.All.SendAsync("ReceiveNewTeam", FantasyTeamName, TeamId); }
/// <summary> /// Get a list of FantasyTeams from teh FantasyManager's standings dictionary /// </summary> /// <returns>A list containing FantasyTeam objects for each team</returns> public static void GetFantasyTeamList(System.Action callbackOnComplete) { new GameSparks.Api.Requests.LogEventRequest() .SetEventKey("getFantasyTeams") .SetEventAttribute("team", "") .Send((response) => { if (!response.HasErrors) { Logging.Log("Received FantasyTeams from GameSparks: " + response.JSONString.ToString()); if (response.BaseData != null) { GameSparks.Core.GSData data = response.ScriptData; if (data != null) { List <GameSparks.Core.GSData> dataList = data.GetGSDataList("fantasyTeams"); if (dataList != null) { foreach (var obj in dataList) { // Populate a new fantasy team based on the info pulled from the dataList FantasyTeam team = new FantasyTeam(); team.TeamName = obj.GetString("teamName"); // Continue populating team info team.Players = FantasyManager.Instance.GetPlayersOnTeam(team.TeamName); team.Salary = int.Parse(obj.GetString("salary")); team.FPPG = obj.GetString("fppg"); // Grab the corresponding logo image for this team System.Action <Texture2D> imageReceived = delegate(Texture2D image) { team.Logo = Sprite.Create(image, new Rect(0.0f, 0.0f, image.width, image.height), new Vector2(0.5f, 0.5f), 100.0f); }; FantasyManager.Instance.DownloadAnImage(obj.GetString("logoShortCode"), imageReceived); // Add the fantasy team to some persistent data structure if (!FantasyManager.Instance.FantasyTeams.ContainsKey(team.TeamName)) { FantasyManager.Instance.FantasyTeams.Add(team.TeamName, team); } else { FantasyManager.Instance.FantasyTeams[team.TeamName] = team; } } } else { Logging.LogError("Couldn't get FantasyTeams GSData"); } } else { Logging.LogError("FantasyTeams ScriptData is NULL"); } } else { Logging.LogError("FantasyTeams response Base Data = null"); } } else { Logging.Log("Error retrieving FantasyTeams from GameSparks: " + response.Errors.ToString()); } if (callbackOnComplete != null) { callbackOnComplete(); } }); }
public ActionResult Index(string leagueType, string leagueID, int seasonID, int fantasyTeamID, string errMsg = "") { _League model = new _League(); model.cLeague = new League(); model.list_cLeague = new List <League>(); model.cSeason = new Season(); model.list_cFantasyTeam = new List <FantasyTeam>(); model.cFantasyTeam = new FantasyTeam(); model.list_LeagueStanding = new List <FantasyTeam>(); model.cSkater = new Skater(); model.list_Skater = new List <Skater>(); try { //setup errMsg if (errMsg != "") { ViewBag.LeagueError = errMsg; } //Get connection dbconAPP = GetConnection(); dbconAPP.Open(); //Get user info model.cUser = new User(); ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext() .GetUserManager <ApplicationUserManager>() .FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); model.cUser.AspNetUserID = user.Id; model.cUser.UserID = model.cUser.GetUserID(dbconAPP, model.cUser.AspNetUserID); model.cUser.FullName = model.cUser.GetUserName(dbconAPP, model.cUser.UserID); if (model.cUser.FullName == "Jason Deutsch") { ViewBag.Creator = true; } //Get League info model.cLeague = model.cLeague.GetLeagueInfo(dbconAPP, Convert.ToInt32(leagueID), seasonID); model.cFantasyTeam = new FantasyTeam(); model.cFantasyTeam.Name = model.cLeague.TeamName; model.cFantasyTeam.FantasyTeamID = fantasyTeamID; //Enable or disable the commish edit league button if (model.cLeague.CommissionerUserID == model.cUser.UserID) { ViewBag.IsCommish = true; } ////Enable or disable the draft room button based on when the draft time is //int beforeDraft = (30 * 60) * -1; //allowed into the draft 30 minutes before //int afterDraft = (model.cLeague.DraftTimePerTeam * model.cLeague.RosterSize * model.cLeague.MaxTeams) + (15 * 60); //allowed into draft 15 minutes after the end of the draft //var test1 = model.cLeague.DraftDate.ToFileTimeUtc(); //var test2 = model.cLeague.DraftDate.ToBinary(); //var test3 = model.cLeague.DraftDate.ToUniversalTime(); //var test4 = model.cLeague.DraftDate.ToFileTime(); //var testNow = DateTime.Now.ToBinary(); //var testNowUTC = DateTime.UtcNow; //var testNowUtcBinary = DateTime.UtcNow.ToBinary(); //var testNowFileTimeUTC = DateTime.Now.ToFileTimeUtc(); //var testNowFileTime = DateTime.Now.ToFileTime(); //var inactiveDraftTime = model.cLeague.DraftDate.AddSeconds(afterDraft).ToFileTime(); //var activeDraftTime = model.cLeague.DraftDate.AddSeconds(beforeDraft).ToFileTime(); //var currentTime = DateTime.Now.ToFileTime(); ////Having trouble getting this date comparison to work on Azure web hosting solutions ////double intInactiveDate = Convert.ToDouble(inactiveDraftTime.ToString("yyyyMMddhhmmss")); ////double intActiveDate = Convert.ToDouble(activeDraftTime.ToString("yyyyMMddhhmmss")); ////double intDateTimeNow = Convert.ToDouble(DateTime.Now.ToString("yyyyMMddhhmmss")); ////Azure web hosting service compares to the tick so this won't work //if (inactiveDraftTime > currentTime && activeDraftTime < currentTime) //{ // //Enable the draft button // ViewBag.IsDraft = true; //} ////ViewBag.IsDraft = true; //get list of teams first by total team points, then by draft pick number model.cSeason = new Season(); model.list_cFantasyTeam = new List <FantasyTeam>(); model.list_cFantasyTeam = model.cFantasyTeam.GetFantasyTeamStandings(dbconAPP, model.cLeague.SeasonID, model.cLeague.LeagueID); //if list is empty then sort teams by draft order model.list_SeasonFantasyTeams = model.cFantasyTeam.GetSeasonFantasyTeamList(dbconAPP, model.cLeague.SeasonID); if (model.list_cFantasyTeam.Count < 1) { //Get season draft order model.cSeason.SeasonID = model.cLeague.SeasonID; model.cSeason.GetSeasonInfo(dbconAPP, model.cSeason); if (model.cSeason.DraftOrder != "") { //Order teams according to the draft order foreach (var item in model.cSeason.DraftOrder.Split('|')) { FantasyTeam tempFT = new FantasyTeam(); tempFT = model.list_SeasonFantasyTeams.Find(x => x.FantasyTeamID == Convert.ToInt32(item)); model.list_cFantasyTeam.Add(tempFT); } } else { model.list_cFantasyTeam = model.list_SeasonFantasyTeams; } } //Create standings list //First, verify that all teams are included in the standings list model.list_LeagueStanding = new List <FantasyTeam>(); if (model.list_cFantasyTeam.Count != model.list_SeasonFantasyTeams.Count) { model.list_LeagueStanding = model.list_cFantasyTeam.OrderByDescending(x => x.TotalTeamPoints).ToList(); foreach (var item in model.list_SeasonFantasyTeams) { var test = model.list_LeagueStanding.Find(m => m.FantasyTeamID == item.FantasyTeamID); if (test == null) { item.TotalTeamPoints = 0.00; model.list_LeagueStanding.Add(item); } } } else { model.list_LeagueStanding = model.list_cFantasyTeam.OrderByDescending(x => x.TotalTeamPoints).ToList(); } //set fantasy team id and get fantasy team info model.cFantasyTeam.FantasyTeamID = fantasyTeamID; model.cFantasyTeam.GetFantasyTeamInfo(dbconAPP, model.cFantasyTeam); //Get Fantasy Team skater list model.cSkater = new Skater(); model.list_Skater = new List <Skater>(); model.list_Skater = model.cSkater.GetFantasyTeamSkaterList(dbconAPP, seasonID, fantasyTeamID); //Determine if the season is over if (DateTime.Now > model.cLeague.EndDate) { ViewBag.SeasonEnded = true; //need to change so users can't select a start date before the draft date, etc. ViewBag.MinDate = DateTime.Now.ToString("yyyy-MM-dd"); ViewBag.MaxDate = DateTime.Now.AddYears(10).ToString("yyyy-MM-dd"); } } catch (Exception ex) { ViewBag.LeagueError += "ERROR: " + ex.Message + " (League.Index[GET])."; return(View(model)); } finally { if (dbconAPP != null && dbconAPP.State == System.Data.ConnectionState.Open) { dbconAPP.Close(); } } //string fantasyTeamName, string leagueName, int seasonID, int teamID Session["fantasyTeamName"] = model.cFantasyTeam.Name; Session["leagueName"] = model.cLeague.LeagueName; Session["seasonID"] = model.cLeague.SeasonID; Session["teamID"] = model.cFantasyTeam.FantasyTeamID; return(View(model)); }
public int RemoveFantasyTeam(FantasyTeam team) { return(dbConnection.Delete(team)); }
void DeleteSelectedFantasyTeam(FantasyTeam fantasyTeam) { fantasyTeamRepository.RemoveFantasyTeam(fantasyTeam); }
public ActionResult Index(_Home model, string buttonAction, string leagueID) { FantasyTeam modelFantasyTeam = new FantasyTeam(); string errType = "League"; string errMsg = ""; try { //Get connection dbconAPP = GetConnection(); dbconAPP.Open(); //Verify user isn't already apart of the league ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); model.cLeague = new League(); model.cUser = new User(); model.cUser.UserID = model.cUser.GetUserID(dbconAPP, user.Id); model.cLeague.LeagueID = Convert.ToInt32(leagueID); if (model.cLeague.VerifyLeagueUsers(dbconAPP, model.cLeague, model.cUser.UserID)) { return(Content("You cannot join this league because you are already a member.")); } //Process request based on buttonAction value switch (buttonAction.ToUpper()) { case "PUBLIC": //TempData["model"] = model; List <League> tempPublic = new List <League>(); tempPublic = model.list_cLeaguePublic.Where(n => n.LeagueID == model.cLeague.LeagueID).ToList <League>(); model.cLeague = tempPublic[0]; ViewBag.LeagueType = "Public"; //return View("JoinLeague", model); //return RedirectToAction("JoinPublicLeague"); break; case "PRIVATE": //TempData["model"] = model; List <League> tempPrivate = new List <League>(); tempPrivate = model.list_cLeaguePrivate.Where(n => n.LeagueID == model.cLeague.LeagueID).ToList <League>(); model.cLeague = tempPrivate[0]; ViewBag.LeagueType = "Private"; //return View("JoinLeague", model); //return RedirectToAction("JoinPrivateLeague"); break; } //Get Fantasy Team info errType = "FantasyTeam"; modelFantasyTeam.UserID = model.cUser.UserID; modelFantasyTeam.LeagueID = model.cLeague.LeagueID; modelFantasyTeam.LeagueName = model.cLeague.LeagueName; return(PartialView("_JoinLeague", modelFantasyTeam)); } catch (Exception ex) { if (errType == "League") { errMsg += "ERROR: " + ex.Message + " (Home.Index[POST])."; return(Content(errMsg)); } else { errMsg += "ERROR: " + ex.Message + " (Home.Index[POST])."; ViewBag.JoinLeagueError = errMsg; return(PartialView("_JoinLeague", modelFantasyTeam)); } } finally { if (dbconAPP != null && dbconAPP.State == System.Data.ConnectionState.Open) { dbconAPP.Close(); } } }
public ActionResult Index() { //string fantasyTeamName, string leagueName, int seasonID, int teamID _Draft model = new _Draft(); model.cUser = new User(); model.cFantasyTeam = new FantasyTeam(); model.cLeague = new League(); model.cSeason = new Season(); model.cSkater = new Skater(); model.cDerbyTeam = new DerbyTeam(); model.list_cDerbyTeam = new List <DerbyTeam>(); model.list_cFantasyTeam = new List <FantasyTeam>(); model.list_cLeague = new List <League>(); model.list_cSeason = new List <Season>(); model.list_cSkater = new List <Skater>(); try { //Get session vars string fantasyTeamName = Session["fantasyTeamName"].ToString(); string leagueName = Session["leagueName"].ToString(); int seasonID = Convert.ToInt32(Session["seasonID"].ToString()); int teamID = Convert.ToInt32(Session["teamID"].ToString()); //Get connection dbconAPP = GetConnection(); dbconAPP.Open(); //Get UserID ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext() .GetUserManager <ApplicationUserManager>() .FindById(System.Web.HttpContext.Current.User.Identity.GetUserId()); model.cUser.AspNetUserID = user.Id; model.cUser.UserID = model.cUser.GetUserID(dbconAPP, model.cUser.AspNetUserID); //Get Draft Info Session["FantasyTeamName"] = fantasyTeamName; Session["LeagueName"] = leagueName; model.cFantasyTeam.Name = fantasyTeamName; model.cLeague.LeagueName = leagueName; model.cSeason.SeasonID = Convert.ToInt32(seasonID); model.cFantasyTeam.SeasonID = Convert.ToInt32(seasonID); model.cFantasyTeam.FantasyTeamID = Convert.ToInt32(teamID); model.GetDraftInfo(dbconAPP, model); foreach (var item in model.list_cSkater) { List <DerbyTeam> tempList = new List <DerbyTeam>(); tempList = model.list_cDerbyTeam.Where(n => n.DerbyTeamID == item.DerbyTeamID).ToList <DerbyTeam>(); item.DerbyTeamName = tempList[0].Name; } //Calculate total draft time in seconds and convert to minutes int totalDraftSeconds = model.list_SeasonFantasyTeams.Count * model.cSeason.RosterSize * model.cSeason.DraftTimePerTeam; ViewBag.TotalDraftTime = totalDraftSeconds / 60; ViewBag.TotalPicks = model.list_SeasonFantasyTeams.Count * model.cSeason.RosterSize; //Create Draft Order if the draft order hasn't been created yet if (model.cSeason.DraftOrder == null || model.cSeason.DraftOrder == "") { Dictionary <int, int> dictDraftOrder = new Dictionary <int, int>(); Random randoNum = new Random(); int numTeams = model.list_SeasonFantasyTeams.Count; int min = 0; int max = numTeams; for (int i = 1; i <= numTeams; i++) { int intTemp = randoNum.Next(min, max); while (dictDraftOrder.ContainsValue(model.list_SeasonFantasyTeams[intTemp].FantasyTeamID)) { if (intTemp == min) { min++; } else if (intTemp == max) { max--; } intTemp = randoNum.Next(min, max); } if (intTemp == min) { min++; } else if (intTemp == max) { max--; } dictDraftOrder.Add(i, model.list_SeasonFantasyTeams[intTemp].FantasyTeamID); } for (int i = 1; i <= dictDraftOrder.Count; i++) { if (i != dictDraftOrder.Count) { model.cSeason.DraftOrder += dictDraftOrder[i].ToString() + "|"; } else { model.cSeason.DraftOrder += dictDraftOrder[i].ToString(); } } model.cSeason.UpdateDraftOrder(dbconAPP, model.cSeason.SeasonID, model.cSeason.DraftOrder); model.cSeason.UpdateCurrentPick(dbconAPP, model.cSeason.SeasonID, Convert.ToInt32(dictDraftOrder[1].ToString())); } //Get current pick model.cSeason.CurrentPickFantasyTeamID = model.cSeason.GetCurrentPickTeamID(dbconAPP, model.cSeason.SeasonID); FantasyTeam tempFTM = new FantasyTeam(); tempFTM = model.list_SeasonFantasyTeams.Single(s => s.FantasyTeamID == model.cSeason.CurrentPickFantasyTeamID); model.cSeason.CurrentPickFantasyTeamName = tempFTM.Name; //Order fantasy teams into list string draftOrderNames = ""; string draftOrderTeamLogos = ""; model.list_DraftOrderTeams = new List <FantasyTeam>(); List <string> tempOrderList = new List <string>(); tempOrderList = model.cSeason.DraftOrder.Split('|').ToList(); foreach (var item in tempOrderList) { FantasyTeam tempModelFT = new FantasyTeam(); tempModelFT = model.list_SeasonFantasyTeams.Single(s => s.FantasyTeamID == Convert.ToInt32(item)); model.list_DraftOrderTeams.Add(tempModelFT); draftOrderNames += tempModelFT.Name + "|"; draftOrderTeamLogos += tempModelFT.Logo + "|"; } draftOrderNames = draftOrderNames.Substring(0, draftOrderNames.Length - 1); draftOrderTeamLogos = draftOrderTeamLogos.Substring(0, draftOrderTeamLogos.Length - 1); ViewBag.DraftOrderNames = draftOrderNames; ViewBag.DraftOrderTeamLogos = draftOrderTeamLogos; //Create Generic Draft Order int totalTeams = model.list_SeasonFantasyTeams.Count; int totalRounds = model.cSeason.RosterSize; string genericDraftOrder = ""; for (int i = 0; i < totalRounds; i++) { if ((i % 2) == 0) { //Walk UP for (int j = 0; j < totalTeams; j++) { genericDraftOrder += j + "|"; } } else { //Walk DOWN for (int j = (totalTeams - 1); j > -1; j--) { genericDraftOrder += j + "|"; } } } //Delete last "|" genericDraftOrder = genericDraftOrder.Substring(0, genericDraftOrder.Length - 1); //Split out genericDraftOrder ViewBag.GenericDraftOrder = genericDraftOrder; //**************************TESTING********************************************** //Determine what draft picks should have already taken place and draft them var test1 = model.cSeason.DraftDate.ToBinary(); var test2 = model.cSeason.DraftDate.ToFileTime(); //console log this //ViewBag.test2Date = model.cSeason.DraftDate; //ViewBag.Test2 = test2; var test3 = model.cSeason.DraftDate.ToFileTimeUtc(); var nowFileTime = DateTime.Now.ToFileTime(); //console log this var nowDate = DateTime.UtcNow; //ViewBag.nowDateUTC = nowDate; //ViewBag.nowFileTime = nowFileTime; var nowFileTimeUTC = DateTime.Now.ToFileTimeUtc(); //convert time to file time and append date to front when comparing //get draft time plus first pick DateTime testDraft1 = model.cSeason.DraftDate.AddSeconds(model.cSeason.DraftTimePerTeam); DateTime testDraft5 = testDraft1.ToUniversalTime(); string testDraft2 = testDraft5.ToString("yyyyMMdd"); string testDraft3 = testDraft5.ToFileTimeUtc().ToString(); testDraft2 = testDraft2 + testDraft3; Double testDraft4 = Convert.ToDouble(testDraft2); //get current time DateTime nowDraft1 = DateTime.UtcNow; string nowDraft2 = nowDraft1.ToString("yyyyMMdd"); string nowDraft3 = nowDraft1.ToFileTimeUtc().ToString(); nowDraft2 = nowDraft2 + nowDraft3; Double nowDraft4 = Convert.ToDouble(nowDraft2); //if (model.cSeason.DraftDate.AddSeconds(model.cSeason.DraftTimePerTeam) < DateTime.Now) //if(testDraft4 < nowDraft4) if (1 == 2) {//if true, that means the draft has already started and is already past the first pick double diffSeconds = (DateTime.Now - model.cSeason.DraftDate).TotalSeconds; int estPicks = Convert.ToInt32(diffSeconds) / model.cSeason.DraftTimePerTeam; for (int i = 0; i < estPicks; i++) { List <string> listGenericDraftOrder = new List <string>(); listGenericDraftOrder = genericDraftOrder.Split('|').ToList(); var pick = Convert.ToInt32(listGenericDraftOrder[i].ToString()); var checkTeamID = model.list_DraftOrderTeams[pick].FantasyTeamID; bool draftCheck = model.TeamDraftedCount(dbconAPP, model.cSeason.SeasonID, checkTeamID, i + 1); if (!draftCheck) { //draft highest ranked player left to team tempFTM = new FantasyTeam(); tempFTM.SkaterID = model.cSkater.GetNextRankedSkaterID(dbconAPP, Convert.ToInt32(seasonID)); tempFTM.FantasyTeamID = checkTeamID; tempFTM.SeasonID = model.cSeason.SeasonID; tempFTM.DraftPickNumber = i + 1; tempFTM.UserID = model.cUser.UserID; //SELECT * FROM tblFantasyTeamRoster WHERE SeasonID = 4 //SELECT* FROM tblSeason WHERE SeasonID = 4 //Draft is not snaking here, still snaking when logging in before the draft starts model.cFantasyTeam.AddSkaterToFantasyTeam(dbconAPP, tempFTM); } } //refresh list of available skaters model.list_cSkater = new List <Skater>(); model.list_cSkater = model.cSkater.GetSkaterList(dbconAPP, model.cFantasyTeam.SeasonID); foreach (var item in model.list_cSkater) { List <DerbyTeam> tempList = new List <DerbyTeam>(); tempList = model.list_cDerbyTeam.Where(n => n.DerbyTeamID == item.DerbyTeamID).ToList <DerbyTeam>(); item.DerbyTeamName = tempList[0].Name; } } //**************************TESTING********************************************** //Generate a random number for different users Random rnd = new Random(); ViewBag.Random = rnd.Next(1, 100); } catch (Exception ex) { ViewBag.LeagueError += "ERROR: " + ex.Message + " (Draft.Index[GET])."; return(View(model)); } finally { if (dbconAPP != null && dbconAPP.State == System.Data.ConnectionState.Open) { dbconAPP.Close(); } } return(View(model)); }