pass to the SSRS report multiple integer values - c#

I try to pass to a SSRS report, from the C# code multiple arrays of integer
var rsExec = new ReportExecutionServiceSoapClient(binding, new EndpointAddress(config.ReportExecutionUrl));
ParameterValue[] reportParam = new ParameterValue[] {
new ParameterValue { Name = "pCityId", Value = cityId.ToString() },
new ParameterValue { Name = "pDepartmentIds", Value = string.Join(",", departmentIds) },
new ParameterValue { Name = "pBuildingIds", Value = string.Join(",", buidingIds) }
};
await rsExec.SetExecutionParametersAsync(null, null, reportParam, "en-us");
as the Value type of ParameterValue is "string", it seems I have no choice but passing a CSV as parameter to the report.
Then, in the report I can use data type as integer, and say that I am passing "multiple values", but how to do it from the C# code?
PS. Related to that question

To send parameters where the Allow multiple values option is selected, you need to send a new ParameterValue object for each value that is going to be consumed by the report, all with the same Name.
In the case described above, you need to send a ParameterValue for each value in the departmentIds collection, all with the same parameter name ("pDepartmentIds").
So, if there was 3 department IDs to send, the reportParam array should contain 3 ParameterValue objects, all with the name "pDepartmentIds", one for each department ID.
ParameterValue[] reportParam = new ParameterValue[] {
new ParameterValue { Name = "pCityId", Value = cityId.ToString() },
new ParameterValue { Name = "pDepartmentIds", Value = "1" },
new ParameterValue { Name = "pDepartmentIds", Value = "2" },
new ParameterValue { Name = "pDepartmentIds", Value = "3" },
...
};
Do something similar for buildingIds.

Related

Stripe-Metadata not in response (WebHook/.net-core)

I am using stripe for payments.
When I create the SessionCreateOptions object I add the CustomerId and ProductId for later usage in my Webhook.
var options = new SessionCreateOptions
{
PaymentMethodTypes = new List<string> {
"card",
},
CustomerEmail = buyer.Email,
LineItems = new List<SessionLineItemOptions> {
new SessionLineItemOptions {
Name = packages.First().Name,
Description = packages.First().Description,
Amount = (long)(totalAmount * 100),
Currency = "eur",
Quantity = 1,
},
},
SuccessUrl = appSettings.RedirectHost.Url + "/Checkouts/Show/success?session_id={CHECKOUT_SESSION_ID}",
CancelUrl = appSettings.RedirectHost.Url + "/Checkouts/Show/failed",
Metadata = new Dictionary<String, String>()
{
{ "CustomerId", buyer.Id.ToString()},
{ "ProductId", packages.First().Id.ToString()}
},
};
After a successful payment the webhook gets called and retrieves to object with customer data, price and other values, but the metadata dictionary is empty.
You are retrieving the PaymentIntent that was created by the CheckoutSession, but you're setting the metadata on the CheckoutSession itself.
There are two options, depending on where you want to store and retrieve the metadata. You can retrieve the CheckoutSession directly [0], or you change your code to set the metadata on the PaymentIntent when creating the CheckoutSession, via payment_intent_data.metadata [1].
[0] https://stripe.com/docs/api/checkout/sessions/retrieve
[1] https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata

Using C# Moq testing getting Parameter count mismatch?

I know there are similar questions but somehow I am not able to figure out the situation in my case. I am getting Paramater count mismatch exception.
Here is how I am registering my Mock,
var couponService =
DependencyResolver.Resolve<Mock<ICouponWebServiceAdapter>>();
couponService.Setup(a =>
a.checkCouponAvailability(It.IsAny<orderLine[]>(),
It.IsAny<orderHeader>()))
.Returns((couponDetail[] request) =>
{
var coupon = new couponDetail
{
description = "75% off the original price",
value = 50
};
var coupon1 = new couponDetail
{
description = "500 off the original price",
value = 20
};
var coupondetails = new couponDetail[] { coupon, coupon1 };
return coupondetails;
});
the checkCouponAvailability is returning couponDetail[]
What am I doing wrong? I tried putting my return as IQueryable
It appears that inside of the Returns method you are specifying a parameter called request of type couponDetail[], yet the method itself takes the parameters of (orderLine[], orderHeader). The method that is passed into Returns gets invoked with the actual parameters that are passed into your mocked method which will cause the ParameterCountMismatchException you are getting.
You can pass in the literal object you want by mocking your return before mocking the function. Example below:
var coupondetails = new couponDetail[] {
new couponDetail
{
description = "75% off the original price",
value = 50
},
new couponDetail
{
description = "500 off the original price",
value = 20
}
};
var couponService = DependencyResolver.Resolve<Mock<ICouponWebServiceAdapter>>();
couponService
.Setup(a => a.checkCouponAvailability(It.IsAny<orderLine[]>(), It.IsAny<orderHeader>()))
.Returns(coupondetails);
You can pass a method to returns which MUST take all of the arguments passed into the original method. Example below:
var couponService = DependencyResolver.Resolve<Mock<ICouponWebServiceAdapter>>();
couponService
.Setup(a => a.checkCouponAvailability(It.IsAny<orderLine[]>(), It.IsAny<orderHeader>()))
.Returns((orderLine[] arg1, orderHeader arg2) => {
return new couponDetail[] {
new couponDetail
{
description = "75% off the original price",
value = 50
},
new couponDetail
{
description = "500 off the original price",
value = 20
}
};
});

Creating Sort and Partition Keys on DynamoDb

Getting this error when creating a table:
"One or more parameter values were invalid:
Number of attributes in KeySchema does not
exactly match number of attributes defined in AttributeDefinitions"
I followed the example here
I have my keyed attributes in both sections. The only thing I am wondering about is that my keyed attribute types are strings, not numbers. I was not able to find an answer one way or the other on that one.
My implementation
private static void CreateTableMember()
{
string tableName = "Member";
var response = client.CreateTable(new CreateTableRequest
{
TableName = tableName,
AttributeDefinitions = new List<AttributeDefinition>()
{
new AttributeDefinition
{
AttributeName = "MasterCustomerId",
AttributeType = "S"
},
new AttributeDefinition
{
AttributeName = "LastName",
AttributeType = "S"
},
new AttributeDefinition
{
AttributeName = "DistrictId",
AttributeType = "S"
},
new AttributeDefinition
{
AttributeName = "EmailAddress",
AttributeType = "S"
},
new AttributeDefinition
{
AttributeName = "FirstName",
AttributeType = "S"
}
},
KeySchema = new List<KeySchemaElement>()
{
new KeySchemaElement
{
AttributeName = "MasterCustomerId",
KeyType = "HASH" // Partition Key
},
new KeySchemaElement
{
AttributeName = "LastName",
KeyType = "RANGE" //Sort key
}
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 10,
WriteCapacityUnits = 5
}
});
WaitTillTableCreated(client, tableName, response);
}
You do not need to specify non-key attributes when creating a DynamoDB table. DynamoDB does not have a fixed schema. Instead, each data item may have a different number of attributes (aside from the mandatory key attributes).
Removing the non-keyed attributes fixed the issue

JsonConvert.SerializeObject adds default Result name

Whenever i am trying to Serialize the Object with JsonConvert.SerializeObject it adds a default array name as "d"
json = JsonConvert.SerializeObject(new
{
resultsets = new List<Result>()
{
new Result { id = 1, value = "ABC", info = "ABC" },
new Result { id = 2, value = "JKL", info = "JKL" },
new Result { id = 3, value = "GSG", info = "DYU" }
}
});
return json;
The Json responce is
{
"d": "{"resultsets":[{"id":1,"value":"ABC","info":"ABC"},{"id":2,"value":"JKL","info":"JKL"},{"id":3,"value":"GSG","info":"DYU"}]}"
}
where extra array added with name "d"
i want simple array as follow
{"resultsets":[{"id":1,"value":"ABC","info":"ABC"},{"id":2,"value":"JKL","info":"JKL"},{"id":3,"value":"GSG","info":"DYU"}]}
This is to prevent direct script execution:
Suppose you were returning a plain array. The following is not a valid JS-statement:
{"d": [1]}
whereas this is:
[1]
You can find more information here:
http://encosia.com/a-breaking-change-between-versions-of-aspnet-ajax/#comment-34045

SqlException because Subquery returned more than 1 value

I have the following LINQ query that I am using to construct a structure to stuff into a JavaScript grid library which is irrelevant for this example, but I figured I would still explain that.
var output = myObjects.Select(
p => new RowModel
{
ID = p.LeadUID,
Cells =
new CellCollection(fields,
p.myDataDatas.Where(q => q.myField.ParentUID == null).Select(
q => new CellModel
{
Value = q.Value,
Name = q.myField.Description,
Display = q.myField.Description
}).ToList()
,
new CellModel
{
Name = "Campaign",
Display = "Campaign",
Value = p.Campaign.Name
}
,
new CellModel
{
Name = "CampaignEnabled",
Display = "CampaignEnabled",
Value = p.Campaign.IsActive.ToString()
},
new CellModel
{
Name = "Date Received",
Display = "Date Received",
Value = p.DateAdded.ToString()
}
,
new CellModel
{
Name = "Is Valid",
Display = "Is Valid",
Value = BooleanMap[p.IsValid]
}
,
new CellModel
{
Name = "Invalid Reason",
Display = "Invalid Reason",
Value = p.InvalidReason
}
,
new CellModel
{
Name = "Is Returned",
Display = "Is Returned",
Value = BooleanMap[p.IsReturned]
}
,
new CellModel
{
Name = "Return Reason",
Display = "Return Reason",
Value =
context.MYReturns.SingleOrDefault(
l => l.LeadUID == p.MyUID).ReturnReason
}
,
new CellModel
{
Name = "Workflow",
Display = "Workflow",
Value =
context.Stages.SingleOrDefault(
s => s.LifecycleStageUID == p.LifecycleStageUID).
Name
}
,
new CellModel
{
Name = "WorkflowEnabled",
Display = "WorkflowEnabled",
Value =
context.Stages.SingleOrDefault(
s => s.LifecycleStageUID == p.LifecycleStageUID).
IsActive.ToString()
}
,
new CellModel
{
Name = "Status",
Display = "Status",
Value = p.MyStatus.Name
}
,
new CellModel
{
Name = "StatusDeleted",
Display = "StatusDeleted",
Value = (p.MyStatus.Deleted).ToString()
}
,
new CellModel
{
Name = "LeadSource",
Display = "Lead Source",
Value = MySourcesMap[p.AccountSourceUID].Name
}
,
new CellModel
{
Name = "LeadSourceEnabled",
Display = "LeadSourceEnabled",
Value = AccountSoucesEnabledMap[p.AccountSourceUID].ToString()
}
)
}
);
var rows = output.ToList();
return rows;
I would like to expect that my changing the names of most of my variables in the code will not affect the big picture.
My problem that I am facing is SOMETIMES I am getting the following SQLException message:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
What I am wondering, is where in my query am I doing something wrong that would sometimes(most of the time) work, and then very rarely returns this error message. How can I correctly prevent this from happening?
use the DataContext.Log property to display the sql generated by your query. You most likely have a sub-query that is generating more than one result when only one result is valid. For example the following sql will fail if more than one result is returned in the sub-query:
Select * from orders where customer_id =
(select customer_id from customer where name ='bob')
The equality of the where clause in the main query makes no sense if there is more than one result returned from the sub-query.
You may need to alter the uniqueness of some columns of data in your storage in order to ensure that only one row is returned in the sub-query. Another alternative is to alter your class so that the specific problem property being assigned to is a collection instead of a single value.
The SingleOrDefault call will throw an exception if the expression returns more than one item. Maybe you could try and use FirstOrDefault if its just the Top 1 you want.

Categories

Resources