I am trying to make a razor module that displays the members, whos anniversary is today, but also from the last 14 days and the next 14 days.

I have had some help, but we never found a solution and now I turn to you guys.

This is what I got so far. There is NO property called anniversary and I dont know, why he added it. The only date is dateHire and todays date.

The problem starts after with the if statement. Before that, the properties are diplayed, so there is data.

@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>

I hope you understand, else just ask!

Thank you so much for your help! :-)

Related posts

Recent Viewed