private void UpdateSuburb(int SuburbId, string Suburbname) { try { using (var Suburbs = new SuburbBusiness()) { var entity = new SuburbEntity(); entity.SuburbId = SuburbId; entity.SuburbName = Suburbname; var opSuccessful = Suburbs.UpdateSuburb(entity); } } catch (Exception ex) { //Log exception error _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true); } }
public bool UpdateSuburb(SuburbEntity entity) { try { bool bOpDoneSuccessfully; using (var repository = new SuburbRepository()) { bOpDoneSuccessfully = repository.Update(entity); } return(bOpDoneSuccessfully); } catch (Exception ex) { //Log exception error _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true); throw new Exception("BusinessLogic:SuburbBusiness::UpdateSuburb::Error occured.", ex); } }
public ActionResult Create(SuburbEntity obj) { if (!ModelState.IsValid) { return(View()); } try { InsertSuburb(obj.StateId, obj.SuburbName ); return(RedirectToAction("ListAll")); } catch (Exception ex) { //Log exception error _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true); ViewBag.Message = Server.HtmlEncode(ex.Message); return(View("Error")); } }
public IEnumerable <SuburbEntity> SelectSuburbById(int id) { _errorCode = 0; _rowsAffected = 0; var returnedEntities = new List <SuburbEntity>(); try { var sb = new StringBuilder(); sb.Append("SELECT "); sb.Append("[SuburbId], "); sb.Append("[SuburbName],"); sb.Append("st.[StateId],"); sb.Append("[StateName] "); sb.Append("FROM [dbo].[Suburb] sb , [dbo].[State] st "); sb.Append("WHERE sb.StateId =st.StateId and "); sb.Append("st.[StateId] = @StateId "); sb.Append("SELECT @intErrorCode=@@ERROR; "); var commandText = sb.ToString(); sb.Clear(); using (var dbConnection = _dbProviderFactory.CreateConnection()) { if (dbConnection == null) { throw new ArgumentNullException("dbConnection", "The db connection can't be null."); } dbConnection.ConnectionString = _connectionString; using (var dbCommand = _dbProviderFactory.CreateCommand()) { if (dbCommand == null) { throw new ArgumentNullException("dbCommand" + " The db SelectSuburbById command for entity [Suburb] can't be null. "); } dbCommand.Connection = dbConnection; dbCommand.CommandText = commandText; //Input Parameters _dataHandler.AddParameterToCommand(dbCommand, "@StateId", CsType.Int, ParameterDirection.Input, id); //Output Parameters _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null); //Open Connection if (dbConnection.State != ConnectionState.Open) { dbConnection.Open(); } //Execute query. using (var reader = dbCommand.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { var entity = new SuburbEntity(); entity.SuburbId = reader.GetInt32(0); entity.SuburbName = reader.GetString(1); entity.StateId = reader.GetInt32(2); entity.StateName = reader.GetString(3); returnedEntities.Add(entity); break; } } } _errorCode = int.Parse(dbCommand.Parameters["@intErrorCode"].Value.ToString()); if (_errorCode != 0) { // Throw error. throw new Exception("The SelectSuburbById method for entity [Suburb] reported the Database ErrorCode: " + _errorCode); } } } return(returnedEntities); } catch (Exception ex) { //Log exception error _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true); //Bubble error to caller and encapsulate Exception object throw new Exception("AddressRepository::SelectSuburbById::Error occured.", ex); } }