public async Task <IActionResult> Edit(int id, JudgeScoreViewModel teamScoreViewModel) { var allowEditing = await IsScoreEditEnabled(); if (!allowEditing) { return(View("Error", new ErrorViewModel { ErrorCode = "Score Edit Disabled", Message = "Possibly all judges already concluded their scores." })); } if (id != teamScoreViewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var teamScore = _context.JudgeScores.Find(id); var entity = _context.Attach(teamScore); entity.Entity.Id = id; entity.Entity.InnovationScore = teamScoreViewModel.InnovationScore.Value; entity.Entity.UsefulnessScore = teamScoreViewModel.UsefulnessScore.Value; entity.Entity.CompanyValueScore = teamScoreViewModel.CompanyValueScore.Value; entity.Entity.PresentationScore = teamScoreViewModel.PresentationScore.Value; entity.Entity.QualityScore = teamScoreViewModel.QualityScore.Value; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ScoreExists(teamScoreViewModel.Id)) { return(NotFound()); } throw; } return(RedirectToAction(nameof(Index))); } return(View(teamScoreViewModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Value")] Settings settings) { if (id != settings.Id) { return(NotFound()); } if (ModelState.IsValid) { try { settings.LastUpdated = DateTime.Now; settings.UpdatedBy = User.FindFirst(ClaimTypes.NameIdentifier).Value; var entry = _context.Attach(settings); entry.Property(x => x.Name).IsModified = true; entry.Property(x => x.Value).IsModified = true; entry.Property(x => x.LastUpdated).IsModified = true; entry.Property(x => x.UpdatedBy).IsModified = true; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SettingsExists(settings.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(settings)); }
public async Task <IActionResult> Edit(string teamCode, [Bind("Id,TeamCode,TeamName,Avatar,Theme,ProblemStatement,ITRequirements,RepoUrl,Location,OtherRequirements,Participants")] TeamViewModel teamViewModel) { if (teamCode != teamViewModel.TeamCode) { return(NotFound()); } if (ModelState.IsValid) { if (!ParticipantsEnteredCorrectly(teamViewModel.Participants)) { ViewData["locations"] = FetchEventLocationSelectItemList(); return(View(teamViewModel)); } //Raw participants in text are good to deserialize var participantsDtos = TeamViewModel.DeserializeParticipants(teamViewModel.Participants); var team = new Team(teamViewModel, participantsDtos); var oldParticipants = _context.Participants.Where(x => x.Team.Id == team.Id); _context.Participants.RemoveRange(oldParticipants); try { _context.Attach(team); _context.Entry(team).Property(p => p.TeamName).IsModified = true; _context.Entry(team).Property(p => p.ProblemStatement).IsModified = true; _context.Entry(team).Property(p => p.Theme).IsModified = true; _context.Entry(team).Collection(p => p.Participants).IsModified = true; _context.Entry(team).Property(p => p.ITRequirements).IsModified = true; _context.Entry(team).Property(p => p.OtherRequirements).IsModified = true; _context.Entry(team).Property(p => p.RepoUrl).IsModified = true; _context.Entry(team).Property(p => p.Location).IsModified = true; //Only flag as modified if user uploads something if (team?.Avatar?.Length > 0) { _context.Entry(team).Property(p => p.Avatar).IsModified = true; } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeamViewModelExists(teamViewModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["locations"] = FetchEventLocationSelectItemList(); return(View(teamViewModel)); }