Ejemplo n.º 1
0
        public ActionResult Edit(int? id)
        {
            Post post = _db.GetPost(id);

            EditPostViewModel model = new EditPostViewModel
            {
                Id = post.Id,
                Title = post.Title,
                Date = post.Date,
                Body = post.Body,
                Preview = post.Preview,
                PhotoPath = post.PhotoPath

            };

            StringBuilder tagList = new StringBuilder();
            foreach (Tag tag in post.Tags)
            {
                tagList.AppendFormat("{0} ", tag.Name);
            }

            ViewBag.Tags = string.IsNullOrEmpty(tagList.ToString()) ? "" : tagList.ToString();

            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult Edit(EditPostViewModel model, DateTime date, string tags, HttpPostedFileBase file)
        {
            //Unnecessary right now.
            //bool validateTitle = _db.ValidateDuplicateTitle(model.Title);

            if (ModelState.IsValid)
            {
                PostBLL postBLL = new PostBLL();
                string photoPath = ImageUtility.UpdatePhoto(file, ImagePath.BlogPostImage);
                Post post = postBLL.UpdatePost(model.Id, model.Title, model.Body, date, tags, photoPath);
                return RedirectToAction("Post", new { UrlTitle = post.UrlTitle });

            }

            //Something went wrong
            model.Date = date;
            model.File = file;
            ViewBag.Tags = tags;
            return View(model);
        }