public async Task <IWriterResult> UpdatePrizePool(UpdatePrizePoolModel model) { var game = await GameReader.GetGame(model.GameId); using (var context = DataContextFactory.CreateContext()) { var existingPrizes = await context.Prize .Where(x => x.GameId == game.Id) .ToListAsync(); if (!model.Name.Equals(model.NewName, StringComparison.OrdinalIgnoreCase)) { if (existingPrizes.Any(x => x.Name.Equals(model.NewName, StringComparison.OrdinalIgnoreCase))) { return(new WriterResult(false, "Prize pool name already exists")); } } foreach (var existingPrize in existingPrizes.Where(x => x.Name == model.Name)) { existingPrize.Name = model.NewName; existingPrize.Description = model.Description; } await context.SaveChangesAsync(); return(new WriterResult(true, "Successfully updated prizes")); } }
public async Task <ActionResult> UpdatePrizePoolModal(UpdatePrizePoolModel model) { if (!ModelState.IsValid) { return(View(model)); } var result = await PrizeWriter.UpdatePrizePool(model); if (!ModelState.IsWriterResultValid(result)) { return(View(model)); } return(CloseModalSuccess()); }