public ActionResult EditCompetitor(CompetitorVM competitorVM) { if (ModelState.IsValid) { var temporaryCompetitionEventsList = new List <CompetitorEvents>(); var temporaryCompetitorEventsList = new List <CompetitorEvents>(); temporaryCompetitionEventsList = _competitorEventsRepository.GetWhere(x => x.CompetitionID == competitorVM.CompetitionID).ToList(); temporaryCompetitorEventsList = temporaryCompetitionEventsList.Where(x => x.CompetitiorID == competitorVM.Competitor.ID).ToList(); foreach (var item in competitorVM.SelectedEventsList) { if (temporaryCompetitorEventsList.Find(x => x.EventID == int.Parse(item)) == null) { var competitorEvents = new CompetitorEvents(); competitorEvents.CompetitiorID = competitorVM.Competitor.ID; competitorEvents.EventID = int.Parse(item); competitorEvents.CompetitionID = competitorVM.CompetitionID; _competitorEventsRepository.Create(competitorEvents); } else { var competitorEvents = temporaryCompetitorEventsList.Find(x => x.EventID == int.Parse(item)); _competitorEventsRepository.Delete(competitorEvents); } } _competitorRepository.Update(competitorVM.Competitor); return(RedirectToAction("Registered", new { id = competitorVM.CompetitionID })); } return(View(competitorVM)); }
public ActionResult Register(CompetitorVM viewModel) { if (ModelState.IsValid) { viewModel.Competitor.IsConfirmed = false; _competitorRepository.Create(viewModel.Competitor); foreach (var item in viewModel.SelectedEventsList) { var competitorEvents = new CompetitorEvents(); competitorEvents.CompetitiorID = viewModel.Competitor.ID; competitorEvents.EventID = int.Parse(item); competitorEvents.CompetitionID = viewModel.CompetitionID; _competitorEventsRepository.Create(competitorEvents); } } return(RedirectToAction("RegisterConfirm")); }