0

I am developing ASP.NET MVC application using entity framework and for data access i am following unitofwork and repository pattern. For UI, I am using kendo.

Now i implemented kendo grid which is bind to signalr, so that different user can see the live updates.

Issue

Any database operation that i perform via signalr hub was not reflecting into the database.

[Microsoft.AspNet.SignalR.Authorize(Roles = "SuperAdmin")]
public class EquipmentTypeHub : Hub
{

    public ILogisticsService Service { get; set; }
    public EquipmentTypeHub()
    {            
        Service = GetLogisticsService();
    }
    private LogisticsService GetLogisticsService()
    {
        LogisticsService logisticsService = DependencyResolver.Current.GetService<LogisticsService>();
        return logisticsService;
    }

    public void SaveEquipmentType(EquipmentTypeViewModel model)
    {           
        try
        {
            var equipmentType = Service.GetEquipmentTypes<EquipmentType>(a => a.Id == model.Id).FirstOrDefault();

            if (equipmentType == null)
            {
                equipmentType = new EquipmentType();
            }
            equipmentType.EquipmentTypeName = "Firefox"; //I am trying to update a record from chrome to firefox
            equipmentType.EquipmentTypeId = model.EquipmentTypeId;
            equipmentType.IsActive = model.IsActive;
            Service.SaveEquipmentType<EquipmentType>(equipmentType);
            Clients.Others.SaveEquipmentType(model);              
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
 }

Below was the record i am trying to update:

enter image description here

But record remains unchanged and system also didn't throw any error.

Below was the actual content of the model before commit()

enter image description here

Update

If i do the same as unauthenticated user the database gets updated and i am using asp.net identity 2.0

Appreciate your help thanks!

10
  • Can you show your calls to the hub from JS? Are you sure that the hub is actually being hit? Commented Jul 20, 2015 at 13:08
  • Yes, I am able to hit the hub method and i able to debug it since the ui code was too long i was not able to show it. I didn't get any error and context.saveChanges() also been executed Commented Jul 20, 2015 at 13:10
  • So you can follow the debug into your hub SaveEquipmentType, yet DB isn't updated. Problem most likely is in your service then - can you follow the debug into that? Commented Jul 20, 2015 at 13:11
  • yes as you mentioned i debugged my code but my concern is if i perform same operation via mvc controller database gets updated as expected but if i perform same via hub class it was not updating into the database Commented Jul 20, 2015 at 13:13
  • I suggest you check the actual contents of the model when you debug. It most likely is blank Commented Jul 20, 2015 at 13:14

2 Answers 2

1

Unless I'm misunderstanding your code example and your requirement, I have to sat that you're using SignalR all wrong - it's not designed to be an API for CRUD operations. It's designed to publish/subscribe to messaging between server and client.

You might, for example, somewhere in your system add equipment to your database. You would then use SignalR to notify connected clients of this new equipment. They could, for example, then make a call to retrieve this new equipment.

This line, for example: Clients.Others.SaveEquipmentType(model); appears to be the broadcast to connected clients. Nothing more.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I agree but i am having an requirement that i should bind the kendo grid with signalr and below was the link demos.telerik.com/kendo-ui/grid/signalr
1

Unity container manages the lifetime of objects of all the dependencies that it resolves using lifetime managers.

Unity container includes different lifetime managers for different purposes. You can specify the lifetime manager in the RegisterType() method at the time of registering type-mapping.

For example, the following code snippet shows how to register a type-mapping with TransientLifetimeManager.

var container = new UnityContainer()
               .RegisterType<ICar, BMW>(new TransientLifetimeManager());

You can register your type's mappings in UnityConfig RegisterTypes

 //Register your type's mappings here.
 container.RegisterType<ChatHub, ChatHub>(new TransientLifetimeManager());
 container.RegisterType<IHubActivator, UnityHubActivator>(new TransientLifetimeManager());

Check this out Transient Lifetime Manager

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.