Example #1
0
        public NewBlogArticleViewModel GetCategoryList()
        {
            var categories = _topBloggersDb.Categories.ToList();

            var model = new NewBlogArticleViewModel
            {
                Categories = categories
            };

            return(model);
        }
Example #2
0
        public ActionResult Create()
        {
            var email  = (string)Session["AUTHOR"];
            var author = _accountService.GetAuthorDashboard(email).Author;
            var list   = _accountService.GetCategoryList().Categories;

            if (email == null)
            {
                return(RedirectToAction("Login"));
            }

            var model = new NewBlogArticleViewModel
            {
                Author     = author,
                Categories = list
            };

            return(View(model));
        }
Example #3
0
        public ActionResult Create([Bind(Include = "Title,Description,Text,AuthorID,CategoryID")] Article article, HttpPostedFileWrapper file)
        {
            var email  = (string)Session["AUTHOR"];
            var author = _accountService.GetAuthorDashboard(email).Author;
            var list   = _accountService.GetCategoryList().Categories;

            try
            {
                if (ModelState.IsValid)
                {
                    _accountService.CreateNewBlogArticle(article, file);

                    return(RedirectToAction("Dashboard"));
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }

            var model = new NewBlogArticleViewModel
            {
                Author     = author,
                Categories = list
            };

            return(View(model));
        }