public async Task <ActionResult> Edit(ManagerViewModel managerViewModel) { ModelState.Remove("Email1.EmailId"); ModelState.Remove("Email2.EmailId"); ModelState.Remove("Email1.ManagerId"); ModelState.Remove("Email2.ManagerId"); if (ModelState.IsValid) { if (!string.IsNullOrEmpty(managerViewModel.Email1.Address)) { if (managerViewModel.Email1.EmailId == 0) { managerViewModel.Email1.ManagerId = managerViewModel.Manager.ManagerId; db.Emails.Add(managerViewModel.Email1); } else { db.SetModified(managerViewModel.Email1); } } if (!string.IsNullOrEmpty(managerViewModel.Email2.Address)) { if (managerViewModel.Email2.EmailId == 0) { managerViewModel.Email2.ManagerId = managerViewModel.Manager.ManagerId; db.Emails.Add(managerViewModel.Email2); } else { db.SetModified(managerViewModel.Email2); } } if (string.IsNullOrEmpty(managerViewModel.Email1.Address) && managerViewModel.Email1.EmailId > 0) { var email = new Email { EmailId = managerViewModel.Email1.EmailId }; db.SetModified(email); } if (string.IsNullOrEmpty(managerViewModel.Email2.Address) && managerViewModel.Email2.EmailId > 0) { var email = new Email { EmailId = managerViewModel.Email2.EmailId }; db.SetModified(email); } db.SetModified(managerViewModel.Manager); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(managerViewModel)); }
public async Task <ActionResult> Edit([Bind(Include = "ConcedeId,TeamId,GameWeekId,ManagerId,Substitute")] Concede concede) { if (ModelState.IsValid) { concede.Created = DateTime.UtcNow; concede.CreatedBy = User.Identity.Name; var managerGoalKeeper = db.ManagerGoalKeepers.AsNoTracking().Where(x => x.TeamId == concede.TeamId).FirstOrDefault(); if (managerGoalKeeper != null) { concede.ManagerId = managerGoalKeeper.ManagerId; concede.Substitute = managerGoalKeeper.Substitute; } db.SetModified(concede); var team = db.Teams.Where(x => x.TeamId == concede.TeamId).FirstOrDefault(); auditService.Log("Concede", "Concede Updated", User.Identity.Name, string.Format("{0} conceded updated for {1} ({2})", !concede.Cup ? "Goal" : "Cup goal", team?.Name, team?.ManagerGoalKeepers?.FirstOrDefault()?.Manager?.Name ?? "Unattached"), concede.GameWeekId); await db.SaveChangesAsync(); gameWeekSummaryService.Create(concede.GameWeekId); cupWeekSummaryService.Create(concede.GameWeekId); return(RedirectToAction("Index")); } ViewBag.GameWeekId = new SelectList(db.GameWeeks.AsNoTracking().OrderBy(x => x.Number), "GameWeekId", "Details", gameWeekService.GetCurrent()?.GameWeekId); ViewBag.TeamId = new SelectList(db.ManagerGoalKeepers.AsNoTracking().Include(x => x.Team).OrderBy(x => x.Team.Name), "TeamId", "Details"); return(View(concede)); }
public async Task <ActionResult> Edit(GroupViewModel groupViewModel) { if (ModelState.IsValid) { Group existing = db.Groups.Include(x => x.Managers).Where(x => x.GroupId == groupViewModel.Group.GroupId).FirstOrDefault(); foreach (var manager in db.Managers) { if (groupViewModel.Managers.Exists(x => x.Manager.ManagerId == manager.ManagerId && x.Selected)) { if (!existing.Managers.Exists(x => x.ManagerId == manager.ManagerId)) { existing.Managers.Add(manager); } } else if (existing.Managers.Exists(x => x.ManagerId == manager.ManagerId)) { existing.Managers.Remove(manager); } } existing.Name = groupViewModel.Group.Name; existing.GroupLegs = groupViewModel.Group.GroupLegs; existing.TeamsAdvancing = groupViewModel.Group.TeamsAdvancing; db.SetModified(existing); await db.SaveChangesAsync(); return(RedirectToAction("Details", "Cup", new { id = groupViewModel.Cup.CupId })); } return(View(groupViewModel)); }
public async Task <ActionResult> Edit([Bind(Include = "GameWeekId,Number,Start,Complete")] GameWeek gameWeek) { if (ModelState.IsValid) { db.SetModified(gameWeek); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(gameWeek)); }
public async Task <ActionResult> Edit([Bind(Include = "MeetingId,Date,Location,Longitude,Latitude")] Meeting meeting) { if (ModelState.IsValid) { db.SetModified(meeting); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(meeting)); }
public async Task <ActionResult> Edit([Bind(Include = "CupId,Name,HasGroupStage,KnockoutLegs,FinalLegs")] Cup cup) { if (ModelState.IsValid) { db.SetModified(cup); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(cup)); }
public async Task <ActionResult> Edit([Bind(Include = "HistoryId,Year,Teams,League1,League2,Cup,Plate,LeagueCup")] History history) { if (ModelState.IsValid) { db.SetModified(history); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(history)); }
public async Task <ActionResult> Edit([Bind(Include = "LeagueId,Name,Rank")] League league) { if (ModelState.IsValid) { db.SetModified(league); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(league)); }
public async Task <ActionResult> Edit([Bind(Include = "TeamId,LeagueId,Name,Alias")] Team team) { if (ModelState.IsValid) { db.SetModified(team); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.LeagueId = new SelectList(db.Leagues, "LeagueId", "Name", team.LeagueId); return(View(team)); }
public async Task <ActionResult> Edit([Bind(Include = "PlayerId,TeamId,FirstName,LastName,Position")] Player player) { if (ModelState.IsValid) { db.SetModified(player); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.TeamId = new SelectList(db.Teams.AsNoTracking().OrderBy(x => x.Name), "TeamId", "Name", player.TeamId); return(View(player)); }
public async Task <ActionResult> Edit([Bind(Include = "FixtureId,CupId,GameWeekId,HomeManagerId,AwayManagerId,Round")] Fixture fixture) { if (ModelState.IsValid) { db.SetModified(fixture); await db.SaveChangesAsync(); return(RedirectToAction("Details", "Cup", new { id = fixture.CupId })); } var managers = db.Managers.AsNoTracking().OrderBy(x => x.Name); ViewBag.AwayManagerId = new SelectList(managers, "ManagerId", "Name", fixture.AwayManagerId); ViewBag.GameWeekId = new SelectList(db.GameWeeks.AsNoTracking().OrderBy(x => x.Number), "GameWeekId", "Details", fixture.GameWeekId); ViewBag.HomeManagerId = new SelectList(managers, "ManagerId", "Name", fixture.HomeManagerId); return(View(fixture)); }
public async Task <ActionResult> Edit([Bind(Include = "GoalId,PlayerId,GameWeekId")] Goal goal) { if (ModelState.IsValid) { var managerId = db.ManagerPlayers.AsNoTracking().Where(x => x.PlayerId == goal.PlayerId).Select(x => x.ManagerId).FirstOrDefault(); goal.ManagerId = managerId; goal.Created = DateTime.UtcNow; goal.CreatedBy = User.Identity.Name; db.SetModified(goal); var player = db.Players.Where(x => x.PlayerId == goal.PlayerId).FirstOrDefault(); auditService.Log("Goal", "Goal Updated", User.Identity.Name, string.Format("{0} updated for {1} ({2})", !goal.Cup ? "Goal" : "Cup goal", player?.FullName, player?.ManagerPlayers?.FirstOrDefault()?.Manager?.Name ?? "Unattached"), goal.GameWeekId); await db.SaveChangesAsync(); gameWeekSummaryService.Create(goal.GameWeekId); cupWeekSummaryService.Create(goal.GameWeekId); return(RedirectToAction("Index")); } ViewBag.GameWeekId = new SelectList(db.GameWeeks.AsNoTracking().OrderBy(x => x.Number), "GameWeekId", "Details", gameWeekService.GetCurrent()?.GameWeekId); ViewBag.PlayerId = new SelectList(db.ManagerPlayers.AsNoTracking().Include(x => x.Player).Where(x => !x.Substitute).OrderBy(x => x.Player.LastName).ThenBy(x => x.Player.FirstName), "PlayerId", "Details"); return(View(goal)); }