Exemple #1
0
        internal Post Edit(Post updated, string id)
        {
            Post original = GetPostsById(updated.Id);

            if (original.CreatorId != id)
            {
                throw new Exception("Access Denied: You cannot edit items you did not create.");
            }
            updated.Title = updated.Title == null ? original.Title : updated.Title;
            updated.Body  = updated.Body == null ? original.Body : updated.Body;
            updated.Img   = updated.Img == null ? original.Img : updated.Img;
            return(_repo.EditPost(updated));
        }
Exemple #2
0
 public ActionResult EditPost(Publicacao post, FormCollection collection, HttpPostedFileBase file)
 {
     try
     {
         // TODO: Add update logic here
         PostsRepository.EditPost(post, file);
         return(RedirectToAction("ListPosts", "Publicacao"));
     }
     catch
     {
         return(View());
     }
 }
 public ActionResult EditPost(Post post, FormCollection collection, HttpPostedFileBase file)
 {
     try
     {
         // TODO: Add update logic here
         if (file != null)
         {
             PostsRepository.EditPost(post, file);
         }
         else
         {
             PostsRepository.EditPostSemMudarImagem(post);
         }
         Usuario sessao = (Usuario)Session["object"];
         Session["object"] = UsuariosRepository.SelectUsuario(sessao.Id);
         return(RedirectToAction("ListPosts", "Post"));
     }
     catch
     {
         return(View("Error"));
     }
 }