public void Update(UpdateGameSetting entity) { using (var transaction = _entityContext.Database.BeginTransaction()) { try { GameSettings gameSetting = _entityContext.GameSettings.FirstOrDefault(x => x.GameSettingId == entity.GameSettingId); if (gameSetting == null) { throw new NullReferenceException(); } gameSetting.GameLength = entity.GameLength; gameSetting.UpdatedAt = DateTime.UtcNow; _entityContext.Update(gameSetting); _entityContext.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } }
public void Update(UpdateGameSetting entity) { try { _gameSettingsRepository.Update(entity); } catch (MySqlException) { throw new ConnectionException(); } catch (Exception) { throw new OperationException("An error occured while updating Game Settings!"); } }
public IActionResult Edit(UpdateGameSetting entity) { if (ModelState.IsValid) { try { _gameSettingsLogic.Update(entity); return(RedirectToAction("Index")); } catch (Exception exception) { View(exception.Message); } } return(View()); }
public IActionResult Edit(int id) { try { GameSettings gameSettings = _gameSettingsLogic.GetSettingsById(id); UpdateGameSetting updateGameSetting = new UpdateGameSetting { GameSettingId = gameSettings.GameSettingId, GameLength = gameSettings.GameLength, UpdatedAt = gameSettings.UpdatedAt }; return(View("Edit", updateGameSetting)); } catch (Exception ex) { _logger.Log(LogLevel.Error, $"The following error occurred: {ex.Message} @ {GetType().Name}"); ViewBag.ErrorMessage = ex.Message; return(View("Index")); } }