Esempio n. 1
0
        public void kreirajBlog(BlogNew bn)
        {
            BlogPost bp = new BlogPost {
                Title = bn.title, Description = bn.description, Author = new ObjectId(bn.autorId)
            };
            var collection     = this.database.GetCollection <BlogPost>("blogovi");
            var collectionNova = this.database.GetCollection <User>("useri");

            collection.InsertOne(bp);
            ObjectId iod      = new ObjectId(bn.autorId);
            var      lista    = collectionNova.Find(x => x.Id == iod);
            User     korisnik = lista.ToList()[0];

            if (korisnik.Blogs != null)
            {
                korisnik.Blogs.Add(bp);
            }
            else
            {
                korisnik.Blogs = new List <BlogPost>();
                korisnik.Blogs.Add(bp);
            }

            var filter = Builders <User> .Filter.Eq("Id", iod);

            var update = Builders <User> .Update.Set("Blogs", korisnik.Blogs);

            collectionNova.UpdateOne(filter, update);
        }
Esempio n. 2
0
        public ActionResult AddBlog(FormCollection fc)
        {
            string  title    = fc["title"].ToString();
            string  opis     = fc["description"].ToString();
            string  authorID = mon.vratiUseraPoEmailu(fc["email"].ToString()).Id.ToString();
            BlogNew bn       = new BlogNew {
                title = title, description = opis, autorId = authorID
            };

            mon.kreirajBlog(bn);
            return(RedirectToAction("Details", "Profile", new { id = authorID }));
        }