コード例 #1
0
ファイル: Translator.cs プロジェクト: kyvkri/MG
        public static List<WishListJSON> translate(List<WishList> wls)
        {
            List<WishListJSON> wlsJson = new List<WishListJSON>();
            foreach (WishList wl in wls)
            {
                int numComments = 0;
                WishListJSON wlJson = new WishListJSON();

                wlJson.nodeId = wl.NodeId;
                wlJson.name = wl.Name;
                if (wl.Status == Status.Private)
                {
                    wlJson.status = "Lukket";
                }
                else
                {
                    wlJson.status = "Delt";
                }
                wlJson.createDate = wl.CreateDate.ToShortDateString();
                wlJson.description = wl.Description;
                wlJson.views = wl.Views;
                wlJson.birthYear = wl.BirthYear;
                wlJson.url = WAFContext.GetUrl(wl.NodeId);

                foreach (WishJSON wish in translate(wl.Wishes.Get(), wl.NodeId))
                {
                        numComments += wish.comments.Count;
                }
                wlJson.comments = numComments;
                wlsJson.Add(wlJson);
            }

            return wlsJson;
        }
コード例 #2
0
ファイル: WishListController.cs プロジェクト: kyvkri/mg-git
        public JsonResult GetWishList(int nodeId, String authkey)
        {
            WishList currentWishList = WAFRuntime.SystemSession.GetContent<WishList>(nodeId);
            WishListJSON wlJson = new WishListJSON();

            // Authkey OK
            if (currentWishList.Guid.ToString() == authkey)
            {
                wlJson = Translator.TranslateWl(currentWishList);
                currentWishList.Views += 1;
                currentWishList.UpdateChanges();
            }
            // Owner?
            else if (! WAFContext.Session.IsAnonymous())
            {
                UserMG user = (UserMG) WAFContext.Session.GetUser();
                List<WishList> wls = user.WishLists.Query<WishList>().Where(AqlWishList.NodeId == nodeId).Execute(1);
                if (wls != null || wls.Count > 0)
                {
                    wlJson = Translator.TranslateWl(currentWishList);
                }
            }

            return Json(wlJson, JsonRequestBehavior.AllowGet);
        }
コード例 #3
0
ファイル: Translator.cs プロジェクト: kyvkri/mg-git
        public static WishListJSON TranslateWl(WishList wl)
        {
            WishListJSON wlJson = new WishListJSON ();

            int numComments = 0;

            wlJson.nodeId = wl.NodeId;
            wlJson.name = wl.Name;
            if (wl.Status == Status.Private)
            {
                wlJson.status = "Lukket";
            }
            else
            {
                wlJson.status = "Delt";
            }
            wlJson.authKey = wl.Guid.ToString();
            wlJson.createDate = wl.CreateDate.ToShortDateString();
            wlJson.description = wl.Description;
            wlJson.views = wl.Views;
            wlJson.birthYear = wl.BirthYear;
            wlJson.gender = wl.Gender.ToString();
            wlJson.url = WAFContext.GetUrl(wl.NodeId);
            if (wl.Occasion.IsSet())
            {
                wlJson.occasionId = wl.Occasion.GetId().ToString();
            }
            foreach (WishJSON wish in TranslateWishes(wl.Wishes.Get(), wl.NodeId))
            {
                numComments += wish.comments.Count;
            }
            wlJson.comments = numComments;

            return wlJson;
        }