public async Task <string> UpdateAsync(TournamentViewModels.Edit viewModel) { Tournament tournamentUpdated; if (viewModel.Id is not null) { tournamentUpdated = await toornamentService.UpdateTournament(viewModel.Id, new Queries.Tournament.Update(viewModel)); var tournament = await GetBy(tournamentUpdated.Id); tournament.Update(tournamentUpdated); context.Tournaments.Update(tournament); } else { tournamentUpdated = await toornamentService.CreateTournament(new Queries.Tournament.Create(viewModel)); await context.Tournaments.AddAsync(tournamentUpdated); } await context.SaveChangesAsync(); return(tournamentUpdated.Id); }
public async Task <IActionResult> Edit(string id, TournamentViewModels.Edit viewModel) { if (id is not null && id != viewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { if (viewModel.ParticipantType == "single") { viewModel.TeamMinSize = null; viewModel.TeamMaxSize = null; } if (!viewModel.RegistrationEnabled) { viewModel.RegistrationOpeningDatetime = null; viewModel.RegistrationClosingDatetime = null; } if (!viewModel.CheckInParticipantEnabled) { viewModel.CheckInParticipantStartDatetime = null; viewModel.CheckInParticipantEndDatetime = null; } try { id = await tournamentRepository.UpdateAsync(viewModel); await tournamentRepository.SaveChangesAsync(); } catch (BadHttpRequestException e) { TempData["refreshMessage"] = $"{e.Message}, Status Code: {e.StatusCode}"; } return(RedirectToAction(nameof(Details), new { id })); } if (!ModelState.IsValid && viewModel.Id is null) { ViewData["isEdit"] = false; } ViewData["platforms"] = GetPlatformsAsMultiSelectList(); ViewData["participantTypes"] = GetParticipantTypesAsSelectList(); ViewData["timezones"] = GetTimezonesAsSelectList(); ViewData["games"] = GetGamesAsSelectList(viewModel.Discipline); return(View(viewModel)); }
public Create(TournamentViewModels.Edit viewModel) { Name = viewModel.Name ?? throw new ArgumentNullException(nameof(viewModel.Name)); Timezone = viewModel.Timezone ?? throw new ArgumentNullException(nameof(viewModel.Timezone)); Size = viewModel.Size; Discipline = viewModel.Discipline ?? throw new ArgumentNullException(nameof(viewModel.Discipline)); ParticipantType = viewModel.ParticipantType ?? throw new ArgumentNullException(nameof(viewModel.ParticipantType)); Platforms = viewModel.Platforms ?? throw new ArgumentNullException(nameof(viewModel.Platforms)); FullName = viewModel.FullName; ScheduledDateStart = viewModel.ScheduledDateStart?.ToString("yyyy-MM-dd"); ScheduledDateEnd = viewModel.ScheduledDateEnd?.ToString("yyyy-MM-dd"); Public = viewModel.Public; Online = viewModel.Online; Location = viewModel.Location; Country = viewModel.Country; Logo = viewModel.Logo is null ? null : new Logo() { LogoLarge = viewModel.Logo.LogoLarge, LogoMedium = viewModel.Logo.LogoMedium, LogoSmall = viewModel.Logo.LogoSmall, Original = viewModel.Logo.Original }; RegistrationEnabled = viewModel.RegistrationEnabled; RegistrationOpeningDatetime = viewModel.RegistrationOpeningDatetime; RegistrationClosingDatetime = viewModel.RegistrationClosingDatetime; Organization = viewModel.Organization; Contact = viewModel.Contact; Discord = viewModel.Discord; Website = viewModel.Website; Description = viewModel.Description; Rules = viewModel.Rules; Prize = viewModel.Prize; MatchReportEnabled = viewModel.MatchReportEnabled; RegistrationRequestMessage = viewModel.RegistrationRequestMessage; CheckInEnabled = viewModel.CheckInEnabled; CheckInParticipantEnabled = viewModel.CheckInParticipantEnabled; CheckInParticipantStartDatetime = viewModel.CheckInParticipantStartDatetime; CheckInParticipantEndDatetime = viewModel.CheckInParticipantEndDatetime; Archived = viewModel.Archived; RegistrationAcceptanceMessage = viewModel.RegistrationAcceptanceMessage; RegistrationRefusalMessage = viewModel.RegistrationRefusalMessage; RegistrationTermsEnabled = viewModel.RegistrationTermsEnabled; RegistrationTermsUrl = viewModel.RegistrationTermsUrl; TeamMinSize = viewModel.TeamMinSize; TeamMaxSize = viewModel.TeamMaxSize; }
public Update(TournamentViewModels.Edit viewModel) { Name = viewModel.Name; Timezone = viewModel.Timezone; Size = viewModel.Size; FullName = viewModel.FullName; ScheduledDateStart = viewModel.ScheduledDateStart?.ToString("yyyy-MM-dd"); ScheduledDateEnd = viewModel.ScheduledDateEnd?.ToString("yyyy-MM-dd"); Public = viewModel.Public; Online = viewModel.Online; Location = viewModel.Location; Country = viewModel.Country; Logo = viewModel.Logo is null ? null : new Logo() { LogoLarge = viewModel.Logo.LogoLarge, LogoMedium = viewModel.Logo.LogoMedium, LogoSmall = viewModel.Logo.LogoSmall, Original = viewModel.Logo.Original }; RegistrationEnabled = viewModel.RegistrationEnabled; RegistrationOpeningDatetime = viewModel.RegistrationOpeningDatetime?.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo); RegistrationClosingDatetime = viewModel.RegistrationClosingDatetime?.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo); Organization = viewModel.Organization; Contact = viewModel.Contact; Discord = viewModel.Discord; Website = viewModel.Website; Description = viewModel.Description; Rules = viewModel.Rules; Prize = viewModel.Prize; MatchReportEnabled = viewModel.MatchReportEnabled; RegistrationRequestMessage = viewModel.RegistrationRequestMessage; CheckInEnabled = viewModel.CheckInEnabled; CheckInParticipantEnabled = viewModel.CheckInParticipantEnabled; CheckInParticipantStartDatetime = viewModel.CheckInParticipantStartDatetime?.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo); CheckInParticipantEndDatetime = viewModel.CheckInParticipantEndDatetime?.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo); Archived = viewModel.Archived; RegistrationAcceptanceMessage = viewModel.RegistrationAcceptanceMessage; RegistrationRefusalMessage = viewModel.RegistrationRefusalMessage; RegistrationTermsEnabled = viewModel.RegistrationTermsEnabled; RegistrationTermsUrl = viewModel.RegistrationTermsUrl; TeamMinSize = viewModel.TeamMinSize; TeamMaxSize = viewModel.TeamMaxSize; }