예제 #1
0
        public void SaveSyndicationList()
        {
            var syndication = new SyndicationList();
            syndication.Id = SyndicationList.NewId("dodyg").Full();
            syndication.Guid = Stamp.GUID().ToString();
            syndication.Name = "dodyg";
            syndication.Title = "Dody's Syndication Wall";
            syndication.Description = "Amazing Wall";
            syndication.Keywords = "dody, syndication";
            var opml = new Opml();
            opml.LoadFromXML(_sampleOPML);
            syndication.Sources = new RssSubscription(opml);

            using (var store = Raven.GetStoreFromServer())
            {
                using (var session = store.OpenSession(Raven.DATABASE_NAME))
                {
                    session.Store(syndication);
                    session.SaveChanges();
                }
            }
        }
예제 #2
0
        public ActionResult Create(BasicSyndicationListViewModel vm)
        {
            //this is for basic validation
            if (!ModelState.IsValid)
                return View(vm);

            var existingSyndication = RavenSession.Query<SyndicationList>().Where(x => x.Name == vm.Name).FirstOrDefault();

            if (existingSyndication != null)
                this.PropertyValidationMessage("Name", string.Format("Please pick another name. {0} has already been taken.", vm.Name));

            //do another check after this 'advanced' validation
            if (!ModelState.IsValid)
                return View(vm);

            var list = new SyndicationList();
            list.Id = SyndicationList.NewId(vm.Name).Full();
            list.Guid = Stamp.GUID().ToString();
            list.Name = vm.Name;
            list.Title = vm.Title;
            list.Description = vm.Description;
            list.Keywords = vm.Keywords;

            RavenSession.Store(list);

            //take care of the temporary account

            var transient = CookieMonster.GetFromCookie<TransientAccount>(Request.Cookies[TransientAccount.COOKIE_NAME]);
            if (!transient.IsFound)
            {
                var init = new TransientAccount();
                init.SyndicationGuids.Add(list.Guid);
                init.MarkUpdated();
                Response.Cookies.Add(CookieMonster.SetCookie(init, TransientAccount.COOKIE_NAME));
            }
            else
            {
                transient.Item.SyndicationGuids.Add(list.Guid);
                transient.Item.MarkUpdated();
                Response.Cookies.Add(CookieMonster.SetCookie(transient.Item, TransientAccount.COOKIE_NAME));
            }

            this.RavenSession.SaveChanges();

            return RedirectToAction("Sources", new { guid = list.Guid });
        }