Esempio n. 1
0
        public ActionResult Create([Bind(Include = "ID,clientId,GenreID,Title,Content")] Post post)
        {
            if (post.Content != null && post.Title != null && post.GenreID != 0)
            {
                if (AuthorizationMiddleware.Authorized(Session))
                {
                    if (ModelState.IsValid)
                    {
                        post.CreationDate = DateTime.Now;
                        db.Posts.Add(post);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }

                    ViewBag.ClientID = new SelectList(db.Clients, "ID", "ClientName", post.ClientID);
                    ViewBag.GenreID  = new SelectList(db.Genres, "ID", "Name", post.GenreID);
                    return(View(post));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 2
0
        public ActionResult PostComment(int clientId, int postId, string content)
        {
            if (AuthorizationMiddleware.Authorized(Session))
            {
                Comment comment = new Comment
                {
                    Content      = content,
                    ClientID     = clientId,
                    PostID       = postId,
                    CreationDate = DateTime.Now
                };

                if (content != string.Empty)
                {
                    db.Comments.Add(comment);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (AuthorizationMiddleware.Authorized(Session))
            {
                Post post = db.Posts.Find(id);

                // Getting all the comments of the post
                List <Comment> lstRemove = new List <Comment>();
                lstRemove = db.Comments.Where(x => x.Post.ID == id).ToList();

                // Removing all the comments of that post
                foreach (Comment cur in lstRemove)
                {
                    Comment comment = db.Comments.Find(cur.ID);
                    db.Comments.Remove(comment);
                }

                db.Posts.Remove(post);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 4
0
 // GET: Posts/Create
 public ActionResult Create()
 {
     if (AuthorizationMiddleware.Authorized(Session))
     {
         ViewBag.ClientID = new SelectList(db.Clients, "ID", "ClientName");
         ViewBag.GenreID  = new SelectList(db.Genres, "ID", "Name");
         return(View());
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Esempio n. 5
0
 public ActionResult DeleteConfirmed(int id)
 {
     if (AuthorizationMiddleware.Authorized(Session))
     {
         Comment comment = db.Comments.Find(id);
         db.Comments.Remove(comment);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Esempio n. 6
0
 public ActionResult Edit([Bind(Include = "ID,ClientID,PostID,Content,CreationDate")] Comment comment)
 {
     if (AuthorizationMiddleware.Authorized(Session))
     {
         if (ModelState.IsValid)
         {
             db.Entry(comment).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewBag.ClientID = new SelectList(db.Clients, "ID", "ClientName", comment.ClientID);
         ViewBag.PostID   = new SelectList(db.Posts, "ID", "Content", comment.PostID);
         return(View(comment));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Esempio n. 7
0
 // GET: Posts/Delete/5
 public ActionResult Delete(int?id)
 {
     if (AuthorizationMiddleware.Authorized(Session))
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         Post post = db.Posts.Find(id);
         if (post == null)
         {
             return(HttpNotFound());
         }
         return(View(post));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Esempio n. 8
0
 // GET: Posts/Edit/5
 public ActionResult Edit(int?id)
 {
     if (AuthorizationMiddleware.Authorized(Session))
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         Post post = db.Posts.Find(id);
         if (post == null)
         {
             return(HttpNotFound());
         }
         ViewBag.ClientID = new SelectList(db.Clients, "ID", "ClientName", post.ClientID);
         ViewBag.GenreID  = new SelectList(db.Genres, "ID", "Name", post.GenreID);
         return(View(post));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }