public async Task <IActionResult> AddContestant(List <AddContestantViewModel> model, int competitionInstanceId, int competitionId, string userId) { if (ModelState.IsValid) { foreach (var item in model) { if (item.Add) { var contestantInHeat = new ContestantInHeat { Bib = item.Bib, HeatId = item.HeatId, Modified = DateTime.Now, Team = item.Team, UserId = item.UserId }; await _heatService.AddAsyncContestantInHeat(contestantInHeat); if (item.ChipNumber > 0) { var chip = await _chipService.GetChipByNumberAsync(item.ChipNumber); if (chip == null) { await _heatService.RemoveAsyncContestantInHeat(contestantInHeat); return(Json("There exists no chip with the chip number " + item.ChipNumber)); } var chipinHeat = new ChipInHeat { ChipCode = chip.Code, HeatId = item.HeatId, UserId = item.UserId, Valid = true }; try { await _chipService.AssignChipToUserInHeatAsync(chipinHeat); } catch (Exception e) { await _heatService.RemoveAsyncContestantInHeat(contestantInHeat); return(Json(e.Message)); } } } } return(RedirectToAction("Contestants", "CompetitionInstance", new { @competitionId = competitionId, @competitionInstanceId = competitionInstanceId })); } var user = await _adminService.GetUserByIdAsync(userId); ViewBag.UserName = user.FirstName + " " + user.MiddleName + " " + user.LastName; return(View(model)); }
public async Task <IActionResult> AddContestant(AddContestantToHeatViewModel model, int heatId, int eventId, int competitionId, int competitionInstanceId, string userId) { if (!ModelState.IsValid) { var user = await _adminService.GetUserByIdAsync(userId); ViewBag.UserName = user.FirstName + " " + user.LastName; var heat = await _heatService.GetHeatByIdAsync(heatId); ViewBag.HeatId = heat.HeatNumber; return(View(model)); } var entity = new ContestantInHeat { Bib = model.Bib, HeatId = heatId, Modified = DateTime.Now, Team = model.Team, UserId = model.UserId }; await _heatService.AddAsyncContestantInHeat(entity); if (model.ChipNumber > 0) { var chip = await _chipService.GetChipByNumberAsync(model.ChipNumber); if (chip == null) { await _heatService.RemoveAsyncContestantInHeat(entity); return(Json("There exists no chip with the chip number " + model.ChipNumber)); } var chipinHeat = new ChipInHeat { ChipCode = chip.Code, HeatId = heatId, UserId = model.UserId, Valid = true }; try { await _chipService.AssignChipToUserInHeatAsync(chipinHeat); } catch (Exception e) { await _heatService.RemoveAsyncContestantInHeat(entity); return(Json(e.Message)); } } return(RedirectToAction("Heat", "Admin", new { heatId, eventId, competitionId, competitionInstanceId })); }
public async Task <IActionResult> RegisterToEvent(RegisterToEventDto model, string userId, int eventId) { if (ModelState.IsValid) { var heatsInEvent = _heatService.GetHeatsForEvent(model.Event.Id); var heatId = (from x in heatsInEvent where x.HeatNumber == 0 select x.Id).SingleOrDefault(); var contestantInHeat = new ContestantInHeat { HeatId = heatId, UserId = model.UserId, Modified = DateTime.Now }; await _heatService.AddAsyncContestantInHeat(contestantInHeat); return(RedirectToAction("Events", "User", new { @competitionInstanceId = model.Instance.Id })); } return(View(model)); }