public bool UpdateHousehold(UpdateHousehold request) { NpgsqlConnection connection = new NpgsqlConnection(_connectionString); connection.Open(); try { var rowUpdated = false; NpgsqlCommand command = new NpgsqlCommand("UPDATE public.\"House\" " + $"SET \"Name\"='{request.Name}' " + $"WHERE \"Id\" = {request.Id} " + "RETURNING \"Id\"", connection); NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { rowUpdated = true; } reader.Close(); return(rowUpdated); } catch (System.Exception exception) { throw new System.Exception($"An Error occured while updating the household '{request.Name}'", exception); } finally { connection.Close(); } }
public CommunicationResponse UpdateHousehold([FromBody] UpdateHouseholdRequest request) { var response = new AddHouseholdResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } UpdateHousehold updateHousehold = new UpdateHousehold { Id = request.Id, Name = request.Name }; bool rowUpdated = _houseRepository.UpdateHousehold(updateHousehold); if (rowUpdated == false) { response.AddError("The given House Id does not correspond to an existing Household"); return(response); } } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}"); } return(response); }