Пример #1
0
 public JsonResult GetInspiration()
 {
     var wishes = WAFContext.Session.GetContents<Wish>();
     var count = wishes.Count();
     var rand = new System.Random();
     var randomWish = wishes.Skip(rand.Next(count)).FirstOrDefault();
     var inspiration = new InspirationJSON { Title = randomWish.Name, Signature = "Brudepar", Link = randomWish.HyperLink.GetUrl() };
     return Json(inspiration, JsonRequestBehavior.AllowGet);
 }
Пример #2
0
        public static List<InspirationJSON> GetInspiration()
        {
            var q = WAFContext.Session.CreateQuery();

            var aOccasion = new AqlAliasWishListOccasion();
            var aWls = new AqlAliasWishList();
            var aWish = new AqlAliasWish();

            var join1 = new AqlAliasRelThemeWishList(aOccasion, aWls);
            var join2 = new AqlAliasRelWishListWishes(join1, aWish, aWls);

            q.From(join2);

            var rOccasion = q.Select(aOccasion.Name);
            var rGender = q.Select(aWls.Gender);
            var rBirthYear = q.Select(aWls.BirthYear);
            var rTitle = q.Select(aWish.Name);
            var rHyperLink = q.Select(aWish.HyperLink);
            var rs = q.Execute();

            List<InspirationJSON> jsonList = new List<InspirationJSON>();
            while (rs.Read())
            {
                InspirationJSON ij = new InspirationJSON();

                ij.Title = rTitle.Value;
                ij.Occasion = rOccasion.Value;

                if (2 == rGender)
                {
                    ij.Gender = "Female";
                }
                else
                {
                    ij.Gender = "Male";
                }

                if (rHyperLink.Value != null && rHyperLink.Value != "")
                {
                    ij.Link = rHyperLink.Value;

                    if (ij.Link.Length < 30)
                    {
                        ij.LinkShort = ij.Link;
                    }
                    else
                    {
                        ij.LinkShort = ij.Link.Substring(0, 27) + "...";
                    }
                }

                int thisYear = DateTime.Today.Year;
                int birthYear = 0;
                if (int.TryParse(rBirthYear.ToString(), out birthYear))
                {
                    birthYear = rBirthYear;
                }
                else
                {
                    birthYear = thisYear - 30;
                }

                ij.Age = (thisYear - birthYear);

                if ("Bryllup" == ij.Occasion)
                {
                    ij.Signature = "Brudepar";
                }
                else if ("Dåp" == ij.Occasion)
                {
                    ij.Signature = "Dåpsbarn";
                }
                else if ("Babyshower" == ij.Occasion)
                {
                    ij.Signature = "Babyshower";
                }
                else if ("Konfirmasjon" == ij.Occasion)
                {
                    ij.Signature = "Konfirmant";
                }
                else
                {
                    String outGender = "";

                    if ("Female" == ij.Gender && ij.Age < 17)
                    {
                        outGender = "Jente";
                    }
                    else if ("Female" == ij.Gender)
                    {
                        outGender = "Kvinne";
                    }
                    else if ("Male" == ij.Gender && ij.Age < 17)
                    {
                        outGender = "Gutt";
                    }
                    else if ("Male" == ij.Gender)
                    {
                        outGender = "Mann";
                    }

                    ij.Signature = outGender + ", " + ij.Age + " år";
                }

                jsonList.Add(ij);
            }

            return jsonList;
        }