public ActionResult MoveUp(int id) { var match = _db.Matches.Find(id); if (match == null) { return(HttpNotFound()); } var weekMatches = _db.Matches.Where(x => x.WeekId == match.WeekId); var match1 = weekMatches.First(x => x.Rink == match.Rink - 1); match1.Rink = match.Rink; match.Rink = match1.Rink - 1; _db.Entry(match).State = EntityState.Modified; try { _db.SaveChanges(); } catch (Exception e) { ErrorSignal.FromCurrentContext().Raise(e); throw; } return(RedirectToAction("Index", new { weekid = match.WeekId, id = match.Schedule.Leagueid })); }
public ActionResult Edit([Bind(Include = "id,UserId,LeagueId,Roles,rowversion")] UserLeague userLeague) { try { if (ModelState.IsValid) { _db.Entry(userLeague).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index", new { id = userLeague.LeagueId })); } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (UserLeague)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes. The member was deleted by another user."); } else { var databaseValues = (UserLeague)databaseEntry.ToObject(); if (databaseValues.UserId != clientValues.UserId) { ModelState.AddModelError("User", "Current value: " + databaseValues.User.username); } if (databaseValues.LeagueId != clientValues.LeagueId) { ModelState.AddModelError("League", "Current value: " + databaseValues.League.LeagueName); } if (databaseValues.Roles != clientValues.Roles) { ModelState.AddModelError("Roles", "Current value: " + databaseValues.Roles); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); userLeague.rowversion = databaseValues.rowversion; } } catch (Exception dex) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); ErrorSignal.FromCurrentContext().Raise(dex); } return(View(userLeague)); }
public ActionResult Edit([Bind(Include = "id,LeagueId,MembershipId,rowversion")] Player player) { try { if (ModelState.IsValid) { _db.Entry(player).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index", new { id = player.Leagueid })); } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Player)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes. The player was deleted by another user."); } else { var databaseValues = (Player)databaseEntry.ToObject(); if (databaseValues.Leagueid != clientValues.Leagueid) { ModelState.AddModelError("League", "Current value: " + databaseValues.Leagueid); } if (databaseValues.MembershipId != clientValues.MembershipId) { ModelState.AddModelError("Member", "Current value: " + databaseValues.MembershipId); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); player.rowversion = databaseValues.rowversion; } } catch (Exception dex) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); ErrorSignal.FromCurrentContext().Raise(dex); } var list = GetRemainingMembers(player.Leagueid); list.Add(player.Membership); list.Sort((a, b) => String.Compare(a.LastName + " " + a.FirstName, b.LastName + " " + b.FirstName, StringComparison.CurrentCulture)); ViewBag.List = list; return(View(player)); }
public ActionResult Edit([Bind(Include = "id,username,Roles,password,rowversion")] User user) { if (ModelState.IsValid) { var sharedSecret = (string)TempData["Secret"]; user.password = Crypto.DecryptStringAES(user.password, sharedSecret); user.username = user.username.ToLower().Trim(); _db.Entry(user).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } var dict = new List <Role>(); dict.Add(new Role("", "No Roles")); dict.Add(new Role("Admin", "Admin")); ViewBag.Roles = new SelectList(dict, "RoleValue", "RoleText", user.Roles); return(View(user)); }
public ActionResult Edit([Bind(Include = "id,FirstName,LastName,FullName,shortname,NickName,rowversion")] Membership membership) { if (ModelState.IsValid) { db.Entry(membership).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(membership)); }
public ActionResult ChangePassword( [Bind(Include = "EmailAddress,OldPassword, Password,Confirm")] ChangePasswordViewModel chpvm) { if (ModelState.IsValid) { var users = _db.Users.Where(x => x.username == chpvm.EmailAddress.ToLower().Trim()); if (!users.Any()) { ModelState.AddModelError(string.Empty, "User Id or Current Password not found"); return(View(chpvm)); } var user = users.First(); if (user.password != chpvm.OldPassword) { ModelState.AddModelError(string.Empty, "User Id or Current Password not found"); return(View(chpvm)); } if (chpvm.Password != chpvm.Confirm) { ModelState.AddModelError(string.Empty, "New Password and Confirming Password are not the same"); return(View(chpvm)); } try { user.password = chpvm.Password; _db.Entry(user).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("PasswordAccepted", "Accounts")); } catch { ModelState.AddModelError(string.Empty, "Password was not updated, try again"); } } return(View(chpvm)); }
public ActionResult Edit([Bind(Include = "id,Skip,Lead,ViceSkip,TeamId,LeagueId,TeamNo,rowversion")] Team team) { try { if (ModelState.IsValid) { team.Skip = team.Skip == 0 ? (int?)null : team.Skip; team.ViceSkip = team.ViceSkip == 0 ? (int?)null : team.ViceSkip; team.Lead = team.Lead == 0 ? (int?)null : team.Lead; if (CheckTeam(team)) { ModelState.AddModelError(string.Empty, "Unable to save record, a player cannot be on a team in multiple positions"); } else { _db.Entry(team).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index", new { id = team.Leagueid })); } } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Team)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes. The member was deleted by another user."); } else { var databaseValues = (Team)databaseEntry.ToObject(); if (databaseValues.Skip != clientValues.Skip) { ModelState.AddModelError("Skip", "Current value: " + databaseValues.Skip); } if (databaseValues.ViceSkip != clientValues.ViceSkip) { ModelState.AddModelError("Vice Skip", "Current value: " + databaseValues.ViceSkip); } if (databaseValues.Lead != clientValues.Lead) { ModelState.AddModelError("Lead", "Current value: " + databaseValues.Lead); } if (databaseValues.Leagueid != clientValues.Leagueid) { ModelState.AddModelError("League", "Current value: " + databaseValues.Leagueid); } if (databaseValues.TeamNo != clientValues.TeamNo) { ModelState.AddModelError("Team Number", "Current value: " + databaseValues.TeamNo); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); team.rowversion = databaseValues.rowversion; } } var league = _db.Leagues.Find(team.Leagueid); if (league == null) { return(HttpNotFound()); } var teams = _db.Teams.Where(x => x.Leagueid == team.Leagueid).OrderBy(x => x.TeamNo); var list = RemainingPlayers(team, teams.ToList()); ViewBag.List = list; ViewBag.Teams = teams; ViewBag.TeamSize = league.TeamSize; return(View(team)); }
public ActionResult Edit([Bind(Include = "id,FirstName,LastName,shortname,Wheelchair,rowversion")] Membership membership) { try { if (ModelState.IsValid) { _db.Entry(membership).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Membership)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes. The member was deleted by another user."); } else { var databaseValues = (Membership)databaseEntry.ToObject(); if (databaseValues.FirstName != clientValues.FirstName) { ModelState.AddModelError("First Name", "Current value: " + databaseValues.FirstName); } if (databaseValues.LastName != clientValues.LastName) { ModelState.AddModelError("Last Name", "Current value: " + databaseValues.LastName); } if (databaseValues.shortname != clientValues.shortname) { ModelState.AddModelError("Short Name", "Current value: " + databaseValues.shortname); } if (databaseValues.Wheelchair != clientValues.Wheelchair) { ModelState.AddModelError("Wheelchair", "Current value: " + databaseValues.Wheelchair); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); membership.rowversion = databaseValues.rowversion; } } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. Cannot have duplicate names."); } catch (Exception dex) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); ErrorSignal.FromCurrentContext().Raise(dex); } return(View(membership)); }
public ActionResult Edit([Bind(Include = "id,Green,Direction,Boundary,rowversion")] RinkOrder rinkOrder) { try { if (ModelState.IsValid) { db.Entry(rinkOrder).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (RinkOrder)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes. The rink was deleted by another user."); } else { var databaseValues = (RinkOrder)databaseEntry.ToObject(); if (databaseValues.id != clientValues.id) { ModelState.AddModelError("id", "Current value: " + databaseValues.id); } if (databaseValues.Direction != clientValues.Direction) { ModelState.AddModelError("Direction", "Current value: " + databaseValues.Direction); } if (databaseValues.Green != clientValues.Green) { ModelState.AddModelError("Green", "Current value: " + databaseValues.Green); } if (databaseValues.Boundary != clientValues.Boundary) { ModelState.AddModelError("Boundary", "Current value: " + databaseValues.Boundary); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); rinkOrder.rowversion = databaseValues.rowversion; } } catch (Exception dex) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); ErrorSignal.FromCurrentContext().Raise(dex); } return(View(rinkOrder)); }
public ActionResult Edit([Bind(Include = "id,GameDate,Leagueid,Cancelled,rowversion")] Schedule schedule) { try { if (ModelState.IsValid) { if (db.Schedules.Any(x => x.GameDate == schedule.GameDate && x.id != schedule.id)) { ModelState.AddModelError(string.Empty, "Duplicate date is not allowed"); } else { db.Entry(schedule).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", new { id = schedule.Leagueid })); } } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Schedule)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes. The schedule record was deleted by another user."); } else { var databaseValues = (Schedule)databaseEntry.ToObject(); if (databaseValues.WeekDate != clientValues.WeekDate) { ModelState.AddModelError("Game Date", "Current value: " + databaseValues.GameDate.ToShortDateString()); } if (databaseValues.Cancelled != clientValues.Cancelled) { ModelState.AddModelError("Cancelled", "Current value: " + databaseValues.Cancelled); } if (databaseValues.Leagueid != clientValues.Leagueid) { ModelState.AddModelError("League", "Current value: " + databaseValues.Leagueid); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); schedule.rowversion = databaseValues.rowversion; } } catch (Exception dex) { while (dex.InnerException != null) { dex = dex.InnerException; } //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", $"Unable to save changes. {dex.Message}"); ErrorSignal.FromCurrentContext().Raise(dex); } ViewBag.Schedule = db.Schedules.Where(x => x.Leagueid == schedule.Leagueid).OrderBy(x => x.GameDate); return(View(schedule)); }
public ActionResult Edit([Bind(Include = "id,LeagueName,TeamSize,Active,rowversion,TiesAllowed,PointsCount,WinPoints,TiePoints,ByePoints,StartWeek")] League league) { try { if (ModelState.IsValid) { _db.Entry(league).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (League)entry.Entity; var databaseEntry = entry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes. The league was deleted by another user."); } else { var databaseValues = (League)databaseEntry.ToObject(); if (databaseValues.LeagueName != clientValues.LeagueName) { ModelState.AddModelError("League Name", "Current value: " + databaseValues.LeagueName); } if (databaseValues.TeamSize != clientValues.TeamSize) { ModelState.AddModelError("Team Size", "Current value: " + databaseValues.TeamSize); } if (databaseValues.Active != clientValues.Active) { ModelState.AddModelError("Active", "Current value: " + databaseValues.Active); } if (databaseValues.TiesAllowed != clientValues.TiesAllowed) { ModelState.AddModelError("Ties Allowed", "Current value: " + databaseValues.TiesAllowed); } if (databaseValues.PointsCount != clientValues.PointsCount) { ModelState.AddModelError("Do Points Count", "Current value: " + databaseValues.PointsCount); } if (databaseValues.WinPoints != clientValues.WinPoints) { ModelState.AddModelError("Win Points", "Current value: " + databaseValues.WinPoints); } if (databaseValues.TiePoints != clientValues.TiePoints) { ModelState.AddModelError("Tie Points", "Current value: " + databaseValues.TiePoints); } if (databaseValues.ByePoints != clientValues.ByePoints) { ModelState.AddModelError("Bye Points", "Current value: " + databaseValues.ByePoints); } if (databaseValues.StartWeek != clientValues.StartWeek) { ModelState.AddModelError("Start Week", "Current value: " + databaseValues.StartWeek); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); league.rowversion = databaseValues.rowversion; } } catch (Exception dex) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); ErrorSignal.FromCurrentContext().Raise(dex); } return(View(league)); }