Rank: Newbie
Groups: Registered
Joined: 11/19/2019(UTC) Posts: 2 Thanks: 1 times
|
Hi folks! Firstly for a FOSS product, Seal Report is amazing. Took a bit to get my head around it, but so far it's really promising. Now, I've worked through this thread and successfully "cloned" a restriction value across multiple models, and this is working great. However, I'm struggling with accessing models by ID. See below (I'm aware this is probably terrible code done badly!): Code:report.Models[1].Restrictions[0].Date1 = report.Models[0].Restrictions[0].Date1;
report.Models[2].Restrictions[0].Date1 = wc.AddDays(2);
report.Models[3].Restrictions[0].Date1 = wc.AddDays(3);
When I add new models, the ID seems to change sometimes especially if I delete one. What I would like to be able to do is something like this: Code:report.Model("Model Name").Restrictions[0].Date1 = report.Model("Other Model Name").Restrictions[0].
One thought I had was looping through all models, checking the name against a hard-coded list and setting the restriction(s) that way, using something equivalent to a MySQL CASE statement, however that just feels clunky. I've found the way to access a restriction by name using GetRestrictionByName() - is there a similar method for models? I've read through a number of posts here - learning a lot in the process - but haven't yet found a definitive answer. Any help/pointers greatly appreciated. Cheers Edited by user Tuesday, November 19, 2019 4:13:26 PM(UTC)
| Reason: Extra detail
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/20/2013(UTC) Posts: 1,209 Thanks: 14 times Was thanked: 206 time(s) in 199 post(s)
|
There is no helper to get a model by name, however you can do like this (like all other Collections): Code:var model = report.Models.FirstOrDefault(i => i.Name = "My Model Name");
if (model != null) {
}
It works for report.Sources (or any collection) as well.... Code:
var auditSource = Repository.Instance.Sources.FirstOrDefault(i => i.Name == "Audit");
auditSource = report.Sources.FirstOrDefault(i => i.Name == "Audit");
|
1 user thanked epf for this useful post.
|
|
|
Rank: Newbie
Groups: Registered
Joined: 11/19/2019(UTC) Posts: 2 Thanks: 1 times
|
Fantastic, thank you! It's been years since I touched C# so this is all foreign to me. This works perfectly for what I need.
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.