Mono Support Can't figure out Rating 

Viewed 29830 time(s), 13 post(s), 12/19/2011 5:41:15 PM - by grant.stone007
12/28/2011 2:55:34 AM
647 Reputation 69 Total posts

I have devised a solution by taking a different approach. I customized the MessageCreate.ascx and some class overrides as opposed to the custom usercontrol I was attempting before. See my markup and code below. This works perfectly using the standard MonoXRating.ascx.

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="myMessageDetails.ascx.cs" Inherits="myMessageDetails" %>
...

<%@ Register TagPrefix="MonoX" TagName="Rating" Src="/MonoX/Controls/MonoXRating.ascx" %>
...

<
asp:Panel runat="server" ID="pnlContainer">
    <div class="input-form reply-message">
    <dl>
    <dd>
 
<MonoX:Rating ID="ctlRating" runat="server"
    ParentEntityType="Message"
    OnRating="myOnRating"
    OnRated="myOnRated"
    ShowRatingHistory="true"
/>
<br />
        <asp:Label ID="lblMessage" runat="server" AssociatedControlID="txtMessage"></asp:Label>
        <asp:TextBox ID="txtMessage" Rows="8" TextMode="MultiLine" runat="server"></asp:TextBox>
    </dd>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
 
using MonoSoftware.MonoX.Controls;
using MonoSoftware.MonoX.Repositories;
using MonoSoftware.MonoX.DAL.EntityClasses;
using MonoSoftware.MonoX.Utilities;
 
using MonoSoftware.MonoX;
using MonoSoftware.MonoX.API;
using System.Configuration;
using Telerik.Web.UI;
 
/// <summary>
/// Summary description for myMessageDetails
/// </summary>
public partial class myMessageDetails : MonoSoftware.MonoX.ModuleGallery.SocialNetworking.MessageDetails
{
    public myMessageDetails()
    {
        //
        // TODO: Add constructor logic here
        //
    }
 
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
            MonoSoftware.MonoX.Controls.MonoXRating r (MonoSoftware.MonoX.Controls.MonoXRating)this.FindControl("ctlRating");
      
r.ParentEntityId = this.MessageId;
      r.DataBind();   
    }
 
    protected void myOnRating(object sender, EventArgs e)
    {
        MonoSoftware.MonoX.Controls.MonoXRating r = (MonoSoftware.MonoX.Controls.MonoXRating)this.FindControl("ctlRating");
        r.ParentEntityId = this.MessageId;
    }
 
    protected void myOnRated(object sender, MonoSoftware.Core.EventArgs<decimal> e)
    {
        //e.Value has the rating <decimal>.
   //do something based upon the rating...
    
}
}

1
12/19/2011 5:41:15 PM
647 Reputation 69 Total posts

I am attempting to implement Rating on the MessageDetails control. It seems to me that the RatingBBL and the MonoXRating controls do not operated correctly when ParentEntityType is Message. I have experimented with API in very isolated manner as shown below and have verified values of all parameters to be correct at runtime.

Guid peid = this.MessageId;
IRatingBLL r = RatingBLL.GetInstance();
EntityCollection<SnRatingEntity> rc = r.GetRatingCollection(peid, SnEntityType.Message, false, 100);
bool israted = r.IsRatedByUser(peid, SnEntityType.Message, SecurityUtility.GetUserId());

No matter what the values of GetUserId() and ParentEntityId are..

1. call to GetRatingCollection() returns ALL records from the snRating table regardless of parameter values.
2. call to IsRatedbyUser() returns true.

Is there perhaps something wrong with the RatingBLL in case of ParentEntityType=SnEntityType.Message OR is that my code is wrong (more likely reason)?

Any comments would be greatly appreciated.


2
12/20/2011 9:09:51 AM
15993 Reputation 2214 Total posts

Hi,

we have fixed the relation issue you have found, basically Messages weren't supported so we have made small modification to support them and you can download latest package from the InMail.

Let us know if rating for Messages is working now.

Regards

3
12/20/2011 5:53:11 PM
647 Reputation 69 Total posts

Thank you so much. My test code below now works in context of MesageDetails.aspx...

Guid peid = this.MessageId;
IRatingBLL r = RatingBLL.GetInstance();
EntityCollection<SnRatingEntity> rc = r.GetRatingCollection(peid, SnEntityType.Message, false, 100);
bool israted = r.IsRatedByUser(peid, SnEntityType.Message, SecurityUtility.GetUserId());
r.SaveRating(1, SecurityUtility.GetUserId(), peid, SnEntityType.Message);

Next, I attempted to implement MonoXRating.ascx on MessageDetails.aspx as shown below. Render seems to work correctly but Save Rating does not. When I rate, the control seems to do work, then refreshes as though no rate (no stars selected) and no records were created in db tables snRelationships nor snRating.


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MessageDetails.ascx.cs" Inherits="MonoSoftware.MonoX.ModuleGallery.SocialNetworking.MessageDetails" %>
<%@ Import Namespace="MonoSoftware.MonoX.Resources" %>
<%@ Register Namespace="MonoSoftware.Web.Pager" Assembly="MonoSoftware.Web.Pager" TagPrefix="mono" %>
<%@ Register TagPrefix="Mono" Assembly="MonoX" Namespace="MonoSoftware.MonoX.Blog" %>
<%@ Register TagPrefix="MonoX" TagName="SilverlightUpload" Src="/MonoX/ModuleGallery/SilverlightUploadModule.ascx" %>
<%@ Register TagPrefix="MonoX" TagName="FileGallery" Src="/MonoX/ModuleGallery/SocialNetworking/FileGallery.ascx" %>
<%@ Register TagPrefix="MonoX" TagName="StyledButton" Src="/MonoX/controls/StyledButton.ascx" %>

<%@ Register TagPrefix="MonoX" TagName="Rating" Src="/MonoX/controls/MonoXRating.ascx" %>

<div style="border:solid 1px silver;">
<div style="font-size:150%;font-weight:bold;padding:10px;"><asp:Literal runat="server" ID="ltlSubject"></asp:Literal></div>
<div style="padding:5px;height:100%;width:100%;">

<asp:ListView ID="lvPosts" runat="server">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<table cellpadding="0" cellspacing="0" width="95%" class="message-details">
<tr>
<td style="width: 0%; text-align: center;">
<Mono:Gravatar ID="ctlGravatar" runat="server" Size="100" Email='<%# Eval("AspnetUser.Email") %>' UserName='<%# Eval("AspnetUser.UserName") %>' /><br />
<strong><asp:Literal ID="lblAuthor" runat="server" Text='<%# Eval("AspnetUser.UserName") %>'></asp:Literal></strong>
<div class="date"><asp:Literal ID="lblDate" runat="server" Text='<%# Eval("DateCreated") %>'></asp:Literal></div>
</td>
<td style="width: 100%;">
<pre style='white-space:pre-wrap;word-wrap:break-word;'><asp:Literal ID="ltlMessage" runat="server" Text='<%# Eval("Body") %>'></asp:Literal></pre>


<MonoX:Rating ID="ctlRating" runat="server" ShowRatingHistory="true" ParentEntityType="Message" ParentEntityId='<%# Eval("Id") %>' />


<MonoX:FileGallery ID="ctlFileGalleryItem" runat="server" ParentEntityType="Message" ParentEntityId='<%# Eval("Id") %>' Visible='<%# AllowFileUpload %>' ViewFilePageId='<%# ViewFilePageId %>' ViewFilePageUrl='<%# ViewFilePageUrl %>' UsePrettyPhoto='<%# this.UsePrettyPhoto %>' Width="100%" />
</td>
</tr>
</table>
</ItemTemplate>
<ItemSeparatorTemplate>
<div style="width:94%;clear:both;border-bottom:1px dashed silver;padding-top: 2px;padding-bottom: 2px;height:5px;margin: 10px auto;"></div>
</ItemSeparatorTemplate>
</asp:ListView>
</div>
<div style="padding-left:15px;">
<mono:Pager runat="server" ID="pager" PageSize="20" NumericButtonCount="5" AllowCustomPaging="true" AutoPaging="false">
<PagerTemplate></PagerTemplate>
</mono:Pager>
</div>


<asp:Panel runat="server" ID="pnlContainer">
<div class="input-form reply-message">
<dl>
<dd>
<asp:Label ID="lblMessage" runat="server" AssociatedControlID="txtMessage"></asp:Label>
<asp:TextBox ID="txtMessage" Rows="8" TextMode="MultiLine" runat="server"></asp:TextBox>
</dd>
<asp:Panel runat="server" ID="pnlUpload" style="border:none;">
<dd>
<asp:Label ID="lblUpload" AssociatedControlID="ctlUpload" runat="server"></asp:Label>
<MonoX:SilverlightUpload runat="server" ID="ctlUpload" Width="100%" EnableFileGallery="false" /><br />
</dd>
<dd>
<asp:Label ID="lblFileGallery" AssociatedControlID="ctlFileGallery" runat="server"> </asp:Label>
<MonoX:FileGallery ID="ctlFileGallery" runat="server" ParentEntityType="Message" CssClass="rightLabel" />
</dd>
</asp:Panel>
<dd class="checkbox-messaging">
<asp:CheckBox BorderStyle="None" BorderWidth="0px" ID="chkSendMail" runat="server" TextAlign="Right" Checked="true"></asp:CheckBox>
<%= SocialNetworkingResources.Messaging_MessageDetails_SendMailCopy %>
</dd>
</dl>
<MonoX:StyledButton id="btnSend" runat="server" CausesValidation="false" CssClass="CssFormButton" OnClick="btnSend_Click" />
<MonoX:StyledButton id="btnCancel" runat="server" CausesValidation="false" CssClass="CssFormButton" OnClick="btnCancel_Click" />
</div>
<asp:Label runat="server" ForeColor="Red" ID="lblWarning"></asp:Label>
</asp:Panel>
</div>

My approach may be lacking in proper implementation and too simple but it seems to me it could work. Your feedback will be greatly appreciated.

Once I can get something like above to work I will implement logic so if Current User=Message Creator then cannot rate, etc.

4
12/21/2011 8:14:41 AM
15993 Reputation 2214 Total posts

Hi,

please try to replace your code with the below code, you need to use MessageId property rather then Id as it doesn't exist.

<MonoX:Rating ID="ctlRating" runat="server" ShowRatingHistory="true" ParentEntityType="Message" ParentEntityId='<%# Eval("MessageId") %>' />

Let us know if this works for you.

Regards

5
12/21/2011 2:23:03 PM
647 Reputation 69 Total posts

This does not work as <%# Eval("MessageId") %> is referring to an SnMessageEntity at runtime and snMeessageEntity does not have a MessageId property. It does have an Id property and I believe Id does contain the correct value at runtime. See my below test case where I output message id.

This is also evidenced in that the Rating control behaves as expected in it's initial Display, Rating History, etc seem correct. IT is just the action of Rating that appears to not work. No records are saved to database and control does not indicate any rating subsequent the postback call.


<td style="width: 100%;">
<pre style='white-space:pre-wrap;word-wrap:break-word;'><asp:Literal ID="ltlMessage" runat="server" Text='<%# Eval("Body") %>'></asp:Literal></pre>
<MonoX:FileGallery ID="ctlFileGalleryItem" runat="server" ParentEntityType="Message" ParentEntityId='<%# Eval("Id") %>' Visible='<%# AllowFileUpload %>' ViewFilePageId='<%# ViewFilePageId %>' ViewFilePageUrl='<%# ViewFilePageUrl %>' UsePrettyPhoto='<%# this.UsePrettyPhoto %>' Width="100%" />

<MonoX:Rating ID="ctlRating" runat="server" ShowRatingHistory="true" ParentEntityType="Message" ParentEntityId='<%# Eval("Id") %>' />
my MessageID=<%# Eval("Id") %>

</td>


6
12/22/2011 9:18:57 PM
15993 Reputation 2214 Total posts

Hi,

I tried to evaluate the MessageId on the MessageDetails as MessageId is the property of that control my mistake was that I used binding expression and not the inline render expression as I should. The correct code that you should use is as follows:

<MonoX:Rating ID="ctlRating" runat="server" ShowRatingHistory="true" ParentEntityType="Message" ParentEntityId='<%= Eval("MessageId") %>' />

Let me know if we have a proper result with this change.

Regards

7
12/23/2011 3:07:49 AM
647 Reputation 69 Total posts

I do not think this is correct as I get a build error...

Error 112 Cannot create an object of type 'System.Guid' from its string representation '<%= Eval("MessageId") %>' for the 'ParentEntityId' property.

I am pretty sure that at runtime the binding expression works given it is located in the ListView. The result is a rating control for each message in the message chain. That may or may not be a good idea but it would allow the user to rate an ewntire chain in the event they are viewing a message chain. My goal is to put in logic to show the rating control only on messages that you received, not sent, but that is not illustrated in my experiment shown below. I have provide complete markup so you see exactly what I am doing.


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MessageDetails.ascx.cs" Inherits="MonoSoftware.MonoX.ModuleGallery.SocialNetworking.MessageDetails" %>
<%@ Import Namespace="MonoSoftware.MonoX.Resources" %>
<%@ Register Namespace="MonoSoftware.Web.Pager" Assembly="MonoSoftware.Web.Pager" TagPrefix="mono" %>
<%@ Register TagPrefix="Mono" Assembly="MonoX" Namespace="MonoSoftware.MonoX.Blog" %>
<%@ Register TagPrefix="MonoX" TagName="SilverlightUpload" Src="/MonoX/ModuleGallery/SilverlightUploadModule.ascx" %>
<%@ Register TagPrefix="MonoX" TagName="FileGallery" Src="/MonoX/ModuleGallery/SocialNetworking/FileGallery.ascx" %>
<%@ Register TagPrefix="MonoX" TagName="StyledButton" Src="/MonoX/controls/StyledButton.ascx" %>


<%@ Import Namespace="MonoSoftware.MonoX.Utilities" %>
<%@ Import Namespace="MonoSoftware.MonoX.Repositories" %>
<%@ Import Namespace="MonoSoftware.MonoX.DAL.EntityClasses" %>
<%@ Import Namespace="MonoSoftware.MonoX.DAL.HelperClasses" %>
<%@ Import Namespace="MonoSoftware.MonoX.BusinessLayer" %>

<%@ Register TagPrefix="MonoX" TagName="Rating" Src="/MonoX/controls/MonoXRating.ascx" %>

<div style="border:solid 1px silver;">
<div style="font-size:150%;font-weight:bold;padding:10px;"><asp:Literal runat="server" ID="ltlSubject"></asp:Literal></div>
<div style="padding:5px;height:100%;width:100%;">


<asp:ListView ID="lvPosts" runat="server">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<table cellpadding="0" cellspacing="0" width="95%" class="message-details">
<tr>
<td style="width: 0%; text-align: center;">
<Mono:Gravatar ID="ctlGravatar" runat="server" Size="100" Email='<%# Eval("AspnetUser.Email") %>' UserName='<%# Eval("AspnetUser.UserName") %>' /><br />
<strong><asp:Literal ID="lblAuthor" runat="server" Text='<%# Eval("AspnetUser.UserName") %>'></asp:Literal></strong>
<div class="date"><asp:Literal ID="lblDate" runat="server" Text='<%# Eval("DateCreated") %>'></asp:Literal></div>
</td>
<td style="width: 100%;">
<pre style='white-space:pre-wrap;word-wrap:break-word;'><asp:Literal ID="ltlMessage" runat="server" Text='<%# Eval("Body") %>'></asp:Literal></pre>
<MonoX:FileGallery ID="ctlFileGalleryItem" runat="server" ParentEntityType="Message" ParentEntityId='<%# Eval("Id") %>' Visible='<%# AllowFileUpload %>' ViewFilePageId='<%# ViewFilePageId %>' ViewFilePageUrl='<%# ViewFilePageUrl %>' UsePrettyPhoto='<%# this.UsePrettyPhoto %>' Width="100%" />


<MonoX:Rating ID="ctlRating" runat="server"
ShowRatingHistory="true"
ParentEntityType="Message"
ParentEntityId='<%# Eval("Id") %>'
/>
My MessageID=<%# Eval("Id") %>
<br />


</td>
</tr>
</table>
</ItemTemplate>
<ItemSeparatorTemplate>
<div style="width:94%;clear:both;border-bottom:1px dashed silver;padding-top: 2px;padding-bottom: 2px;height:5px;margin: 10px auto;"></div>
</ItemSeparatorTemplate>
</asp:ListView>
</div>
<div style="padding-left:15px;">
<mono:Pager runat="server" ID="pager" PageSize="20" NumericButtonCount="5" AllowCustomPaging="true" AutoPaging="false">
<PagerTemplate></PagerTemplate>
</mono:Pager>
</div>


<asp:Panel runat="server" ID="pnlContainer">
<div class="input-form reply-message">
<dl>
<dd>
<asp:Label ID="lblMessage" runat="server" AssociatedControlID="txtMessage"></asp:Label>
<asp:TextBox ID="txtMessage" Rows="8" TextMode="MultiLine" runat="server"></asp:TextBox>
</dd>
<asp:Panel runat="server" ID="pnlUpload" style="border:none;">
<dd>
<asp:Label ID="lblUpload" AssociatedControlID="ctlUpload" runat="server"></asp:Label>
<MonoX:SilverlightUpload runat="server" ID="ctlUpload" Width="100%" EnableFileGallery="false" /><br />
</dd>
<dd>
<asp:Label ID="lblFileGallery" AssociatedControlID="ctlFileGallery" runat="server"> </asp:Label>
<MonoX:FileGallery ID="ctlFileGallery" runat="server" ParentEntityType="Message" CssClass="rightLabel" />
</dd>
</asp:Panel>
<dd class="checkbox-messaging">
<asp:CheckBox BorderStyle="None" BorderWidth="0px" ID="chkSendMail" runat="server" TextAlign="Right" Checked="true"></asp:CheckBox>
<%= SocialNetworkingResources.Messaging_MessageDetails_SendMailCopy %>
</dd>
</dl>
<MonoX:StyledButton id="btnSend" runat="server" CausesValidation="false" CssClass="CssFormButton" OnClick="btnSend_Click" />
<MonoX:StyledButton id="btnCancel" runat="server" CausesValidation="false" CssClass="CssFormButton" OnClick="btnCancel_Click" />
</div>
<asp:Label runat="server" ForeColor="Red" ID="lblWarning"></asp:Label>
</asp:Panel>
</div>

8
12/23/2011 8:11:32 AM
15993 Reputation 2214 Total posts

Ok, sorry I didn't noticed that so you should use the binding expression and you should bind to the Id as you did, but can you please check if the Rating event and Rated event are raised when you click the rate button ? This will signal us if everything is properly bound.

Other thing that may cause this issue is the MessageDetails binding which is executed only once, so when you perform the postback with rating control MessageDetail messages are not recreated and therefor rating control is not recreated so rating event is not raised. So please check above and get back to us.

Regards

9
12/23/2011 1:27:50 PM
647 Reputation 69 Total posts

That makes sense. it would seem the controls lose their values when rating occures. I will compose a more in depth usage and make sure the events are firing and have proper state.

Your advice is very helpful.

10
12/26/2011 9:08:19 PM
647 Reputation 69 Total posts

I am having no success at determining if the Rating and Rated events are firing. I copied the markup of MonoXRating.ascx to a custom ascx I named myMessageRating.ascx and changed to Inherits="a_myMessageRating".

Below is code for custom class. put breakpoints on all lines and tried to debug. The OnInit, OnLoad and OnPreRender all seem to execute as expected and the values of ParentEntityType and ParentEntityId are correct. My custom event handlers never get fired off.

My code may be totally wrong for trying to test the Rating and Rated events. Please advise.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using MonoSoftware.MonoX;
using MonoSoftware.MonoX.API;
using MonoSoftware.MonoX.Utilities;
using MonoSoftware.MonoX.Repositories;
using System.Configuration;
using MonoSoftware.MonoX.DAL.EntityClasses;
using MonoSoftware.LLBLGen;
using MonoSoftware.MonoX.DAL.HelperClasses;
using MonoSoftware.MonoX.BusinessLayer;
 
public partial class a_myMessageRating : MonoSoftware.MonoX.Controls.MonoXRating
{
        protected override void OnInit(EventArgs e)
        {
          base.Rating += new EventHandler<RatingEventArgs>(myRating);
          base.Rated += new EventHandler<MonoSoftware.Core.EventArgs<decimal>>(myRated);
          base.OnInit(e);
        }
        protected override void OnLoad(EventArgs e)
        {
               base.OnLoad(e);
         }
       protected override void OnPreRender(EventArgs e)
       {
              base.OnPreRender(e);
       }
       void myRated(object sender,  MonoSoftware.Core.EventArgs<decimal> e)
       {
             int i = 0;
       }
       void myRating(object sender, RatingEventArgs e)
       {
             int i = 0;
       }
  }

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