How to pass generic list value to InOutArgument declared in Workflow Xaml - xaml

I have a entity class SEBLInBound as mentioned below
public class SEBLInbound
{
public int MEME_CK
{
get;
set;
}
public String EligibilityBeginDate
{
get;
set;
}
public String EligibilityEndDate
{
get;
set;
}
public Char VoidIndicator
{
get;
set;
}
public Char ReInstate
{
get;
set;
}
public char PriorToGoLive
{
get;
set;
}
}
I have declared a INOutArgument in XAML with type of this Entity class
<x:Members>
<x:Property Name="ErrorMsg" Type="OutArgument(x:String)" />
<x:Property Name="InboundProp" Type="InOutArgument(local:SEBLInbound)" />
<x:Property Name="argument1" Type="InArgument(x:String)" />
<x:Property Name="argument2" Type="InArgument(x:String)" />
</x:Members>
now from cs file i want to pass list value List to this Xaml for manipulation.
Please let me know, how to pass the value to workflow
THanks in advance

You pass objects into Workflow arguments using a dictionary object where the Keys are the name of the argument.
IDictionary<string, object> inParams = new Dictionary<string, object>
{
{"InboundProp", _yourDataObject01 },
{"argument1", _yourDataObject02 },
{"argument2", _yourDataObject03 },
};
_workflowApplication = new WorkflowApplication(new MyWorkFlow(), inParams)
_workflowApplication.Run();

Related

XAML Binding - Cannot access array item

I'm trying to bind a property via MVVM pattern.
The payload is something like that:
{
"QualificationSummary": "For all positions individuals must have IT-related experience...",
"PositionRemuneration": [
{
"MinimumRange": "62639.0",
"MaximumRange": "137348.0",
"RateIntervalCode": "PA"
}
]
}
I Tried this, but did nor worked.
<Label>
<Label.Text>
<MultiBinding StringFormat="{}{0}{1}">
<Binding Path="PositionRemuneration[MinimumRange]"/>
<Binding Path="PositionRemuneration[MaximumRange]"/>
</MultiBinding>
</Label.Text>
</Label>
Any clues?
After spend some time understanding the problem, that's the solution.
The c# class:
public Positionlocation[] PositionLocation { get; set; }
public class Positionlocation
{
public string LocationName { get; set; }
public string CountryCode { get; set; }
public string CountrySubDivisionCode { get; set; }
public string CityName { get; set; }
public float Longitude { get; set; }
public float Latitude { get; set; }
}
and to access the property:
<Binding Path="MatchedObjectDescriptor.PositionLocation[0].LocationName"/>

ASP.NET Core Web API Not Returning List of Child Items

I am creating a ASP.NET Core web API that uses EF Core. I have a GET endpoint that returns a list of reports from the database. I have a related table which stores screenshots for the reports. The reportId is the foreign key in the images table.
I have a List item in the reports class which points to the ImagesList class.
I have the foreign key reportId in the ImageList class and identified as a foreign key. I also have a navigation property setup to the Reports class.
Reports Class:
[Table("Vw_ReportsList", Schema = "pbi")]
public class Reports
{
[Key]
public string reportId { get; set; }
[Required]
public string reportName { get; set; }
public string reportDescription { get; set; }
public string reportType { get; set; }
public string reportAuthor { get; set; }
public string reportLastUpdate { get; set; }
public string reportLastExecution { get; set; }
public List<ImagesList> Screenshots { get; set; }
//collection navigation property
}
ImageList Class:
[Table("Vw_ScreenshotsList", Schema = "pbi")]
public class ImagesList
{
[Key]
public int id { get; set; }
public string fileNameTest { get; set; }
public string imageData { get; set; }
public string created { get; set; }
public string reportId { get; set; }
[ForeignKey("reportId")]
public virtual Reports Reports { get; set; }
//navigation property
}
Context:
public class ServiceCatalogContext : DbContext
{
public ServiceCatalogContext(DbContextOptions<ServiceCatalogContext> options) : base(options) { }
public DbSet<Reports> Reports { get; set; }
public DbSet<ImagesList> ImagesLists { get; set; }
public DbSet<Images> Images { get; set; }
//used for the image upload POST call
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// modelBuilder.Entity<ImagesList>().HasOne<Reports>().WithMany().HasForeignKey(s => s.reportId);
modelBuilder.Entity<ImagesList>().HasOne(s => s.Reports).WithMany(s => s.Screenshots).HasForeignKey(s => s.reportId);
modelBuilder.Entity<Reports>().HasMany(r => r.Screenshots).WithOne().HasForeignKey(r => r.reportId);
}
}
My API works and returns the list of reports with no errors but I do not receive the screenshots list that I am expecting.
Here is a sample of the API output:
{
"reportId": "AC79F4CD-3771-42B2-B7F8-46AE4CE8DC80",
"reportName": "Dashboard Usage Metrics Report",
"reportDescription": "DESCRIPTION HERE - Dashboard Usage Metrics Report",
"reportType": "Excel",
"reportLastUpdate": "07/22/2020",
"reportLastExecution": "07/23/2020"
},
{
"reportId": "138CD5FA-6B5A-4C63-A449-DA9A9BBBF689",
"reportName": "Report Usage Metrics Report",
"reportDescription": "DESCRIPTION HERE - Report Usage Metrics Report",
"reportType": "Excel",
"reportLastUpdate": "07/22/2020",
"reportLastExecution": "07/23/2020"
}
I not receiving any error message from the API so I am not sure what I missed in order for each report to return the related images.
Edit: Adding Controller action
[HttpGet]
[EnableQuery()] //enabled OData querying
public IQueryable<Reports> Get()
{
return _context.Reports;
}
Edit: Updated ImagesList class
I also have Odata installed so here the metadata if that is of help:
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="ServiceCatalog.API.Entities" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="Reports">
<Key>
<PropertyRef Name="reportId" />
</Key>
<Property Name="reportId" Type="Edm.String" Nullable="false" />
<Property Name="reportName" Type="Edm.String" Nullable="false" />
<Property Name="reportDescription" Type="Edm.String" />
<Property Name="reportType" Type="Edm.String" />
<Property Name="reportLastUpdate" Type="Edm.String" />
<Property Name="reportLastExecution" Type="Edm.String" />
<NavigationProperty Name="Screenshots" Type="Collection(ServiceCatalog.API.Entities.ImagesList)" />
</EntityType>
<EntityType Name="ImagesList">
<Key>
<PropertyRef Name="id" />
</Key>
<Property Name="id" Type="Edm.Int32" Nullable="false" />
<Property Name="fileNameTest" Type="Edm.String" />
<Property Name="imageData" Type="Edm.String" />
<Property Name="created" Type="Edm.String" />
<Property Name="reportId" Type="Edm.String" />
<NavigationProperty Name="Reports" Type="ServiceCatalog.API.Entities.Reports">
<ReferentialConstraint Property="reportId" ReferencedProperty="reportId" />
</NavigationProperty>
</EntityType>
</Schema>
<Schema Namespace="Default" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityContainer Name="Container">
<EntitySet Name="reports" EntityType="ServiceCatalog.API.Entities.Reports" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Design your model like below:
[Table("Vw_ReportsList", Schema = "pbi")]
public class Reports
{
[Key]
public string reportId { get; set; }
[Required]
public string reportName { get; set; }
public string reportDescription { get; set; }
public string reportType { get; set; }
public string reportAuthor { get; set; }
public string reportLastUpdate { get; set; }
public string reportLastExecution { get; set; }
public List<ImagesList> Screenshots { get; set; }
//collection navigation property
}
[Table("Vw_ScreenshotsList", Schema = "pbi")]
public class ImagesList
{
[Key]
public int id { get; set; }
public string fileNameTest { get; set; }
public string imageData { get; set; }
public string created { get; set; }
public string reportId { get; set; }
// [ForeignKey("reportId")]
public virtual Reports Reports { get; set; }
//navigation property
}
And your DbContext:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ImagesList>().HasOne(s => s.Reports)
.WithMany(s => s.Screenshots).HasForeignKey(s => s.reportId);
//modelBuilder.Entity<Reports>().HasMany(r => r.Screenshots).WithOne().HasForeignKey(r => r.reportId);
}
Your controller:
[HttpGet]
public IQueryable<Reports> Get()
{
return _context.Reports.Include(r=>r.Screenshots);
}
Be sure to install Microsoft.AspNetCore.Mvc.NewtonsoftJson then use the following code:
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});

applying an object with a ICollection<Enum> type

In an ASP.NET 3.1 CORE project, using EF, I am trying to implement an object that holds a type of ICollection<Enum> type.
the problem is after reading some tutorials and trying to migrate it to my database something seems off, I will attach screenshots and code for more understanding.
this is the object class :
public class UsersCredentialsModel
{
[Key]
public string UserId { get; set; }
public ICollection<ServiceModel> Services { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Hash { get; set; }
}
The ServiceModel class:
public class ServiceModel
{
[Key]
public string ServiceId { get; set; }
public Service Service { get; set; }
}
The Service Enum Class:
public enum Service : int
{
Badoo = 0,
Tinder = 1,
Grinder = 2,
OkCupid = 3
}
This is the AppDbContext class:
public class AppDbContext : IdentityDbContext<ApplicationUser>
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Message>().Property(m => m.Service).HasConversion<int>();
builder.Entity<ApplicationUser>().HasMany<Message>(m => m.Messages).WithOne(u =>
u.User).IsRequired();
builder.Entity<ServiceModel>().Property(m => m.Service).HasConversion<int>();
builder.Entity<UsersCredentialsModel>().HasMany(s => s.Services);
base.OnModelCreating(builder);
}
public DbSet<UsersCredentialsModel> UsersCredentialsModels { get; set; }
public DbSet<ServiceModel> ServiceModel { get; set; }
public DbSet<Message> Messages { get; set; }
public DbSet<CookieModel> CookieModel { get; set; }
public DbSet<ProjectionModel> ProjectionModel { get; set; }
}
This is a picture of the UsersCredentialsModel database schema:
** I believe that there should be a filed called "ServiceId" corresponding to the Id of the second table.
and finally a picture of the ServiceModel schema:
from what I understood you can't implement ICollection of type ENUM and you have to wrap it in a class so basically you need an object to hold the ENUM with an ID and another Id that holds the userId.
The problem is that UserCredentialsModel table should hold an Id property of ServiceId coming from ServiceModel table.
because the class has a field of ICollection but when migrating it does nothing

map string filed to generic list in automapper based on .net core

I have a DomainModel and a DTO like this :
public class PostEntity: IEntity
{
[Required]
public string Description { get; set; }
public int Id { get; set; }
[Required]
public string Slug { get; set; }
[Required]
public string Tags { get; set; }
[Required]
public string Title { get; set; }
[Required]
public DateTime CreatedOn { get; set; }
public DateTime? UpdatedOn { get; set; }
public PostStatus Status { get; set; }
public User Writer { get; set; }
public int WriterId { get; set; }
}
public class PostDto
{
public int Id { get; set; }
public string Description { get; set; }
public string Slug { get; set; }
public string Tags { get; set; }
public string Title { get; set; }
public DateTime CreatedOn { get; }
public List<string> TagList { get; set; }
public PostDto()
{
TagList = new List<string>();
}
}
PostEntity'Tags contains some tags seperated by ",", now I want to split tags value by "," and convert it to List, to do this, I've tried this but I get the below compilation error
CreateMap<PostEntity, PostDto>().ForMember(dest => dest.TagList, cc => cc.MapFrom(src => src.Tags.Split(",").ToList()));
I get this error :
An expression tree may not contain a call or invocation that uses optional arguments
I can't reproduce your error, it seems to work fine.
Below is an example where the TagList is correctly mapped
The code I used :
MapperConfiguration MapperConfiguration = new MapperConfiguration(configuration =>
{
configuration
.CreateMap<PostEntity, PostDto>().ForMember(dest => dest.TagList, cc => cc.MapFrom(src => src.Tags.Split(',').ToList()));
});
IMapper mapper = MapperConfiguration.CreateMapper();
PostEntity postEntity = new PostEntity
{
Tags = "Tag1,Tag2,Tag3,Tag4"
};
var mappedObject = mapper.Map<PostEntity, PostDto>(postEntity);
Please bear in mind that Expression.Call API does not support optional parameters. So, you should Replace Split(',') with
Split(',', System.StringSplitOptions.None)
or
Split(',', System.StringSplitOptions.RemoveEmptyEntries)
doing so you won't see that error again.

Handling queries over related documents in RavenDB

I have a project where I have a set of forms:
public class Form
{
public string Id { get; set; }
public string Name { get; set; }
public IList<string> FieldValueIds { get; set; }
public string UserId { get; set; } // the user who completed the form.
public string FormTemplateId { get; set; }
}
Which each "implement" a form template selected at creation of the form.
public class FormTemplate
{
public string Id { get; set; }
public string Name { get; set; }
public IList<string> FieldIds { get; set; }
}
Which defines which fields are present within the form. Each field
public class FormField
{
public string Id { get; set; }
public string Name { get; set; }
public string Caption { get; set; }
public ValueType DataType { get; set; } // Enum specifying the type of data this field accepts.
}
Stores information about the field such as a description and what type it is expecting. Each FormField can be present in multiple FormTemplates with the values for the form being stored as FieldValue objects related to the Form itself.
public class FieldValue
{
public string Id { get; set; }
public string FieldId { get; set; }
public string ValueAsJsonString { get; set; }
}
Other objects include the User Object:
public class User
{
public string Id { get; set; }
public string Username { get; set; }
public string GivenNames { get; set; }
public string Surname { get; set; }
}
I would like to be able to perform a query to find all Forms completed by a user with a specified name, or all Forms where a field with name X has value Y and so forth.
I have looked into usage of indexes as specified in the documentation Indexing related documents, however the implementation as presented in the documentation threw a NotSupportedException when I implemented the example as follows:
class FormTemplates_ByFieldAndName : AbstractIndexCreationTask<FormTemplate>
{
public class Result
{
public string Name { get; set; }
public IList<string> FieldNames { get; set; }
}
public FormTemplates_ByFieldAndName()
{
Map = FormTemplates => from FormTemplate in FormTemplates
select new
{
Name = FormTemplate.Name,
FieldNames = FormTemplate.FieldIds.Select(x => LoadDocument<FormField>(x).Name)
};
}
}
// in code:
IList<FormTemplate> TestResults = session.Query<FormTemplates_ByFieldAndName.Result, FormTemplates_ByFieldAndName>()
.Where(x => x.Name == "TemplateName" || x.FieldNames.Contains("FieldName"))
.OfType<FormTemplate>()
.ToList();
As best as I can tell this was implemented correctly, however I have seen a suggestion to replace the .Contains with a .Any implementation instead. In lieu of this I have been experimenting with a different approach by applying successive .Where arguments. Like so:
var pre = session.Query<FormTemplates_ByFieldAndName.Result, FormTemplates_ByFieldAndName>();
var pr2 = pre.Where(x => x.Name == "TypeTest25");
List<FormTemplate> TestResults = pr2
.Where(x => x.FieldNames.Any(a => a == "field25"))
.OfType<FormTemplate>()
.OrderByScoreDescending()
.ToList();
Modifying the system to perform in a more factory oriented approach by applying successive filters based on a supplied string in a pre-specified format.
Is this the way I should be going for this implementation and if not what should I be changing? In particular if I am to proceed with the Indexing option how would I apply this technique to the nested relationship between Forms and FormFields through FormTemplates.
You seems to be trying to do this in a way that is mostly relational, but you don't have to.
Instead of trying to have a set of independent documents that each has part of the data, just store it all in a single document.
public class Form
{
public string Id { get; set; }
public string Name { get; set; }
public IList<FieldValue> FieldValues { get; set; }
public string UserId { get; set; } // the user who completed the form.
public string FormTemplateId { get; set; }
}
public class FieldValue
{
public string Id { get; set; }
// can store the value directly!
//public string ValueAsJsonString { get; set; }
public object Value {get; set; }
}
This will generate documents that looks like this:
{
"Id": "forms/1234",
"Name": "Tom",
"FieldValues": [
{
"Id": "FromValues/SchoolDistrictName",
"Value": "ABi195"
}
],
"UserId": "users/tom",
"FormTemplateId": "FromTemplate/1234"
}
Which is a much more natural way to model things.
At that point, you can use RavenDB's ability to index dynamic data, see the docs here:
https://ravendb.net/docs/article-page/3.5/Csharp/indexes/using-dynamic-fields