Пример #1
0
        public ActionResult SaveNewBlog(BlogFormViewModel blog)
        {
            if (blog.File != null && blog.File.ContentLength > 0)
            {
                string userId = User.Identity.GetUserId();

                string folderDate = DateTime.Now.ToString("yyyyMMddHHmmss");
                Directory.CreateDirectory(Server.MapPath("~/DynamicContent/BlogImages/Blog" + folderDate));
                var path       = "~/DynamicContent/BlogImages/Blog" + folderDate;
                var pathToSave = "DynamicContent/BlogImages/Blog" + folderDate;

                var blogDB = new Blog
                {
                    Caption         = blog.Caption,
                    Text            = blog.Text,
                    isActive        = blog.isActive,
                    MetaDescription = blog.MetaDescription,
                    MetaKeywords    = blog.MetaDescription,
                    Date            = DateTime.Now,
                    UserId          = userId,
                    ImageName       = blog.File.FileName,
                    ImagePath       = pathToSave,
                    Tags            = blog.Tags,
                    BlogTypeId      = blog.BlogTypeId
                };
                _unitOfWork.Blog.AddBlog(blogDB);
                blog.File.SaveAs(Path.Combine(Server.MapPath(path), blog.File.FileName));
            }

            _unitOfWork.Complete();

            return(RedirectToAction("Index", "BlogManager", new { area = "Admin" }));
        }
Пример #2
0
        public ActionResult SaveEditedBlog(BlogFormViewModel blog)
        {
            var blogDB = _unitOfWork.Blog.GetBlogById(blog.Id);

            var pathToSave = blogDB.ImagePath;
            var path       = "~/" + pathToSave;

            blogDB.Caption         = blog.Caption;
            blogDB.Text            = blog.Text;
            blogDB.isActive        = blog.isActive;
            blogDB.MetaKeywords    = blog.MetaKeywords;
            blogDB.MetaDescription = blog.MetaDescription;
            blogDB.Tags            = blog.Tags;
            blogDB.BlogTypeId      = blog.BlogTypeId;
            if (blog.File != null)
            {
                blogDB.ImageName = blog.File.FileName;
                blogDB.ImagePath = pathToSave;
                blog.File.SaveAs(Path.Combine(Server.MapPath(path), blog.File.FileName));
            }

            _unitOfWork.Complete();

            return(RedirectToAction("Index", "BlogManager", new { area = "Admin" }));
        }
Пример #3
0
        public ActionResult NewBlog()
        {
            var viewModel = new BlogFormViewModel
            {
                Id        = new int(),
                imageName = "/Content/Images/upload-icon.png"
            };

            return(View("AddBlog", viewModel));
        }
Пример #4
0
        // GET: Blogs/Create
        public ActionResult Create()
        {
            var categories = _context.Categories.ToList();

            var blogFormViewModel = new BlogFormViewModel()
            {
                Categories = categories
            };

            return(View("BlogForm", blogFormViewModel));
        }
Пример #5
0
        public ActionResult NewBlog()
        {
            var viewModel = new BlogFormViewModel
            {
                Id        = new int(),
                imageName = "/Areas/Admin/Content/images/upload-icon.png",
                BlogTypes = _unitOfWork.BlogTypes.GetBlogTypes()
            };

            return(View("NewBlog", viewModel));
        }
Пример #6
0
        public ActionResult CreateBlog()
        {
            var viewModel = new BlogFormViewModel
            {
                BlogPost = new Blog
                {
                    CreatedAt        = DateTime.Today,
                    FeatureImagePath = "no image selected"
                }
            };

            return(View("BlogForm", viewModel));
        }
Пример #7
0
        public ActionResult EditBlog(int id)
        {
            var blog = ctx.Blog.Find(id);

            var model = new BlogFormViewModel
            {
                Caption         = blog.Caption,
                Text            = blog.Text,
                Active          = blog.isActive,
                imageName       = "/DynamicContent/BlogImages/" + blog.ImageName,
                MetaKeywords    = blog.MetaKeywords,
                MetaDescription = blog.MetaDescription
            };

            return(View("EditBlog", model));
        }
Пример #8
0
        // GET: Blogs/Edit/5
        public ActionResult Edit(int id)
        {
            var blog = _context.Blogs.Include(b => b.Category).SingleOrDefault(b => b.Id == id);

            if (blog == null)
            {
                return(HttpNotFound());
            }

            var blogFormViewModel = new BlogFormViewModel()
            {
                Categories = _context.Categories.ToList(),
                Blog       = blog
            };

            return(View("BlogForm", blogFormViewModel));
        }
Пример #9
0
        public ActionResult EditBlog(int id)
        {
            var blog = _unitOfWork.Blog.GetBlogById(id);

            var model = new BlogFormViewModel
            {
                Caption         = blog.Caption,
                Text            = blog.Text,
                BlogTypeId      = blog.BlogTypeId,
                Tags            = blog.Tags,
                MetaDescription = blog.MetaDescription,
                MetaKeywords    = blog.MetaKeywords,
                isActive        = blog.isActive,
                imageName       = blog.ImagePath + "/" + blog.ImageName,
                BlogTypes       = _unitOfWork.BlogTypes.GetBlogTypes()
            };

            return(View("EditBlog", model));
        }
Пример #10
0
        public ActionResult SaveBlog(BlogFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("BlogForm", viewModel));
            }
            if (viewModel.FeatureImage != null)
            {
                string fileName  = Path.GetFileNameWithoutExtension(viewModel.FeatureImage.FileName);
                string extension = Path.GetExtension(viewModel.FeatureImage.FileName);
                fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                viewModel.BlogPost.FeatureImagePath = "~/Images/" + fileName;
                fileName = Path.Combine(Server.MapPath("~/Images"), fileName);
                viewModel.FeatureImage.SaveAs(fileName);
            }

            viewModel.BlogPost.AuthorId = User.Identity.GetUserId();
            _context.Blogs.Add(viewModel.BlogPost);
            _context.SaveChanges();
            return(RedirectToAction("Blog", "Admin"));
        }
Пример #11
0
        public ActionResult Save(Blog blog)
        {
            if (!ModelState.IsValid)
            {
                var blogFormViewModel = new BlogFormViewModel()
                {
                    Categories = _context.Categories.ToList(),
                    Blog       = blog
                };

                return(View("BlogForm", blogFormViewModel));
            }

            try
            {
                // TODO: Add insert / edit logic here
                if (blog.Id == 0)
                {
                    _context.Blogs.Add(blog);
                }
                else
                {
                    var blogInDb = _context.Blogs.Single(model => model.Id == blog.Id);
                    //TryUpdateModel(blogInDb);
                    blogInDb.Title       = blog.Title;
                    blogInDb.Description = blog.Description;
                    blogInDb.CategoryId  = blog.CategoryId;
                }

                _context.SaveChanges();

                return(RedirectToAction("Index", "Blogs"));
            }
            catch
            {
                return(View("BlogForm"));
            }
        }
Пример #12
0
        public ActionResult Save(BlogFormViewModel blog)
        {
            if (!ModelState.IsValid)
            {
                var errorModel = new BlogFormViewModel
                {
                    Caption         = blog.Caption,
                    Text            = blog.Text,
                    Active          = blog.Active,
                    imageName       = "/Content/Images/upload-icon.png",
                    MetaKeywords    = blog.MetaKeywords,
                    MetaDescription = blog.MetaDescription
                };
                return(View("AddBlog", errorModel));
            }

            if (blog.Id == 0)
            {
                if (blog.File != null && blog.File.ContentLength > 0)
                {
                    var path   = "/DynamicContent/BlogImages";
                    var blogDB = new Blog
                    {
                        Caption         = blog.Caption,
                        Text            = blog.Text,
                        isActive        = blog.Active,
                        DatePublished   = DateTime.Now,
                        UserId          = Helpers.Authentication.GetLoggedInUser().Id,
                        ImageName       = blog.File.FileName,
                        ImagePath       = Path.Combine(Server.MapPath(path), blog.File.FileName),
                        MetaKeywords    = blog.MetaKeywords,
                        MetaDescription = blog.MetaDescription
                    };
                    ctx.Blog.Add(blogDB);
                    blog.File.SaveAs(blogDB.ImagePath);
                }
                else
                {
                    var errorModel = new BlogFormViewModel
                    {
                        Caption         = blog.Caption,
                        Text            = blog.Text,
                        Active          = blog.Active,
                        imageName       = "/Content/Images/upload-icon.png",
                        MetaKeywords    = blog.MetaKeywords,
                        MetaDescription = blog.MetaDescription
                    };
                    ModelState.AddModelError("", "Glavna slika je obavezna, molimo odaberite sliku.");
                    return(View("AddBlog", errorModel));
                }
            }
            else
            {
                var blogDB = ctx.Blog.Find(blog.Id);

                var path = "/DynamicContent/BlogImages";

                blogDB.Caption         = blog.Caption;
                blogDB.Text            = blog.Text;
                blogDB.isActive        = blog.Active;
                blogDB.MetaKeywords    = blog.MetaKeywords;
                blogDB.MetaDescription = blog.MetaDescription;
                if (blog.File != null)
                {
                    blogDB.ImageName = blog.File.FileName;
                    blogDB.ImagePath = Path.Combine(Server.MapPath(path), blog.File.FileName);
                    blog.File.SaveAs(blogDB.ImagePath);
                }
            }

            ctx.SaveChanges();

            return(RedirectToAction("Index", "BlogManager", new { area = "Admin" }));
        }
Пример #13
0
        public ActionResult Create(BlogFormViewModel form)
        {
            var blogSaveDetails = this.blogSaveDetailsMappper.MapFrom(form);

            try
            {
                this.blogTasks.Save(blogSaveDetails);
                return this.RedirectToAction(c => c.Read(blogSaveDetails.Url));
            }
            catch (RulesException ex)
            {
                ex.AddModelStateErrors(this.ModelState, "Form");
            }

            return this.RedirectToAction(c => c.Create());
        }