Exemplo n.º 1
0
        public ActionResult AddBlog(BlogVM model)
        {
            EFBlogRepo repo = new EFBlogRepo();

            model.Blog.Author = User.Identity.Name;
            model.Blog.Date   = DateTime.Now;

            if (model.File != null)
            {
                //create new folder for blog images
                string title      = model.Blog.Title.Replace(" ", "_");
                string pathString = Server.MapPath("~//img//blogimages");
                pathString += "//" + title;
                System.IO.Directory.CreateDirectory(pathString);

                string pic  = Path.GetFileName(model.File.FileName);
                string path = Path.Combine(
                    Server.MapPath("~//img//blogimages//" + title), pic);

                model.Blog.FeatureImageLocation = path;
                // file is uploaded
                model.File.SaveAs(path);
            }

            model.Blog.BlogCategories = new List <Category>();

            foreach (var id in model.SelectedCategoryIds)
            {
                model.Blog.BlogCategories.Add(repo.GetCategory(id));
            }

            repo.AddBlog(model.Blog);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult AddCategory(string command, Category model)
        {
            if (command == "Cancel")
            {
                return(RedirectToAction("Index"));
            }
            if (command == "Submit")
            {
                EFBlogRepo repo = new EFBlogRepo();
                repo.AddNewCategory(model.CategoryName);

                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }