private static string GetAge(WebsiteResident resident) { if (resident.Birthday != DateTime.MinValue) { var years = (DateTime.Now - resident.Birthday).TotalDays/365.2425; return years.ToString().Split(',')[0]; } else { return "Vides ikke"; } }
public static WebsiteResident Map(IPublishedContent content) { var model = new WebsiteResident { ResidentName = content.GetProperty("navn") != null ? content.GetPropertyValue<string>("navn") : string.Empty, Birthday = content.GetProperty("foedselsdato") != null ? content.GetPropertyValue<DateTime>("foedselsdato") : DateTime.MinValue, WorkTitle = content.GetProperty("beskaeftigelse") != null ? content.GetPropertyValue<string>("beskaeftigelse") : string.Empty, SpareTime = content.GetProperty("fritid") != null ? content.GetPropertyValue<string>("fritid") : string.Empty, Motto = content.GetProperty("motto") != null ? content.GetPropertyValue<string>("motto") : string.Empty, Image = content.GetProperty("beboerbillede") != null ? content.GetPropertyValue<string>("beboerbillede") : string.Empty, ShowInPhonelist = content.GetProperty("showOnPhonelist") != null && content.GetPropertyValue<bool>("showOnPhonelist"), PrivateEmail = content.GetProperty("privatEmail") != null ? content.GetPropertyValue<string>("privatEmail") : string.Empty, Mobile = content.GetProperty("mobil") != null ? content.GetPropertyValue<string>("mobil") : string.Empty, Phone = content.GetProperty("telefon") != null ? content.GetPropertyValue<string>("telefon") : string.Empty, WorkEmail = content.GetProperty("arbejdsEmail") != null ? content.GetPropertyValue<string>("arbejdsEmail") : string.Empty, WorkPhone = content.GetProperty("arbejdsTelefon") != null ? content.GetPropertyValue<string>("arbejdsTelefon") : string.Empty, Notes = content.GetProperty("noter") != null ? content.GetPropertyValue<string>("noter") : string.Empty }; model.Age = GetAge(model); return model; }