我正在尝试制作一个显示成员的剃须刀模块,其中包括今天的周年纪念日,以及过去14天和接下来的14天。
我有一些帮助,但我们从未找到解决办法,现在我转向你们。
这是我到目前为止所得到的。没有被称为周年纪念的财产,我不知道,为什么他补充说。唯一的日期是dateHire和今天的日期。
问题在if语句之后开始。在此之前,属性是显示的,因此有数据。
@using System.Collections
@using Umbraco.Core;
@using Umbraco.Core.Models;
@using Umbraco.Core.Services;
@using Umbraco.Core.Persistence
@inherits umbraco.MacroEngines.DynamicNodeContext
<div id="ani">
<h6>Jubilæum</h6>
@{
IMemberService memberService = ApplicationContext.Current.Services.MemberService;
IEnumerable members = memberService.GetAllMembers();
string hireDate = String.Empty;
int memberId = 0;
string imageId = String.Empty;
string imageUrl = String.Empty;
string firstName = String.Empty;
string middleName = String.Empty;
string lastName = String.Empty;
foreach (IMember currentMember in members)
{
if(currentMember.HasProperty("DateHire"))
{
hireDate = umbraco.library.FormatDateTime(currentMember.GetValue("DateHire").ToString(), "d/M");
}
memberId = currentMember.Id;
if(currentMember.HasProperty("DateHire"))
{
imageId = currentMember.GetValue("Image").ToString();
}
if(currentMember.HasProperty("DateHire"))
{
firstName = currentMember.GetValue("NameFirst").ToString();
}
if(currentMember.HasProperty("DateHire"))
{
middleName = currentMember.GetValue("NameMiddle").ToString();
}
if(currentMember.HasProperty("DateHire"))
{
lastName = currentMember.GetValue("NameLast").ToString();
}
if(String.IsNullOrEmpty(imageId))
{
int outImageId;
Int32.TryParse(imageId, out outImageId);
if(outImageId > 0)
{
IMedia media = new Umbraco.Core.Services.MediaService(new RepositoryFactory()).GetById(outImageId);
imageUrl = media!= null ? media.GetValue("umbracoFile").ToString() : "/css/img/avatar.png";
}
}
@currentMember.Id <br>
@imageId <br>
@firstName <br>
@middleName <br>
@lastName <br><br>
DateTime currentDateTime = DateTime.Now;
DateTime outAnniversary = new DateTime();
if(currentMember.HasProperty("DateHire"))
{
hireDate = currentMember.GetValue("DateHire").ToString();
}
if(currentMember.HasProperty("anniversary"))
{
string anniversary = currentMember.GetValue("anniversary").ToString();
DateTime.TryParse(anniversary, out outAnniversary);
}
if (currentDateTime.Day == outAnniversary.Day)
{
<p>Today!</p>
@currentMember.Id <br>
@imageId <br>
@firstName <br>
@middleName <br>
@lastName <br><br>
}
else if((currentDateTime - outAnniversary).TotalDays < 14 && (currentDateTime - outAnniversary).TotalDays > 0)
{
<p>Going to happen</p>
@currentMember.Id <br>
@imageId <br>
@firstName <br>
@middleName <br>
@lastName <br><br>
}
else if((currentDateTime - outAnniversary).TotalDays > -14 && (currentDateTime - outAnniversary).TotalDays < 0)
{
<p>Has happend</p>
@currentMember.Id <br>
@imageId <br>
@firstName <br>
@middleName <br>
@lastName <br><br>
}
}
}
</div>
我希望你理解,否则就问!
非常感谢你的帮助! : - )