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 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); }