Examples of Code portlets

In ELMA you can create custom portlets by writing their content in Razor.

Razor markup language combines C# and HTML and allows working with system objects.

To create such a portlet, add a Code type portlet to a page. Click on the edit icon. In the opened portlet settings window, click Open markup editor, which will open the editor in a new tab.

To add a C# code line, use the @ character. For example:

<p>
Current time :@DateTime.Now
</p>
 

To add a C# code block, use the @{…} structure. Example:

@{
if(condition)
   {
   code
   }
}
 

For more information, follow this link: http://msdn.microsoft.com/en-us/VS2010TrainingCourse_ASPNETMVC3Razor

Consider examples of Code type portlets.

Example 1. Approval tasks. In this example, the portlet will display approval tasks, in which the current user is the approver.

@using EleWise.ELMA.Security.Models
@using EleWise.ELMA.Security.Services
@using EleWise.ELMA.Tasks.Models
@using EleWise.ELMA.Model.Services;
@using EleWise.ELMA.Model.Managers
@using EleWise.ELMA.Tasks.Managers;
@using EleWise.ELMA.Documents.Models.Tasks
@{  
 
  //create variables for storing static links
  //For document approval
  var DocRef = "http://127.0.0.1:8007/Docflow/Approvement/Execute/";
  //for tasks
  var TaskRef = "http://127.0.0.1:8007/Tasks/Task/Approve/";
  //identify the current user
  var CurUser = (User)AuthenticationService.GetCurrentUser<EleWise.ELMA.Security.Models.IUser>();
//create a filter for an approval task
  var TaskFilter = InterfaceActivator.Create<ApprovalTaskFilter>();
  //specify the statuses of the active tasks
TaskFilter.Statuses=TaskBaseExtensions.ActiveTaskStatuses.ToList(); 
// foreach(var t in TaskBaseExtensions.ActiveTaskStatuses)
// {TaskFilter.Statuses.Add(t);}
  //specify the current user as the approver
  TaskFilter.Query = "Harmonizator="+CurUser;
  //select data by filter
  var ActiveApprove = ApprovalTaskManager.Instance.Find(TaskFilter, null);
  //create a filter for a document approval task
  var DocumentTaskFilter = InterfaceActivator.Create<DocumentApprovementTaskFilter>();
  DocumentTaskFilter.Statuses=TaskBaseExtensions.ActiveTaskStatuses.ToList(); 
  //specify the statuses of the active tasks
// foreach(var w in TaskBaseExtensions.ActiveTaskStatuses)
// {DocumentTaskFilter.Statuses.Add(w);}
  //specify the current user as the approver
  DocumentTaskFilter.Query = "Harmonizator="+CurUser;
  //select data by the filter
  var ActiveDocumentApprove = EntityManager<DocumentApprovementTask>.Instance.Find(DocumentTaskFilter, null);
   
}
  @{
  foreach(var item in ActiveDocumentApprove)
  {
   //generate a link from the created variables and IDs of the found tasks
   <p><a href=@DocRef@item.Id>Согласование документа - @item.Subject</a></p>
  }
  }
  @{
  foreach(var item in ActiveApprove)
  {
   <p><a href=@TaskRef@item.Id>@item.Subject</a></p>
  }
  }
 
Result:
 

Example 2. My contractors. The portlet will display the contractors, for which the current user is responsible and all the contractors created for the current day, regardless of the responsible user.

@using EleWise.ELMA.Security.Models
@using EleWise.ELMA.Security.Services
@using EleWise.ELMA.Documents.Models
@using EleWise.ELMA.Documents.Models.Tasks
@using EleWise.ELMA.CRM.Managers
@using EleWise.ELMA.CRM.Models
@using EleWise.ELMA.Model.Services;
@using EleWise.ELMA.Model.Managers
@using EleWise.ELMA.Tasks.Managers
@using EleWise.ELMA.Tasks.Models
@using EleWise.ELMA.Workflow.Managers
@using EleWise.ELMA.Model.Ranges;
@using EleWise.ELMA.Workflow.Models
 
<h1>My contractors</h1>
@{
    //generate a link, find the required objects
    var KontrRef = "http://127.0.0.1:8007/CRM/ContractorLegal/Details/";
    var CurUser = (User)AuthenticationService.GetCurrentUser<EleWise.ELMA.Security.Models.IUser>();
     
    //create a filter for a contractor
    var contractorFilter = InterfaceActivator.Create<ContractorFilter>();
    //specify the current user as the responsible in the filter
    contractorFilter.Responsible = CurUser;
    //find contractors by filter
    var MyKontr = ContractorManager.Instance.Find(contractorFilter, null);
    foreach(var item in MyKontr)
    {
     <p><a href=@KontrRef@item.Id>@item.Name</a></p>
    }
  
    <h1>New contractors</h1>
      
    //only contractors, created on the current day (regardless of the responsible user)
    var conCreateTodayFilter = InterfaceActivator.Create<ContractorFilter>();
    
    var createdate = new DateTimeRange();
    createdate.From = DateTime.Now.Date;
    conCreateTodayFilter.CreationDate = createdate;
    var NewKontr = ContractorManager.Instance.Find(conCreateTodayFilter, null);
    foreach(var item in NewKontr)
    {
     <p><a href=@KontrRef@item.Id>@item.Name</a></p>
    }
}
 
Result:
 

Example 3. Portlet for managers: Task execution control. This portlet will display the tasks that the executor has not opened for more than 24 hours. The tasks are divided into process and user tasks, the result is displayed in a table.

@using EleWise.ELMA.Model.Managers
@using EleWise.ELMA.Tasks.Models
@using EleWise.ELMA.Model.Services
@using EleWise.ELMA.Model.Ranges
@using EleWise.ELMA.Workflow.Managers
@using EleWise.ELMA.Tasks.Managers;
@using EleWise.ELMA.Projects.Models;
@using EleWise.ELMA.Projects.Managers;
@using EleWise.ELMA.Workflow.Models;
@{   
    var TaskRef = "http://127.0.0.1:8007/Tasks/Task/Execute/";
    var taskFilter = InterfaceActivator.Create<TaskFilter>();
    taskFilter.Status = TaskBaseStatus.NewOrder;
    taskFilter.Query="CreationDate in RelativeDateTime(’’,’0d’) ";
     
    var FreshNewTasks = TaskManager.Instance.Find(taskFilter, null);
  
}
<TABLE border="1" ALIGN=TOP WIDTH=100% >
  
<UL>
<TR>
  
 <TD width="250" VALIGN=TOP><H3>Tasks without activity for more than one day</H3>
 </TD>
 <TD width="250" VALIGN=TOP>
 @{
   foreach(var item in FreshNewTasks)
   {
        <li><a href=@TaskRef@item.Id>@item.Subject</a></li>
   }
 }
@{
   //If there aren't required tasks, add the respective comment
      if(FreshNewTasks.Count <= 0)
   {
     
<p align="center">No tasks with the "New" status</p>
 }}
</TD>
<TD width="250" VALIGN=TOP>
 @{
   foreach(var item in FreshNewTasks)
   {
        <li>@item.CreationDate.Value.ToString().Substring(0,16)</li>
   }
 }
 
</TD>
</UL>
</TR>
 @{
  
    var WTRef = "http://127.0.0.1:8007/Workflow/WorkflowTask/Execute/";
    var wftaskFilter = InterfaceActivator.Create<WorkflowTaskFilter>();
    wftaskFilter.Status = TaskBaseStatus.NewOrder;
    wftaskFilter.Query="CreationDate in RelativeDateTime(’’,’0d’) ";
     
  
    var FreshNewWT = WorkflowTaskManager.Instance.Find(wftaskFilter, null);
}
<UL>
<TR>
 <TD width="250" VALIGN=TOP> <H3> Process tasks without activity for more than one day</H3></TD> 
 <TD width="250" VALIGN=TOP>
 @{
   foreach(var item in FreshNewWT)
   {
        <li> <a href=@WTRef@item.Id>@item.Subject</a></li>
   }
 }
  
  @{
      if(FreshNewWT.Count <= 0)
   {
<p align="center">No tasks with the "New" status</p>
   }
} 
</TD>
<TD width="250" VALIGN=TOP>
 @{
   foreach(var item in FreshNewWT)
   {
        <li>@item.CreationDate.Value.ToString().Substring(0, 16)</li>
   }
 }
</TD>
</UL>
</TR>
</TABLE>
 
Result: