Hi,
I created a hub with the CRUD method:
[Microsoft.AspNet.SignalR.Hubs.HubName("PayslipUploadHub")]
public class PayslipUploadHub : Microsoft.AspNet.SignalR.Hub
{
public DataSourceResult ReadPayslipBatch([DataSourceRequest]DataSourceRequest request)
{
return DAL.GetPayslipBatchHistory(null).ToDataSourceResult(request);
}
public void UpdatePayslipBatch(PayslipGeneration payslipBatch)
{
Clients.Others.update(new DataSourceResult
{
Data = new[] { payslipBatch }
});
}
public DataSourceResult CreatePayslipBatch(DataSourceResult payslipBatch)
{
Clients.Others.create(payslipBatch);
return payslipBatch;
}
public void DestroyPayslipBatch(PayslipGeneration payslipBatch)
{
Clients.Others.destroy(new DataSourceResult
{
Data = new[] { payslipBatch }
});
}
}
I need to trigger the creation and the update not directly from the grid but on other actions. So to trigger Signal R this what i do:
var payslipBatch = DAL.GetPayslipBatchHistory(oResult.Result).First();
using (var scope = _wa.CreateWorkContextScope(HttpContext))
{
var context = scope.Resolve<
Microsoft.AspNet.SignalR.Infrastructure
.IConnectionManager>().GetHubContext<
PayslipUploadHub
>();
context.Clients.All.createPayslipBatch(payslipBatch);
}
When I debug this it actually never break into the CreatePayslipBatch Method of the Hub, and I don't understand why.
Here is the grid declaration:
@(Html.Kendo().Grid<
PayslipGeneration
>()
.Name("PayslipGenerationHistory")
.Columns(columns =>
{
columns.Bound(c => c.Status.Code).Width(60).ClientTemplate("<
i
class
=
'#=Status.Class#'
></
i
>").HtmlAttributes(new { style = "text-align:center" }).Title("Status");
columns.Bound(c => c.Name).Width(250);
columns.Bound(c => c.Period).Format("{0:MMMM yyyy}").Width(110);
columns.Bound(c => c.StatusInfo);
columns.Bound(c => c.Comment);
columns.Bound(c => c.CreatedBy).Width(140);
columns.Bound(c => c.CreatedOn).Format("{0:dd MMM yyyy}").Width(110).Title("Created On");
columns.Bound(c => c.UpdatedBy).Width(140);
columns.Bound(c => c.UpdatedOn).Format("{0:dd MMM yyyy}").Width(110).Title("Updated On");
columns.Template(e => { }).ClientTemplate(
"# if(Status.Code == 'FAILED') " +
"{# <
a
onclick
=
'RegenFailed( #: data.Id # );'
><
i
title
=
'Regenerate Payslip'
class
=
'fa fa-undo fa-2x'
></
i
></
a
> #} " +
"else {# <
i
title
=
'Regenerate Payslip'
class
=
'fa fa-undo fa-2x'
></
i
> #}#")
.Title("").Width(50).HtmlAttributes(new { style = "text-align:center" });
//columns.Command(command => command.Custom("Delete").Click("DeleteBatchLine")).Title("").Width(80);
//columns.Command(command => command.Custom("Check").Click("CheckBatchLine")).Title("").Width(80);
})
.HtmlAttributes(new { style = "height: 380px;" })
.Scrollable()
.Groupable()
.Sortable()
.ClientDetailTemplateId("template")
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(new List<
string
>{"10","20","50"})
)
.DataSource(dataSource => dataSource
.SignalR()
.PageSize(10)
.Events(ev => ev.RequestEnd("onRequestEnd"))
.AutoSync(true)
.ServerFiltering(true)
.ServerPaging(true)
.Sort(s => s.Add("CreatedOn").Descending())
.Transport(tr => tr
.Promise("hubStart")
.Hub("hub")
.Client(c => c
.Read("readPayslipBatch")
.Update("updatePayslipBatch")
.Create("createPayslipBatch")
.Destroy("destroyPayslipBatch"))
.Server(s => s
.Read("ReadPayslipBatch")
.Update("UpdatePayslipBatch")
.Create("CreatePayslipBatch")
.Destroy("DestroyPayslipBatch")))
.Schema(schema => schema
.Data("Data")
.Total("Total")
.Aggregates("Aggregates")
.Model(model =>
{
model.Id("Id");
}
)))
.Events(e => e.DataBound("onDataBound"))
)
At the beginning I was not using the DataSourceResult but directly the type PayslipGeneration and I had a lot of trouble with the pagination. So i converted the read function to return a DataSourceResult and then it broke all the other CRUD method I tried to cast the other CRUD method to work only with DataSourceResult as mention on this post, but it still not working.
Any idea?