How to add new chart(any charts, highcharts or d3 charts) in Serenity admin dashboard - d3.js

I have created an application using Serenity framework. I have completed basic functionality for CRUD using serenity. Based on my tables I need to have graphical representations, any charts like high charts, D3 charts or any .
1. How can I get data from the tables using serenity framework ?
2. How can I customise the data into graphical representations ?

Finally I have found the answer for this. We can use sql queries as well as stored procedure to fetch data from DB. I have used stored procedure to get the data from db.
In repository page you can call stored procedure,
public ListResponse<MyRow> GetCustomData(IDbConnection connection)
{
var data = connection.Query<MyRow>("GetOrders",
param: new
{
startDate = request.nstartDate,
endDate = request.EndDate
},
commandType: System.Data.CommandType.StoredProcedure);
var response = new ListResponse<MyRow>();
response.Entities = (List<MyRow>)data;
return response;
}
I have already defined MyRow as OrderRow like this
using MyRow = Entities.OrderRow;.
You can call this method from your controller. You can pass the value to model and can use data for chart lik highcharts or d3 charts.
Hope this will help you.

Related

nestjs +graphQL - nested response shape for data from same table

I am trying to create a nestjs + graphql API which would pull the data from database based on user's request. I am following code first approach. I have to expose an API which would return the below nested response shape, though the all data are from single table.
Table Columns: EmployeeNo, departmentId, DepartmentName
Expected Response Shape:
{
EmployeeNo
Department {
departmentId,
DepartmentName
}
}
I used TypeORM and trying to figure out how to have nestjs+graphql return response shape like above hen all the fields are available in single table as different columns. Do I need to have two entities pointing to same table? will it work?
Any suggestion would be helpful. Thanks in Advance!

ReactiveUI - ReactiveCommand to get more data for objects in ReactiveList

Currently I am learning ReactiveUI and I am not sure how to approach this problem. What I want to achieve is once a reactive list has been loaded (in this case I am using a command to load it from a local store) I want to be able to trigger that each of the items in the reactive list then go off and fetch data from an api endpoint and update the view model.
What I currently have to load and create the view models using this logic:
LoadSavedLocations = ReactiveCommand.CreateAsyncTask(async o => {
var savedLocations = await _savedLocationService.GetUserSavedLocations();
return savedLocations;
});
LoadSavedLocations.Subscribe(savedLocations =>
{
foreach (var savedZone in savedLocations)
{
Zones.Add(new ZoneDetailViewModel() {
ZoneId = savedZone.ZoneId,
SavedName = savedZone.SavedName,
});
}
});
I want to then be able to have a command that I can kick off (one first load of the screen and then when the user prompts for an update - pull for reload).
There are two ways I think I can do this but struggling with the approach and the code to achieve this.
Option 1
A command which loops through the items in the ReactiveList fetches data from the Api and then updates that viewmodel something along the lines of
UpdateZones = ReactiveCommand.CreateAsyncTask(async o =>
{
foreach (var zone in Zones)
{
// Fetch
// Await
// Update view model
}
return null;
});
With this I am confused around what the return type of the command would be just a new object()? Is there a better way than just looping like this?
Option 2
On the view model ZoneDetailViewModel have a command called FetchExtraData which will then return the data from the API and I can subscribe to that command in the view model and populate the extra properties. With this approach how does the parent viewmodel trigger all the items in the ReactiveList to fire their commands.
For both approaches I don't know how to get each of the items in the ReactiveList to do logic which involves going to an Api and update.

Dataset conversion to Linq object

Our WCF services return Datasets to the webserver,
In the new .NET web site we are going to use MVC 5. Since MVC 5 framework works really well with known business objets (validation framework etc.), we need to convert Datasets to known business objects in the Model classes.
We tried following conversion,
public List<Category> GetCategories()
{
List<Category> cats = new List<Category>();
DataTable dt = //get data table from the dataset;
foreach (DataRow row in dt.Rows)
{
Category cat = new Category();
cat.CategoryID = int.Parse(row["CategoryID"].ToString());
cat.CategoryName = row["CategoryName"].ToString();
cat.Description = row["Description"].ToString();
cat.Picture = GetBytes(row["Picture"].ToString());
cats.Add(cat);
}
return cats;
}
Assume that we retrieve and unpack the data table.
Will this be an expensive conversion if there are 100s' of request per second accessing this code block?
What would be a better way to test the performance under load?
Or is there a better approach to solve this problem?
Really appreciate any help on this.
I would not worry about the time it takes to convert the DataSet to domain objects since it's going to be a fraction of the remote call to get the data through a remote service.
However, for result sets that rarely change I would recommend adding caching around the resolved domain objects to avoid the conversion, but more importantly avoid the WCF call and subsequent DB call.

Entity Framework, mapping Views to Tables

I have a basic view that returns the same columns as a table (give or take 1 field)
in my DAL code, i am returning a list of MyTableObject, however in some cases, i will call the view to return the same data, but from different sources.
List<MyTableObject> tableObjects = new List<MyTableObject>();
if (case1)
tableObjects = entities.MyTableObjects.Where(criteria).ToList();
else
tableObjects = entities.MyViewObjects.Where(criteria).ToList(); // <-- This will obviously break
return tableObjects;
is there a way to Map view entities to be returned as table entities? (other than having table and view implement the same interface and return that interface) i would like to keep the return type as MyTableObject.
I came across Auto Mapper, but not sure if it would be suitable for this scenario..
Looks like i found a cool solution to this..
Initially I tried to implement interface approach and run into some casting issues (using interfaces alongside my predicate builder), and also with interfaces having to create partial classes for each entity that implement the interface..
the answer.. POCOs.
Iused Poco Template for EF, and than simply edited xxxPocoGenerator.Context.tt to return MyTable object from MyViews collection (one line).
public ObjectSet<Trade> v_Trade {
get { return _v_Trade ?? (_v_Trade = CreateObjectSet<Trade>("Trades")); }
}
nice and easy..
You can write a stored procedure (or CommandText in the model, without creating DB Object) that will simply call "Select * from View". Then create Function Import for this procedure and set the return type to MyTableObject.

Get Dataset returned from an ajax enabled wcf service

I call an ajax enabled wcf service method ,
<script type="text/javascript">
function GetEmployee() {
Service.GetEmployeeData('1','5',onGetDataSuccess);
}
function onGetDataSuccess(result) {
Iteratejsondata(result)
}
</script>
and my method is ,
[OperationContract]
public string GetEmployeeData(int currentPage,int pageSize)
{
DataSet ds = GetEmployeeViewData(currentPage,pageSize);
return GetJSONString(ds.Tables[0]);
}
My Dataset ds contains three datatable but i am using the first one for my records...
Other two datatables have values how can i get them in result...
function onGetDataSuccess(result) {
Iteratejsondata(result)
}
Any suggestion...
The only suggestion: do not use DataSets over WCF!
DataSets are evil - they're huge, they carry lots of overhead, the mix data with behavior - all things you should try to avoid like the plague when doing proper SOA. This is doubly true when you're doing Ajax calls asynchronously - you want to transfer as little data as possible using JSON - and having a DataSet with DataTables does not help you at all for your JSON calls...
So really : get yourself acquainted with some kind of an ORM, and grab objects and lists of objects and toss the DataSets onto the digital recycling heap.....
For a small project, if you're using SQL Server as your backend, why not use Linq-to-SQL? Or if that doesn't work for you, check out Subsonic

Resources