Пример #1
0
        public ActionResult Create(Comments comment)
        {
            try
            {
                using (ISession session = NHibernateSession.OpenSession())
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Save(comment);
                        transaction.Commit();
                    }
                }

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                return View();
            }
        }
Пример #2
0
        public ActionResult Delete(int id, Comments comment)
        {
            try
            {
                using (ISession session = NHibernateSession.OpenSession())
                {
                    var commentToDelete = session.Get<Comments>(id);

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Delete(commentToDelete);
                        transaction.Commit();
                    }
                }

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                return View();
            }
        }
        public IHttpActionResult Post(Comments comment)
        {
            try
            {
                using (ISession session = NHibernateSession.OpenSession())
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {

                        session.Save(comment);
                        transaction.Commit();
                    }
                }

                //return Ok();
                return Redirect("api/CommentsAPI"); //provjeriti

            }
            catch (Exception ex)
            {
                return Ok(ex.StackTrace.ToString());
            }
        }
Пример #4
0
        public ActionResult Edit(int id, Comments comment)
        {
            try
            {
                using (ISession session = NHibernateSession.OpenSession())
                {
                    var commentToUpdate = session.Get<Comments>(id);

                    commentToUpdate.CommentID = id;
                    commentToUpdate.CommentNumber = comment.CommentNumber;
                    commentToUpdate.CommentText = comment.CommentText;
                    commentToUpdate.CommentAuthorName = comment.CommentAuthorName;
                    commentToUpdate.CommentAuthorPicture = comment.CommentAuthorPicture;
                    commentToUpdate.CommentDayAndDate = comment.CommentDayAndDate;
                    commentToUpdate.CommentPlus = comment.CommentPlus;
                    commentToUpdate.CommentMinus = comment.CommentMinus;
                    commentToUpdate.CommentParentNumber = comment.CommentParentNumber;
                    commentToUpdate.CommentLevel = comment.CommentLevel;

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Save(commentToUpdate);
                        transaction.Commit();
                    }
                }
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                return View();
            }
        }
 // PUT: api/CommentsAPI/5
 public IHttpActionResult Put(int id, Comments comment)
 {
     return Ok();
 }