public int?CreateCompanyConsignee(CompanyConsigneeBindingModel companyConsigneeModel) { int?createdConsigneeId = null; var CompanyCosignee = new CompanyConsignee(); using (var sqlConnection = new SqlConnection(_DBConnectionString)) { try { //TODO replace with stored procedures sqlConnection.Open(); createdConsigneeId = sqlConnection.ExecuteScalar <int>( @"INSERT INTO CompanyConsignee (CompanyName,CompanyTRN,CompanyAddress,CompanyEmail,CompanyPhoneNumber) OUTPUT Inserted.Id Values (@CompanyName,@CompanyTRN,@CompanyAddress,@CompanyEmail,@CompanyPhone)", new { CompanyName = companyConsigneeModel.CompanyName, CompanyTRN = companyConsigneeModel.CompanyTRN, CompanyAddress = companyConsigneeModel.CompanyAddress, CompanyEmail = companyConsigneeModel.CompanyEmail, CompanyPhone = CompanyCosignee.CompanyPhone, }, commandType: CommandType.Text, commandTimeout: 60); } catch (Exception ex) { _logger.Error(ex, "Error creating company consignee."); //TODO - Rethrow exception here //ex.ToString(); //log exceptions here } } return(createdConsigneeId); }
public int CreateCompanyConsignee(CompanyConsigneeBindingModel companyConsigneeModel) { int?createdConsigneeId = null; var companyCosignee = new CompanyConsignee(); companyCosignee.CompanyName = companyConsigneeModel.CompanyName; companyCosignee.CompanyTRN = companyConsigneeModel.CompanyTRN; companyCosignee.CompanyAddress = companyConsigneeModel.CompanyAddress; companyCosignee.CompanyEmail = companyConsigneeModel.CompanyEmail; companyCosignee.CompanyPhone = companyCosignee.CompanyPhone; companyCosignee.CustomerCode = companyCosignee.CustomerCode; using (var sqlConnection = new SqlConnection(_DBConnectionString)) { try { sqlConnection.Open(); createdConsigneeId = sqlConnection.ExecuteScalar <int>( @"INSERT INTO CompanyConsignee (CompanyName,CompanyTRN,CompanyAddress,CompanyEmail,CompanyPhoneNumber,CustomerCode) OUTPUT Inserted.Id Values (@companyConsignee)", companyCosignee, commandType: CommandType.Text, commandTimeout: 60); } catch (Exception ex) { ex.ToString(); //log exceptions here } } return(createdConsigneeId.Value); }
public CompanyConsignee GetCompanyConsignee(string companyTRN) { CompanyConsignee companyConsignee = null; try { using (var SqlConnection = new SqlConnection(_DBConnectionString)) { //select the unique company companyConsignee = SqlConnection.Query <CompanyConsignee>("SELECT * FROM CompanyConsignee WHERE CompanyTRN = @Company_TRN", new { @Company_TRN = companyTRN }, commandType: CommandType.Text, commandTimeout: 60).FirstOrDefault(); } } catch (Exception ex) { //NLOG //EXCEPTION LOGGING var ext = ex.ToString(); } return(companyConsignee); }