예제 #1
0
        public bool InsertPost(KlasaPomocnicza NowyObiekt)
        {
            try
            {
                Post p = new Post();
                p.data_modyfikacji = NowyObiekt.data_modyfikacji;
                p.data_dodania = NowyObiekt.data_dodania;
                p.tresc = NowyObiekt.tresc;
                p.tytul = NowyObiekt.tytul;
                p.status = 1;

                db.Posts.InsertOnSubmit(p);
                db.SubmitChanges();

                Tag t = new Tag();
                t.id_posta = p.id;
                t.description = NowyObiekt.description;
                t.keywords = NowyObiekt.keywords;

                db.Tags.InsertOnSubmit(t);
                db.SubmitChanges();

                return true;
            }
            catch (Exception ) { return false; }
        }
예제 #2
0
 public ActionResult edytuj(Post post)
 {
     ViewData["post"] = db_admin.edytuj(post.id);
     if (db_admin.ZapiszZmiany(post))
     {
         ViewData["alert"] = "zmiany ok";
         return View();
     }
     else
     {
         ViewData["alert"] = "zmiany zakonczyly sie niepowodzeniem";
         return View();
     }
 }
예제 #3
0
 public void Remove(Post post)
 {
     try
     {
         using (ISession session = NHibernateHelper.AbreSession())
         {
             ITransaction tx = session.BeginTransaction();
             session.Delete(post);
             tx.Commit();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #4
0
        static void Main(string[] args)
        {
            Post post = new Post()
            {
                Id = 2,
                Titulo = "Meu primeiro post 12",
                Conteudo = "Conteudo do post 12",
                DataPublicacao = DateTime.Now,
                Publicado = true
            };

            PostDAO dao = new PostDAO();
            dao.Atualiza(post);
            Console.WriteLine("Atualizei: " + post.Id);

            post.Id = 0;
            dao.Adiciona(post);
            Console.WriteLine("Adicionei: " + post.Id);

            IList<Post> posts = dao.Lista();

            foreach (var pst in posts)
            {
                Console.WriteLine("encontrei: " + pst.Id + " - " + pst.Titulo);
            }

            Post p = dao.BuscaPorId(post.Id);

            if (p != null)
            {
                Console.WriteLine("removi: " + p.Id);
                dao.Remove(p);
            }

            Console.ReadKey();
        }
예제 #5
0
        public bool ZapiszZmiany(Post new_post)
        {
            try{
              Post post = db.Posts.Single(p => p.id == new_post.id);
            post.tytul = new_post.tytul;
            post.tresc = new_post.tresc;
            post.data_dodania = DateTime.Now;
            db.SubmitChanges();
            return true;

              }
            catch(Exception) {return false;}
        }