Mono Support HOW TO DISPLAY NOTIFICATIONS WHEN USER HAS UNREAD MESSAGES 

Viewed 71089 time(s), 20 post(s), 8/1/2014 7:00:34 PM - by ZaeVega
12/23/2014 12:50:36 AM
127 Reputation 15 Total posts

Please
Where I can add this code?

I get this error:
"MonoSoftware.MonoX.Repositories.MessageRepository' does not contain a definition for 'GetInstance"

11
12/23/2014 8:22:11 AM
3016 Reputation 428 Total posts

Hi,

can you please let us know what MonoX version you have?

Regards.

12
12/23/2014 1:25:13 PM
127 Reputation 15 Total posts


MonoX v5.1.40.5030 [31/10/2014], DB v4.7.3842

13
12/23/2014 1:36:54 PM
3016 Reputation 428 Total posts

Hi,

you need to use DI in order to get an instance  for the Message repository:

DependencyInjectionFactory.Resolve<IMessageRepository>().GetNumberOfUnreadMessages(userId);
Regards.

14
12/23/2014 1:50:58 PM
127 Reputation 15 Total posts

error CS0103: The name 'DependencyInjectionFactory' does not exist in the current context

full code is :

<asp:PlaceHolder runat="server" ID="plhNumber"><br><span class='number'><%= DependencyInjectionFactory.Resolve<IMessageRepository>().GetNumberOfUnreadMessages(userId) %></span></asp:PlaceHolder

15
12/23/2014 2:32:08 PM
3016 Reputation 428 Total posts

Just tried on the "SeoLoginStatus" control which has "DependencyInjectionFactory" property inherited from the BaseUserControl and it works.

Also, you need include repository import in your markup:

<%@ Import Namespace="MonoSoftware.MonoX.Repositories" %>

16
12/23/2014 2:50:38 PM
127 Reputation 15 Total posts

"SeoLoginStatus" control code now is

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SeoLoginStatus.ascx.cs"
    Inherits="MonoSoftware.MonoX.Controls.SeoLoginStatus" %>
    <%@ Import Namespace="MonoSoftware.MonoX.Repositories" %>
 
<asp:PlaceHolder ID="panStatus" runat="server">
    <asp:LinkButton runat="server" ID="btnButton">
        <span class="icon-logout"><%= LogoutText %></span>       
    </asp:LinkButton>
    <asp:HyperLink runat="server" ID="btnLink"><%= LoginText %></asp:HyperLink>
</asp:PlaceHolder>
 
<asp:PlaceHolder runat="server" ID="plhNumber">
<span class='number'><%= DependencyInjectionFactory.Resolve<IMessageRepository>().GetNumberOfUnreadMessages(userId) %></span>
 
 
</asp:PlaceHolder>
But I get this error:
error CS0103: The name 'userId' does not exist in the current context

17
12/23/2014 2:55:58 PM
3016 Reputation 428 Total posts

"userId" was just a hint that you need provide "GetNumberOfUnreadMessages" with the required parameters.

UserId can be obtained as I wrote in the topic marked as answered:

SecurityUtility.GetUserId();
It returns current logged user's id.

Regards.

18
12/23/2014 3:21:32 PM
127 Reputation 15 Total posts

Thank you &  I'm sorry it's my mistake  :)

19
12/23/2014 3:23:42 PM
3016 Reputation 428 Total posts

No problem, we are glad that you managed to implement it.

Regards.

20
1 2
This is a demo site for MonoX. Please visit Mono Software for more info.