Ejemplo n.º 1
0
        public ActionResult CreateArticle()
        {
            var viewModel = new RegisterArticleViewModel
            {
                Title = "Create Article",
                EditMode = false,
                PostAction = "CreateArticle",
                Article = new Article()

            };
            return View("CreateArticle", viewModel);
        }
Ejemplo n.º 2
0
        public ActionResult EditArticle(RegisterArticleViewModel viewModel, HttpPostedFileBase image)
        {
            try
            {
                bool test = ModelState.IsValid;

                List<Tuple<string, string>> errors = articleManager.ValidateArticle(viewModel.Article);
                if (errors.Count == 0)
                {
                    viewModel.Article.ModificationdDate = DateTime.Now;
                    viewModel.Article.CreationDate = DateTime.Now;
                    //article.Layout = ViewBag.Layout;
                    //article.Type = ViewBag.Type;
                    if (image != null)
                    {
                        var imageData = new byte[image.ContentLength];
                        image.InputStream.Read(imageData, 0, image.ContentLength);
                        articleManager.UpdateArticle(viewModel.Article, imageData);
                    }
                    else
                    {
                        articleManager.UpdateArticle(viewModel.Article, null);
                    }
                    return RedirectToAction("ArticleView", new { id = viewModel.Article.Id });
                }
                else
                {
                    foreach (Tuple<string, string> t in errors)
                    {
                        ModelState.AddModelError(t.Item1, t.Item2);
                    }
                    return View(viewModel);
                }
            }
            catch (Exception e)
            {
                ViewBag.ErrorTitle = "Server Error";
                ViewBag.ErrorDescription = "Please try again later";
                return View("~/Views/Shared/ErrorPage.cshtml");
            }
        }
Ejemplo n.º 3
0
 public ActionResult EditArticle(int articleId)
 {
     try
     {
         var article = articleManager.GetArticleById(articleId);
         var viewModel = new RegisterArticleViewModel
         {
             Article = article,
             Title = "Edit Article",
             EditMode = true,
             PostAction = "EditArticle",
         };
         return View("CreateArticle", viewModel);
     }
     catch (Exception e)
     {
         ViewBag.ErrorTitle = "Server Error";
         ViewBag.ErrorDescription = "Please try again later";
         return View("~/Views/Shared/ErrorPage.cshtml");
     }
 }