Create the evaluator class
After you prepare the project, you implement the evaluator class. The evaluator class is a class that is used to determine whether the current user is a match for the specified criterion.
The evaluator class must implement the ICriterionEvaluator interface. To create the evaluator class:
- In Visual Studio, open the context menu of the DayOfWeekPersonalization project and click Add » Class.
- Name the class file
DayOfWeekEvaluator.csand click Add. - Make the
DayOfWeekEvaluatorclass implement theICriterionEvaluatorinterface. - Define the
CurrentDayOfWeekproperty.
You get the current day of the week represented as aSystem.DayOfWeekenum, convert it to an integernumber and then return the value. - Implement the
ICriterionEvaluatorinterface.
The value of the current day of the week is compared with the value that you configure as a criterion. If the values match, the personalized version of the page is displayed. Otherwise, the default page is displayed.
Use the following code sample:
C#
using System;
using Telerik.Sitefinity.Personalization;
namespace SitefinityWebApp
{
public class DayOfWeekEvaluator : ICriterionEvaluator
{
protected virtual int CurrentDayOfWeek
{
get
{
DateTime currentDay = DateTime.Now;
int currentDayOfWeek = (int)currentDay.DayOfWeek;
return currentDayOfWeek;
}
}
public bool IsMatch(string settings, IPersonalizationTestContext testContext)
{
if (settings == this.CurrentDayOfWeek.ToString())
{
return true;
}
else
{
return false;
}
}
}
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.