public ActionResult Change(int id) { Context ctx = new Context(); var matchTeams = (from mt in ctx.MatchesTeam where mt.matchId == id select mt).FirstOrDefault(); var teams = (from t in ctx.Teams select t).ToList(); var results = new List<SelectListItem>(); foreach (Teams t in teams) { results.Add(new SelectListItem() { Text = t.teamName, Value = t.teamId.ToString() }); } ViewBag.HomeTeam = results; ViewBag.AwayTeam = results; if (matchTeams == null) { matchTeams = new MatchesTeam(); matchTeams.matchId = id; matchTeams.teamId = 0; matchTeams.teamIsLocal = true; } return View(matchTeams); }
public ActionResult Change(MatchesTeam mt, FormCollection form) { MatchesTeam teamLocal = new MatchesTeam() { matchId = int.Parse(form["matchId"].ToString()), teamId = int.Parse(form["dropHome"].ToString()), teamIsLocal = true }; MatchesTeam teamAway = new MatchesTeam() { matchId = int.Parse(form["matchId"].ToString()), teamId = int.Parse(form["dropAway"].ToString()), teamIsLocal = false }; Context ctx = new Context(); int matchId = int.Parse(form["matchId"].ToString()); var exists = (from ma in ctx.MatchesTeam where ma.matchId == matchId select ma).ToList(); if (exists.Count == 0) { ctx.MatchesTeam.Add(teamLocal); ctx.MatchesTeam.Add(teamAway); } else { if (exists[0].teamIsLocal == true) { exists[0].teamId = int.Parse(form["dropHome"].ToString()); exists[1].teamId = int.Parse(form["dropAway"].ToString()); } else { exists[1].teamId = int.Parse(form["dropHome"].ToString()); exists[0].teamId = int.Parse(form["dropAway"].ToString()); } } ctx.SaveChanges(); return RedirectToAction("List", "Match"); }
public ActionResult Finalist() { Context ctx = new Context(); var users = (from u in ctx.UserProfiles where u.UserName == User.Identity.Name select u).SingleOrDefault(); var result = (from f in ctx.UserFinalist from t in ctx.Teams where f.UserId == users.UserId && t.teamId == f.teamId select new ModelTemp() { teamName = t.teamName, teamFlag = t.teamImage, position = f.position, positionName = f.position == 1 ? "Campeón" : f.position == 2 ? "Sub Campeón" : f.position == 3 ? "Tercer Lugar" : "Cuarto Lugar" }).OrderBy(o => o.position).ToList(); ViewBag.Finalist = result; return View(); }
public ActionResult Index() { Context ctx = new Context(); var user = (from u in ctx.UserProfiles where u.UserName == User.Identity.Name select u).SingleOrDefault(); var userFinalist = (from f in ctx.UserFinalist where f.UserId == user.UserId select f).Count(); if (userFinalist != 4 && !User.Identity.Name.Equals("admin")) { return RedirectToAction("Champions", "Account"); } //ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; return View(); }
public SimpleMembershipInitializer() { Database.SetInitializer<Context>(null); try { using (var context = new Context()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("Context", "UserProfile", "UserId", "UserName", autoCreateTables: true); } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } }
public ActionResult List(string date) { Context ctx = new Context(); DateTime fecha = DateTime.Now; if (date == null) { fecha = new DateTime(Util.LocalDate.Now.Year, Util.LocalDate.Now.Month, Util.LocalDate.Now.Day); } else { fecha = DateTime.Parse(date); } var userId = (from u in ctx.UserProfiles where u.UserName == User.Identity.Name select u.UserId).SingleOrDefault(); var userFinalist = (from f in ctx.UserFinalist where f.UserId == userId select f).Count(); if (userFinalist != 4 && !User.Identity.Name.Equals("admin")) { return RedirectToAction("Champions", "Account"); } var result = (from p in ctx.Predictions from m in ctx.Matches where p.matchId == m.matchId && p.UserId == userId && m.matchDate == fecha //&& (Util.LocalDate.Now - m.matchDate).Hours > 2 select new { p.predictionId, p.matchId, p.homeResult, p.homePenaltyResult, p.awayResult, p.awayPenaltyResult, m.matchDate, m.stadiumName }).OrderBy(o => o.matchId).ToList(); List<PredictionMatches> temp = new List<PredictionMatches>(); foreach (var o in result) { PredictionMatches p = new PredictionMatches() { matchId = o.matchId, predictionId = o.predictionId, awayPenaltyResult = o.awayPenaltyResult, matchDate = o.matchDate, awayResult = o.awayResult, stadiumName = o.stadiumName, homeResult = o.homeResult, homePenaltyResult = o.homePenaltyResult }; var teamsMatches = (from mt in ctx.MatchesTeam from te in ctx.Teams where mt.matchId == o.matchId && te.teamId == mt.teamId select new { te.teamImage, te.teamName, mt.teamIsLocal }); foreach (var i in teamsMatches) { if (i.teamIsLocal) { p.HomeTeam = i.teamName; p.HomeFlag = i.teamImage; } else { p.AwayTeam = i.teamName; p.AwayFlag = i.teamImage; } } temp.Add(p); } ViewBag.Predictions = temp; return View(); }
public ActionResult Modify(Predictions pred) { Context ctx = new Context(); var userId = (from u in ctx.UserProfiles where u.UserName == User.Identity.Name select u.UserId).SingleOrDefault(); var prediction = (from p in ctx.Predictions where p.predictionId == pred.predictionId select p).SingleOrDefault(); var match = (from m in ctx.Matches where m.matchId == prediction.matchId select m).SingleOrDefault(); if (DateTime.Compare(Util.LocalDate.Now, match.matchDate)>= 0) { ModelState.AddModelError("", "No puede modificar las predicciones el mismo día del juego."); return RedirectToAction("Modify", "Prediction", new {@id = pred.predictionId}); } if (!userId.Equals(prediction.UserId)) { return RedirectToAction("List", "Prediction"); } //look for a register //prediction.matchPenaltyResult = pred.matchPenaltyResult; prediction.homeResult = pred.homeResult; prediction.homePenaltyResult = pred.homePenaltyResult == null ? 0 : pred.homePenaltyResult; prediction.awayResult = pred.awayResult; prediction.awayPenaltyResult = pred.awayPenaltyResult == null ? 0 : pred.awayPenaltyResult; prediction.matchPredictionModify = Util.LocalDate.Now; //prediction.matchResult = pred.matchResult; ctx.SaveChanges(); return RedirectToAction("List", "Prediction"); }
public ActionResult ResetPassword(string userName, string token) { Context ctx = new Context(); var userid = (from i in ctx.UserProfiles where i.UserName == userName select i.UserId).FirstOrDefault(); bool any = (from j in ctx.webpages_Memberships where (j.UserId == userid) && (j.PasswordVerificationToken == token) //&& (j.PasswordVerificationTokenExpirationDate < DateTime.Now) select j).Any(); if (any == true) { //generate random password string newpassword = Membership.GeneratePassword(10, 4); //reset password bool response = WebSecurity.ResetPassword(token, newpassword); if (response == true) { //get user emailid to send password var emailid = (from i in ctx.UserProfiles where i.UserName == userName select i.emailAddress).FirstOrDefault(); try { //SendEMail(emailid, subject, body); MailMessage mailMsg = new MailMessage(); mailMsg.Subject = "Recuperar Contraseña"; mailMsg.Body = "La contraseña es " + newpassword; mailMsg.To.Add(new MailAddress(emailid)); //mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(builder.ToString(), null, MediaTypeNames.Text.Html)); mailMsg.IsBodyHtml = false; mailMsg.From = new MailAddress("*****@*****.**"); SmtpClient smtpClient = null; smtpClient = new SmtpClient(); //smtpClient.Send(new MailMessage("*****@*****.**", user.emailAddress, "Predicciones hechas por los usuarios para el Mundial 2014", string.Empty)); smtpClient.Send(mailMsg); TempData["Message"] = "Correo Enviado."; } catch (Exception ex) { TempData["Message"] = "Error enviando el correo. " + ex.Message; } //display message //TempData["Message"] = "Success! Check email we sent. Your New Password Is " + newpassword; } else { //TempData["Message"] = "Hey, avoid random request on this page."; } } else { TempData["Message"] = "Usuario y token no concuerdan."; } return RedirectToAction("ForgotPassword", "Account"); }
public ActionResult Modify(int id) { Context ctx = new Context(); var user = (from u in ctx.UserProfiles where u.UserName == User.Identity.Name select u).SingleOrDefault(); var userFinalist = (from f in ctx.UserFinalist where f.UserId == user.UserId select f).Count(); if (userFinalist != 4 && !User.Identity.Name.Equals("admin")) { return RedirectToAction("Champions", "Account"); } var model = (from p in ctx.Predictions where p.predictionId == id select p).SingleOrDefault(); var matchInfo = (from m in ctx.Matches where m.matchId == model.matchId select m).SingleOrDefault(); ViewBag.MatchInfo = matchInfo.stadiumName + " " + matchInfo.matchDate.ToString("dd/MM/yyyy hh:mm:ss"); var matchTeams = (from mt in ctx.MatchesTeam from t in ctx.Teams where t.teamId == mt.teamId && mt.matchId == matchInfo.matchId select new { t.teamName, mt.teamIsLocal }).ToList(); ViewBag.HomeTeam = (from o in matchTeams where o.teamIsLocal select o.teamName).SingleOrDefault(); ViewBag.AwayTeam = (from o in matchTeams where !o.teamIsLocal select o.teamName).SingleOrDefault(); return View(model); }
public ActionResult Edit(Matches matches, FormCollection form) { Context ctx = new Context(); try { int matchId = int.Parse(form["matchId"].ToString()); var match = (from m in ctx.Matches where m.matchId == matchId select m).SingleOrDefault(); match.homeResult = matches.homeResult; match.awayResult = matches.awayResult; match.Played = true; string[] result = null; string[] resultPenalty = null; if (!match.IsFormula) { var teamLocal = (from mt in ctx.MatchesTeam from t in ctx.Teams where mt.matchId == matchId && t.teamId == mt.teamId && mt.teamIsLocal == true select t).SingleOrDefault(); var teamAway = (from mt in ctx.MatchesTeam from t in ctx.Teams where mt.matchId == matchId && t.teamId == mt.teamId && mt.teamIsLocal == false select t).SingleOrDefault(); teamLocal.matchesPlayed += 1; teamAway.matchesPlayed += 1; //result = matches.matchResult.Split(new char[] { '-' }); if (match.homeResult > match.awayResult) { teamLocal.matchesWin += 1; teamAway.matchesLoses += 1; teamLocal.goalsFavor += match.homeResult; teamAway.goalsFavor += match.awayResult; teamLocal.goalsAgainst += match.awayResult; teamAway.goalsAgainst += match.homeResult; teamLocal.points += 3; teamAway.points += 0; teamLocal.goalsDifference = teamLocal.goalsFavor - teamLocal.goalsAgainst; teamAway.goalsDifference = teamAway.goalsFavor - teamAway.goalsAgainst; } else if (match.awayResult > match.homeResult) { teamAway.matchesWin += 1; teamLocal.matchesLoses += 1; teamLocal.goalsFavor += match.homeResult; teamAway.goalsFavor += match.awayResult; teamLocal.goalsAgainst += match.awayResult; teamAway.goalsAgainst += match.homeResult; teamAway.points += 3; teamLocal.points += 0; teamLocal.goalsDifference = teamLocal.goalsFavor - teamLocal.goalsAgainst; teamAway.goalsDifference = teamAway.goalsFavor - teamAway.goalsAgainst; } else if (match.awayResult == match.homeResult) { teamAway.matchesDraw += 1; teamLocal.matchesDraw += 1; teamLocal.goalsFavor += match.homeResult; teamAway.goalsFavor += match.awayResult; teamLocal.goalsAgainst += match.awayResult; teamAway.goalsAgainst += match.homeResult; teamAway.points += 1; teamLocal.points += 1; teamLocal.goalsDifference = teamLocal.goalsFavor - teamLocal.goalsAgainst; teamAway.goalsDifference = teamAway.goalsFavor - teamAway.goalsAgainst; } } else { match.homePenaltyResult = matches.homePenaltyResult; match.awayPenaltyResult = matches.awayPenaltyResult; } var matchProcessed = (from mp in ctx.MatchProcessed where mp.matchId == matchId select mp).FirstOrDefault(); if (matchProcessed == null) { ctx.MatchProcessed.Add(new MatchProcessed() { matchId = matchId, matchProcessed = false }); } else { if (!matchProcessed.matchProcessed) { matchProcessed.matchProcessed = false; } } } catch (Exception ex) { var changedEntities = ctx.ChangeTracker.Entries().Where(x => x.State != System.Data.EntityState.Unchanged); foreach (var entry in changedEntities.Where(x => x.State == System.Data.EntityState.Modified)) { entry.CurrentValues.SetValues(entry.OriginalValues); entry.State = System.Data.EntityState.Unchanged; } foreach (var entry in changedEntities.Where(x => x.State == System.Data.EntityState.Added)) { entry.State = System.Data.EntityState.Detached; } foreach (var entry in changedEntities.Where(x => x.State == System.Data.EntityState.Deleted)) { entry.State = System.Data.EntityState.Unchanged; } } ctx.SaveChanges(); return RedirectToAction("List", "Match"); }
public ActionResult AuthorizeUser(int id) { Context ctx = new Context(); var users = (from u in ctx.UserProfiles where u.UserId == id select u).SingleOrDefault(); users.isActive = true; ctx.SaveChanges(); return RedirectToAction("Authorize", "Account"); }
public ActionResult List() { Context ctx = new Context(); var user = (from u in ctx.UserProfiles where u.UserName == User.Identity.Name select u).SingleOrDefault(); var userFinalist = (from f in ctx.UserFinalist where f.UserId == user.UserId select f).Count(); if (userFinalist != 4 && !User.Identity.Name.Equals("admin")) { return RedirectToAction("Champions", "Account"); } ViewBag.List = (from u in ctx.UserProfiles where u.UserName != "admin" select u).OrderByDescending(o => o.pointsEarned).ToList(); return View(); }
public ActionResult SendEmails() { Context ctx = new Context(); var users = (from u in ctx.UserProfiles where u.UserName != "admin" select u).ToList(); MailMessage mailMsg = new MailMessage(); StringBuilder builder = new StringBuilder(); List<string> adresses = new List<string>(); foreach (var user in users) { mailMsg.To.Add(new MailAddress(user.emailAddress, user.userCompleteName)); } foreach (var user in users) { builder.Append("<h2>"+ user.userCompleteName + "</h2><br>"); HtmlTable table = new HtmlTable(); var predictions = (from p in ctx.Predictions from m in ctx.Matches where p.UserId == user.UserId && p.matchPredictionModify != null && p.matchId == m.matchId && m.matchDate.Year == Util.LocalDate.Now.Year && m.matchDate.Month == Util.LocalDate.Now.Month && m.matchDate.Day == Util.LocalDate.Now.Day select p).ToList(); HtmlTableRow row = new HtmlTableRow(); GenerateColumns(row); table.Rows.Add(row); foreach (var prediction in predictions) { row = new HtmlTableRow(); HtmlTableCell cell = new HtmlTableCell(); cell.InnerText = prediction.predictionId.ToString(); row.Cells.Add(cell); cell = new HtmlTableCell(); cell.InnerText = prediction.matchId.ToString(); row.Cells.Add(cell); var matchInfo = (from m in ctx.Matches where m.matchId == prediction.matchId select m).SingleOrDefault(); cell = new HtmlTableCell(); cell.InnerText = matchInfo.stadiumName; row.Cells.Add(cell); cell = new HtmlTableCell(); cell.InnerText = matchInfo.matchDate.ToString("dd/MM/yyyy"); row.Cells.Add(cell); var local = (from mt in ctx.MatchesTeam from t in ctx.Teams where mt.matchId == matchInfo.matchId && mt.teamId == t.teamId && mt.teamIsLocal == true select t).SingleOrDefault(); cell = new HtmlTableCell(); cell.InnerText = local.teamName; row.Cells.Add(cell); cell = new HtmlTableCell(); cell.InnerText = prediction.homeResult.ToString(); row.Cells.Add(cell); cell = new HtmlTableCell(); cell.InnerText = prediction.homePenaltyResult.ToString(); row.Cells.Add(cell); var visitor = (from mt in ctx.MatchesTeam from t in ctx.Teams where mt.matchId == matchInfo.matchId && mt.teamId == t.teamId && mt.teamIsLocal == false select t).SingleOrDefault(); cell = new HtmlTableCell(); cell.InnerText = visitor.teamName; row.Cells.Add(cell); cell = new HtmlTableCell(); cell.InnerText = prediction.awayResult.ToString(); row.Cells.Add(cell); cell = new HtmlTableCell(); cell.InnerText = prediction.awayPenaltyResult.ToString(); row.Cells.Add(cell); cell = new HtmlTableCell(); cell.InnerText = prediction.matchPredictionModify.ToString(); row.Cells.Add(cell); table.Rows.Add(row); } StringBuilder sb = new StringBuilder(); StringWriter tw = new StringWriter(sb); HtmlTextWriter hw = new HtmlTextWriter(tw); table.RenderControl(hw); builder.Append(sb.ToString()); builder.Append("<br>"); } mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(builder.ToString(), null, MediaTypeNames.Text.Html)); mailMsg.IsBodyHtml = true; mailMsg.From = new MailAddress("*****@*****.**"); //mailMsg.To.Add(new MailAddress(user.emailAddress)); mailMsg.Subject = "Predicciones hechas por los usuarios para el Mundial 2014"; SmtpClient smtpClient = null; smtpClient = new SmtpClient(); //smtpClient.Send(new MailMessage("*****@*****.**", user.emailAddress, "Predicciones hechas por los usuarios para el Mundial 2014", string.Empty)); smtpClient.Send(mailMsg); return RedirectToAction("Index", "Home"); }
public ActionResult ApplyFormulaMatch(int id) { Context ctx = new Context(); var match = (from m in ctx.Matches where m.matchId == id select m).FirstOrDefault(); string formula = string.Empty; if (match.IsFormula) { if (match.formulaByGroups) { formula = match.formula; string[] groups = formula.Split(new char[] { '-' }); var firstLeg = (from g in ctx.Groups from t in ctx.Teams where g.groupName.Contains(" " + groups[0].Substring(0, 1)) && t.groupId == g.groupId select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList(); var secondLeg = (from g in ctx.Groups from t in ctx.Teams where g.groupName.Contains(" " + groups[1].Substring(0, 1)) && t.groupId == g.groupId select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList(); Teams teamId1 = null; Teams teamId2 = null; if (groups[0].Substring(1, 1).ToString().Equals("1")) teamId1 = firstLeg.FirstOrDefault(); else teamId1 = firstLeg.Skip(1).Take(1).SingleOrDefault(); if(groups[1].Substring(1, 1).ToString().Equals("1")) teamId2 = secondLeg.FirstOrDefault(); else teamId2 = secondLeg.Skip(1).Take(1).SingleOrDefault(); MatchesTeam mt = new MatchesTeam(); mt.matchId = match.matchId; mt.teamId = teamId1.teamId; mt.teamIsLocal = true; ctx.MatchesTeam.Add(mt); mt = new MatchesTeam(); mt.matchId = match.matchId; mt.teamId = teamId2.teamId; mt.teamIsLocal = false; ctx.MatchesTeam.Add(mt); } else { formula = match.formula; string[] games = formula.Split(new char[] { '-' }); int matchFormula = 0; if (games[0].Substring(0, 1).ToString().Equals("W")) { matchFormula = int.Parse(games[0].Substring(1, 2).ToString()); var matchResult = (from m in ctx.Matches where m.matchId == matchFormula select m).FirstOrDefault(); } else { } } ctx.SaveChanges(); return View(); } else { return RedirectToAction("Index", "Home"); } }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return RedirectToAction("Manage"); } if (ModelState.IsValid) { // Insert a new user into the database using (Context db = new Context()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); //Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return RedirectToLocal(returnUrl); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return View(model); }
public ActionResult Champions() { Context ctx = new Context(); var user = (from u in ctx.UserProfiles where u.UserName == User.Identity.Name select u).SingleOrDefault(); var teams = (from t in ctx.Teams select t).OrderBy(o => o.teamId).FirstOrDefault(); List<UserFinalist> userFinalist = new List<UserFinalist>(); for (int i = 1; i <= 4; i++) { UserFinalist f = new UserFinalist(); f.position = i; f.teamId = teams.teamId; f.UserId = user.UserId; userFinalist.Add(f); } ViewBag.UserFinalist = userFinalist; var teamsList = ( from t in ctx.Teams select t).OrderBy(o => o.teamId).ToList(); List<SelectListItem> list = new List<SelectListItem>(); foreach(Teams t in teamsList) { list.Add(new SelectListItem() { Value = t.teamId.ToString(), Text = t.teamName }); } ViewBag.Teams = list; return View(); //return View(); }
public ActionResult Champions(FormCollection form) { Context ctx = new Context(); var users = (from u in ctx.UserProfiles where u.UserName == User.Identity.Name select u).SingleOrDefault(); int team1 = int.Parse(form[form.Keys.Get(1)].ToString()); int team2 = int.Parse(form[form.Keys.Get(2)].ToString()); int team3 = int.Parse(form[form.Keys.Get(3)].ToString()); int team4 = int.Parse(form[form.Keys.Get(4)].ToString()); List<Int32> teams = new List<int>(); teams.Add(team1); if (teams.Contains(team2)) { ModelState.AddModelError("", "Revise los finalistas no puede haber repetidos."); return RedirectToAction("Champions", "Account"); } if (teams.Contains(team3)) { ModelState.AddModelError("", "Revise los finalistas no puede haber repetidos."); return RedirectToAction("Champions", "Account"); } if (teams.Contains(team4)) { ModelState.AddModelError("", "Revise los finalistas no puede haber repetidos."); return RedirectToAction("Champions", "Account"); } ctx.UserFinalist.Add(new UserFinalist() { position = 1, teamId = team1, UserId = users.UserId }); ctx.UserFinalist.Add(new UserFinalist() { position = 2, teamId = team2, UserId = users.UserId }); ctx.UserFinalist.Add(new UserFinalist() { position = 3, teamId = team3, UserId = users.UserId }); ctx.UserFinalist.Add(new UserFinalist() { position = 4, teamId = team4, UserId = users.UserId }); ctx.SaveChanges(); return RedirectToAction("Index", "Home"); }
public ActionResult Calculate() { Context ctx = new Context(); int matchResult = 0; //int matchPenalty = 0; int matchPredictionResult = 0; //int matchPredictionPenalty = 0; bool isDraw = false; //get users var users = (from u in ctx.UserProfiles where u.UserName != "admin" && u.isActive == true select u).ToList(); ////get list of matches processed //var matchesProcessed = (from mp in ctx.MatchProcessed // where mp.matchProcessed == false // select mp.matchId).ToList(); //running users foreach (UserProfile up in users) { //get predictions form users var predictions = (from p in ctx.Predictions from m in ctx.Matches from mp in ctx.MatchProcessed where p.UserId == up.UserId && m.matchId == p.matchId && p.matchPredictionModify != null && mp.matchId == p.matchId && mp.matchProcessed == false select p).OrderBy(o => o.matchId).ToList(); foreach (Predictions p in predictions) { var match = (from m in ctx.Matches where m.matchId == p.matchId select m).FirstOrDefault(); matchResult = match.homeResult - match.awayResult; matchPredictionResult = p.homeResult - p.awayResult; //Draw if (matchResult == 0 && matchPredictionResult == 0) { up.pointsEarned += 5; if (match.homeResult == p.homeResult && match.awayResult == p.awayResult) { up.pointsEarned += 5; } isDraw = true; } //local win if (matchResult > 0 && matchPredictionResult > 0) { up.pointsEarned += 5; if (match.homeResult == p.homeResult && match.awayResult == p.awayResult) { up.pointsEarned += 5; } isDraw = false; } //away win if (matchResult < 0 && matchPredictionResult < 0) { up.pointsEarned += 5; if (match.homeResult == p.homeResult && match.awayResult == p.awayResult) { up.pointsEarned += 5; } isDraw = false; } if (match.IsFormula && isDraw) { //validate penalties if (match.homePenaltyResult == p.homePenaltyResult && match.awayPenaltyResult == p.awayPenaltyResult) { up.pointsEarned += 5; } } if (match.matchId >= 63) { //validate the finalist var finalistThird = (from f in ctx.UserFinalist where f.UserId == up.UserId && f.position == (match.matchId == 63 ? 3 : 1) select f).FirstOrDefault(); var finalistFourth = (from f in ctx.UserFinalist where f.UserId == up.UserId && f.position == (match.matchId == 63 ? 4 : 2) select f).FirstOrDefault(); if (!isDraw) { matchResult = match.homeResult - match.awayResult; if (matchResult < 0) { var teamWinner = (from mt in ctx.MatchesTeam where mt.matchId == match.matchId && !mt.teamIsLocal select mt).FirstOrDefault(); var teamLoser = (from mt in ctx.MatchesTeam where mt.matchId == match.matchId && mt.teamIsLocal select mt).FirstOrDefault(); if (finalistThird.teamId == teamWinner.teamId) { if (match.matchId == 63) up.pointsEarned += 50; else up.pointsEarned += 100; } else if (finalistFourth.teamId == teamLoser.teamId) { if (match.matchId == 63) up.pointsEarned += 25; else up.pointsEarned += 75; } } else { var teamWinner = (from mt in ctx.MatchesTeam where mt.matchId == match.matchId && mt.teamIsLocal select mt).FirstOrDefault(); var teamLoser = (from mt in ctx.MatchesTeam where mt.matchId == match.matchId && !mt.teamIsLocal select mt).FirstOrDefault(); if (finalistThird.teamId == teamWinner.teamId) { if (match.matchId == 63) up.pointsEarned += 50; else up.pointsEarned += 100; } else if (finalistFourth.teamId == teamLoser.teamId) { if (match.matchId == 63) up.pointsEarned += 25; else up.pointsEarned += 75; } } } else { matchResult = match.homePenaltyResult - match.awayPenaltyResult; if (matchResult < 0) { var teamWinner = (from mt in ctx.MatchesTeam where mt.matchId == match.matchId && !mt.teamIsLocal select mt).FirstOrDefault(); var teamLoser = (from mt in ctx.MatchesTeam where mt.matchId == match.matchId && mt.teamIsLocal select mt).FirstOrDefault(); if (finalistThird.teamId == teamWinner.teamId) { if (match.matchId == 63) up.pointsEarned += 50; else up.pointsEarned += 100; } else if (finalistFourth.teamId == teamLoser.teamId) { if (match.matchId == 63) up.pointsEarned += 25; else up.pointsEarned += 75; } } else { var teamWinner = (from mt in ctx.MatchesTeam where mt.matchId == match.matchId && mt.teamIsLocal select mt).FirstOrDefault(); var teamLoser = (from mt in ctx.MatchesTeam where mt.matchId == match.matchId && !mt.teamIsLocal select mt).FirstOrDefault(); if (finalistThird.teamId == teamWinner.teamId) { if (match.matchId == 63) up.pointsEarned += 50; else up.pointsEarned += 100; } else if (finalistFourth.teamId == teamLoser.teamId) { if (match.matchId == 63) up.pointsEarned += 25; else up.pointsEarned += 75; } } } } var matchProcess = (from mp in ctx.MatchProcessed where mp.matchId == match.matchId && mp.matchProcessed == false select mp).FirstOrDefault(); matchProcess.matchProcessed = true; } } ctx.SaveChanges(); return RedirectToAction("List", "Account"); }
public ActionResult UserData(int id) { Context ctx = new Context(); var user = (from u in ctx.UserProfiles where u.UserName == User.Identity.Name select u).SingleOrDefault(); var userFinalist = (from f in ctx.UserFinalist where f.UserId == user.UserId select f).Count(); if (userFinalist != 4 && !User.Identity.Name.Equals("admin")) { return RedirectToAction("Champions", "Account"); } var finalist = (from uf in ctx.UserFinalist from t in ctx.Teams where uf.UserId == id && t.teamId == uf.teamId select new FinalistModel { position = uf.position, teamName = t.teamName, teamImage = t.teamImage }).OrderBy(o => o.position).ToList(); ViewData["FinalistasUsuario"] = finalist; var predictions = (from p in ctx.Predictions from ma in ctx.Matches where p.UserId == id && ma.matchId == p.matchId && p.matchPredictionModify != null select new PredictionUser { predictionId = p.predictionId, matchId = ma.matchId, Stadium = ma.stadiumName, matchDate = ma.matchDate, teamHome = string.Empty, teamHomeImage = string.Empty, teamHomeResult = p.homeResult, temaHomePResult = p.homePenaltyResult, teamAway = string.Empty, teamAwayImage = string.Empty, teamAwayResult = p.awayResult, temaAwayPResult = p.awayPenaltyResult, }).OrderBy(o => o.predictionId).ToList(); foreach (var obj in predictions) { obj.teamHome = (from mt in ctx.MatchesTeam from t in ctx.Teams where mt.matchId == obj.matchId && t.teamId == mt.teamId && mt.teamIsLocal == true select t.teamName).FirstOrDefault(); obj.teamHomeImage = (from mt in ctx.MatchesTeam from t in ctx.Teams where mt.matchId == obj.matchId && t.teamId == mt.teamId && mt.teamIsLocal == true select t.teamImage).FirstOrDefault(); obj.teamAway = (from mt in ctx.MatchesTeam from t in ctx.Teams where mt.matchId == obj.matchId && t.teamId == mt.teamId && mt.teamIsLocal == false select t.teamName).FirstOrDefault(); obj.teamAwayImage = (from mt in ctx.MatchesTeam from t in ctx.Teams where mt.matchId == obj.matchId && t.teamId == mt.teamId && mt.teamIsLocal == false select t.teamImage).FirstOrDefault(); } var userData = (from u in ctx.UserProfiles where u.UserId == id select u.userCompleteName).FirstOrDefault(); ViewBag.Title = "Finalistas y Predicciones del Usuario " + userData; ViewData["Predictions"] = predictions; return View(); }
public ActionResult Index() { Context ctx = new Context(); var user = (from u in ctx.UserProfiles where u.UserName == User.Identity.Name select u).SingleOrDefault(); var userFinalist = (from f in ctx.UserFinalist where f.UserId == user.UserId select f).Count(); if (userFinalist != 4 && !User.Identity.Name.Equals("admin")) { return RedirectToAction("Champions", "Account"); } var groups = (from g in ctx.Groups select g).ToList(); ViewBag.Groups = groups; foreach (Groups g in groups) { switch (g.groupId) { case 1: var GroupA = (from t in ctx.Teams where t.groupId == g.groupId select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList(); ViewBag.GroupA = GroupA; break; case 2: var GroupB = (from t in ctx.Teams where t.groupId == g.groupId select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList(); ViewBag.GroupB = GroupB; break; case 3: var GroupC = (from t in ctx.Teams where t.groupId == g.groupId select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList(); ViewBag.GroupC = GroupC; break; case 4: var GroupD = (from t in ctx.Teams where t.groupId == g.groupId select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList(); ViewBag.GroupD = GroupD; break; case 5: var GroupE = (from t in ctx.Teams where t.groupId == g.groupId select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList(); ViewBag.GroupE = GroupE; break; case 6: var GroupF = (from t in ctx.Teams where t.groupId == g.groupId select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList(); ViewBag.GroupF = GroupF; break; case 7: var GroupG = (from t in ctx.Teams where t.groupId == g.groupId select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList(); ViewBag.GroupG = GroupG; break; case 8: var GroupH = (from t in ctx.Teams where t.groupId == g.groupId select t).OrderByDescending(o => o.points).ThenByDescending(o => o.goalsDifference).ThenByDescending(o => o.goalsFavor).ThenByDescending(o => o.goalsAgainst).ToList(); ViewBag.GroupH = GroupH; break; } } return View(); }
public ActionResult List(string date) { DateTime fecha = DateTime.Now; if (date == null) { fecha = new DateTime(Util.LocalDate.Now.Year, Util.LocalDate.Now.Month, Util.LocalDate.Now.Day); } else { fecha = DateTime.Parse(date); } Context ctx = new Context(); var matches = (from m in ctx.Matches where m.matchDate == fecha select new ModifyMatches() { matchId = m.matchId, matchDate = m.matchDate, matchNumber = m.matchNumber, stadiumName = m.stadiumName, matchResult = string.Empty, matchPenaltyResult = string.Empty }).OrderBy(o => o.matchId).ToList(); foreach (ModifyMatches m in matches) { var teams = (from mt in ctx.MatchesTeam from t in ctx.Teams where mt.matchId == m.matchId && t.teamId == mt.teamId select new { mt.teamIsLocal, t.teamName, t.teamImage }); var results = (from ma in ctx.Matches where ma.matchId == m.matchId select ma).SingleOrDefault(); m.matchResult = results.homeResult.ToString() + "-" + results.awayResult.ToString(); m.matchPenaltyResult = results.homePenaltyResult.ToString() + "-" + results.awayPenaltyResult.ToString(); foreach (var obj in teams) { if (obj.teamIsLocal) { m.HomeFlag = obj.teamImage; m.HomeTeam = obj.teamName; } else { m.AwayFlag = obj.teamImage; m.AwayTeam = obj.teamName; } } } ViewBag.Matches = matches; return View(); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { Context ctx = new Context(); WebSecurity.CreateUserAndAccount(model.UserName, model.Password); var userProfile = (from u in ctx.UserProfiles where u.UserName == model.UserName select u).SingleOrDefault(); userProfile.isActive = model.UserName.Equals("admin") ? true : false; userProfile.pointsEarned = 0; userProfile.userCompleteName = model.userCompleteName; userProfile.emailAddress = model.emailAddress; if (model.UserName != "admin") { var matches = (from m in ctx.Matches select m).OrderBy(o => o.matchNumber).ToList(); foreach (Matches m in matches) { var prediction = new Predictions(); prediction.matchId = m.matchId; prediction.awayPenaltyResult = 0; prediction.homePenaltyResult = 0; prediction.homeResult = 0; prediction.awayResult = 0; prediction.matchPredictionCreateDate = Util.LocalDate.Now; prediction.UserId = userProfile.UserId; ctx.Predictions.Add(prediction); } } ctx.SaveChanges(); //WebSecurity.Login(model.UserName, model.Password); return RedirectToAction("Login", "Account"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
// // GET: /Match/ public ActionResult Edit(int id) { Context ctx = new Context(); return View((from m in ctx.Matches where m.matchId == id select m).SingleOrDefault()); }
public ActionResult ResetAll() { Context ctx = new Context(); var matchesProcessed = (from mp in ctx.MatchProcessed select mp).ToList(); foreach (var mp in matchesProcessed) { ctx.MatchProcessed.Remove(mp); } var users = (from u in ctx.UserProfiles where u.UserName != "admin" select u).ToList(); foreach (var user in users) { user.pointsEarned = 0; } //Remove teams stadistics var teams = (from t in ctx.Teams select t).ToList(); foreach (var team in teams) { team.goalsAgainst = 0; team.goalsDifference = 0; team.goalsFavor = 0; team.matchesDraw = 0; team.matchesLoses = 0; team.matchesPlayed = 0; team.matchesWin = 0; team.points = 0; } ctx.SaveChanges(); return RedirectToAction("Index", "Home"); }
public ActionResult Login(LoginModel model, string returnUrl) { Context ctx = new Context(); if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { var user = (from u in ctx.UserProfiles where u.UserName == model.UserName select u).SingleOrDefault(); if (!user.isActive) { WebSecurity.Logout(); ModelState.AddModelError("", "Usuario no activo"); return View(model); } return RedirectToLocal(returnUrl); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "El usuario y contraseña proporcionados no son correctos."); return View(model); }
public ActionResult Authorize() { Context ctx = new Context(); var users = (from u in ctx.UserProfiles where !u.isActive select u).ToList(); ViewBag.Users = users; return View(); }