public TournamentEntity ToTournamentEntity(TournametViewModel model, string path, bool isNew) { return(new TournamentEntity { EndDate = model.EndDate.ToUniversalTime(), Groups = model.Groups, Id = isNew ? 0 : model.Id, IsActive = model.IsActive, LogoPath = path, Name = model.Name, StartDate = model.StartDate.ToUniversalTime() }); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } TournamentEntity tournament = await _context.Tournaments.FindAsync(id); if (tournament == null) { return(NotFound()); } TournametViewModel model = _converter.ToTournamentViewModel(tournament); return(View(model)); }
public async Task <IActionResult> Edit(TournametViewModel model) { if (ModelState.IsValid) { string path = model.LogoPath; if (model.LogoFile != null) { path = await _image.UploadImageAsync(model.LogoFile, "Tournaments"); } TournamentEntity tournament = _converter.ToTournamentEntity(model, path, false); _context.Update(tournament); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }