public async Task <ActionResult> Create3(MatchEditorViewModel viewModel, string Command) { if (!ModelState.IsValid) { return(View(viewModel)); } if (Command == "Previous") { TempData["Create2"] = viewModel; return(RedirectToAction("Create2")); } if (Command == "Save") { var competitionV = await DbProvider.GetCompetition((Guid)viewModel.CompetitionGuid, viewModel.ViewDate); var campaignGuid = competitionV.Competition.Campaigns.Single(c => c.StartDate <= viewModel.MatchDate && c.EndDate > viewModel.MatchDate).PrimaryKey; var newMatchV = viewModel.ToMatchV(UserId, UserId, campaignGuid); var newMatch = new Match() { PrimaryKey = viewModel.HeaderKey }; DbProvider.Add(newMatch); DbProvider.Add(newMatchV); DbProvider.SaveChanges(); return(RedirectToDetailsIndex(newMatch.PrimaryKey)); } return(View(viewModel)); }
public ActionResult Create() { if (TempData["Create"] != null) { return(View((MatchEditorViewModel)TempData["Create"])); } return(View(MatchEditorViewModel.CreateNew <MatchEditorViewModel>())); }
public static void ToMatchEditorViewModel(this MatchV entity, MatchEditorViewModel viewModel) { viewModel.MatchDate = viewModel.VersionEntity.MatchDate.AddTicks((long)viewModel.VersionEntity.MatchTimeTicks); viewModel.CompetitionGuid = viewModel.VersionEntity.CampaignStage.Campaign.CompetitionKey; viewModel.VenueGuid = viewModel.VersionEntity.VenueGuid; viewModel.Attendance = viewModel.VersionEntity.Attendance; viewModel.Team1Guid = viewModel.VersionEntity.Team1Guid; viewModel.Team1Ht = viewModel.VersionEntity.Team1HT; viewModel.Team1Ft = viewModel.VersionEntity.Team1FT; viewModel.Team2Guid = viewModel.VersionEntity.Team2Guid; viewModel.Team2Ht = viewModel.VersionEntity.Team2HT; viewModel.Team2Ft = viewModel.VersionEntity.Team2FT; }
public ActionResult Create(MatchEditorViewModel viewModel, string Command) { if (!ModelState.IsValid) { return(View(viewModel)); } if (Command == "Next") { TempData["Create2"] = viewModel; return(RedirectToAction("Create2")); } return(RedirectToAction("Create")); }
public static void SetData(this MatchV entityV, MatchEditorViewModel viewModel) { entityV.MatchImportType = entityV.GetMatchImportType(false); entityV.MatchDate = viewModel.MatchDate.Date; entityV.MatchTimeTicks = (viewModel.MatchDate - viewModel.MatchDate.Date).Ticks; entityV.CampaignStageKey = viewModel.CampaignStageViewModel.Entity.PrimaryKey; entityV.VenueGuid = viewModel.VenueGuid; entityV.Attendance = viewModel.Attendance; entityV.Team1Guid = viewModel.Team1Guid; entityV.Team1HT = viewModel.Team1Ht; entityV.Team1FT = viewModel.Team1Ft; entityV.Team2Guid = viewModel.Team2Guid; entityV.Team2HT = viewModel.Team2Ht; entityV.Team2FT = viewModel.Team2Ft; }
public async Task <ActionResult> Edit(MatchEditorViewModel viewModel, string Command) { await SetModelsByPrimaryKey(viewModel); if (!ModelState.IsValid) { return(View(viewModel)); } if (Command == "Next") { TempData["MatchEditorViewModel"] = viewModel; return(RedirectToAction("Edit2")); } return(RedirectToAction("Edit")); }
public async Task <ActionResult> Edit2(MatchEditorViewModel viewModel, string Command) { await SetModelsByPrimaryKey(viewModel); if (!ModelState.IsValid) { return(View(viewModel)); } if (Command == "Previous") { TempData["MatchEditorViewModel"] = viewModel; return(RedirectToAction("Edit", new { id = viewModel.ShortHeaderKey, dt = viewModel.ViewDate.ToUrlString() })); } if (Command == "Next") { TempData["MatchEditorViewModel"] = viewModel; return(RedirectToAction("Edit3")); } return(RedirectToAction("Edit3")); }
public async Task <ActionResult> Edit3(MatchEditorViewModel viewModel, string Command) { await SetModelsByPrimaryKey(viewModel); if (!ModelState.IsValid) { return(View(viewModel)); } if (Command == "Previous") { TempData["MatchEditorViewModel"] = viewModel; return(RedirectToAction("Edit2")); } if (Command == "Save") { viewModel.MatchViewModels = viewModel.HeaderEntity.Versions.OrderByDescending(v => v.EffectiveFrom).ThenByDescending(v => v.IsActive).ToViewModels(DateTime.Now); var competitionV = await DbProvider.GetCompetition((Guid)viewModel.CompetitionGuid, viewModel.ViewDate); var campaignGuid = competitionV.Competition.Campaigns.Single(c => c.StartDate <= viewModel.MatchDate && c.EndDate > viewModel.MatchDate).PrimaryKey; var query = viewModel.HeaderEntity.GetApprovedVersionsByEffectiveDate <Match, MatchV>(Date.LowDate); if (query.Any()) { var entityV = query.Single(); if (viewModel.Equals(entityV)) { ModelState.AddModelError(string.Empty, "No changes have been made."); return(View(viewModel)); } if (entityV.ModifiedUserId == UserId) { entityV.SetData(viewModel); entityV.DateModified = DateTime.Now; DbProvider.SaveChanges(); return(RedirectToEditor("Home", entityV)); } else { entityV.IsActive = false; var newEntityV = viewModel.ToMatchV(entityV.OwnerUserId, UserId, campaignGuid); DbProvider.Add(newEntityV); foreach (var matchEvent in entityV.MatchEvents) { var newMatchEvent = new MatchEvent() { PrimaryKey = Guid.NewGuid(), MatchVPrimaryKey = newEntityV.PrimaryKey, TeamPrimaryKey = matchEvent.TeamPrimaryKey, PersonPrimaryKey = matchEvent.PersonPrimaryKey, PositionType = matchEvent.PositionType, MatchEventType = matchEvent.MatchEventType, Minute = matchEvent.Minute, Extra = matchEvent.Extra }; DbProvider.Add(newMatchEvent); } DbProvider.SaveChanges(); return(RedirectToEditor("Home", newEntityV)); } } } return(View(viewModel)); }