public bool SaveShipmentDetails(ShipmentSettingsModel shipmentMethod) { using (var connection = new SqlConnection(Constants.ConnectorDatabase)) { var cmd = new SqlCommand { CommandText = @"if @Id<=0 Insert into ShippingMethod(CarrierId, EcommerceShippingMethod, ERPShippingMethod,[Description],IsEcommerceDefault,IsErpDefault) values(@CarrierId, @MagnetoShippingMethod, @ERPShippingMethod, @Description,@IsEcommerceDefault,@IsErpDefault) ELSE update ShippingMethod SET CarrierId=@CarrierId,IsEcommerceDefault=@IsEcommerceDefault,IsErpDefault=@IsErpDefault,Description=@Description,EcommerceShippingMethod=@MagnetoShippingMethod,ERPShippingMethod=@ERPShippingMethod where ShippingMethodId=@Id" }; cmd.Parameters.AddWithValue("@Id", shipmentMethod.ShipmentMethodId); cmd.Parameters.AddWithValue("@CarrierId", shipmentMethod.CarrierId); cmd.Parameters.AddWithValue("@MagnetoShippingMethod", shipmentMethod.MagentoShipmentId); cmd.Parameters.AddWithValue("@ERPShippingMethod", shipmentMethod.GpShipmentId); cmd.Parameters.AddWithValue("@Description", shipmentMethod.Description); cmd.Parameters.AddWithValue("@IsEcommerceDefault", shipmentMethod.IsEcommerceDefault); cmd.Parameters.AddWithValue("@IsErpDefault", shipmentMethod.IsErpDefault); cmd.Connection = connection; connection.Open(); int i = cmd.ExecuteNonQuery(); if (i <= 0) { return(false); } UpdateDefaultFlags(shipmentMethod, connection); return(true); } }
private static void UpdateErpDefaults(ShipmentSettingsModel shipmentMethod, SqlConnection connection) { const string commandText = "update ShippingMethod SET IsErpDefault=0 where EcommerceShippingMethod=@EcommerceShippingMethod AND ERPShippingMethod<>@ERPShippingMethod"; using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddWithValue("@ERPShippingMethod", shipmentMethod.GpShipmentId); command.Parameters.AddWithValue("@EcommerceShippingMethod", shipmentMethod.MagentoShipmentId); command.ExecuteNonQuery(); } }
private static void UpdateDefaultFlags(ShipmentSettingsModel shipmentMethod, SqlConnection connection) { if (shipmentMethod.IsEcommerceDefault) { UpdateEcommerceDefaults(shipmentMethod, connection); } if (shipmentMethod.IsErpDefault) { UpdateErpDefaults(shipmentMethod, connection); } }
public bool IsShippingMethodExistsInGp(ShipmentSettingsModel shippingMethod) { using (var connection = new SqlConnection(Constants.ErpDatabase)) { const string commandText = @"Select SHIPMTHD from SY03000 where SHIPMTHD=@SHIPMTHD"; using (var command = new SqlCommand(commandText, connection)) { connection.Open(); command.Parameters.AddWithValue("@SHIPMTHD", shippingMethod.GpShipmentId); using (SqlDataReader dataReader = command.ExecuteReader()) { return(dataReader.Read()); } } } }
public bool IsShippingMethodExists(ShipmentSettingsModel shipmentSettingsModel) { bool result; using (var connection = new SqlConnection(Constants.ConnectorDatabase)) { const string commandText = @"Select ShippingMethodId from ShippingMethod where EcommerceShippingMethod=@MagnetoShippingMethod AND ERPShippingMethod=@ERPShippingMethod AND ShippingMethodId<>@ShippingMethodId"; using (var command = new SqlCommand(commandText, connection)) { connection.Open(); command.Parameters.AddWithValue("@MagnetoShippingMethod", shipmentSettingsModel.MagentoShipmentId); command.Parameters.AddWithValue("@ERPShippingMethod", shipmentSettingsModel.GpShipmentId); command.Parameters.AddWithValue("@ShippingMethodId", shipmentSettingsModel.ShipmentMethodId); using (SqlDataReader dataReader = command.ExecuteReader()) { result = dataReader.Read(); } connection.Close(); } } return(result); }
private void AddNewShipmentRecord() { ShippingMethod = new ShipmentSettingsModel(); ValidationMessage = ""; ShowPopup = true; }