Ejemplo n.º 1
0
 public ActionResult Create()
 {
     UsersUOW userUOF = new UsersUOW();
     var blogs = _dbContext.Blogs.ToList();
     BlogViewModel blogViewModel = new BlogViewModel();
     var user = userUOF.FindUser(User.Identity.Name);
     blogViewModel.TagsList = _dbContext.Tags.ToList().Select(r => new SelectListItem
     {
         Selected = false,
         Text = r.Name,
         Value = r.Name
     });
     blogViewModel.UserId = user.Id;
     return View(blogViewModel);
 }
Ejemplo n.º 2
0
        public ActionResult CreateNewStyleBlog()
        {
            UsersUOW userUOF = new UsersUOW();
            var blogs = _dbContext.Blogs.ToList();
            BlogViewModel blogViewModel = new BlogViewModel();
            var user = userUOF.FindUser(User.Identity.Name);
            blogViewModel.Tags = _dbContext.Tags.Select(tag => new TagsCheckBox
            {
                Id = tag.Id,
                Name = tag.Name,
                IsChecked = false
            }).ToList();

            blogViewModel.UserId = user.Id;
            return View(blogViewModel);
        }
Ejemplo n.º 3
0
        public ActionResult Create(BlogViewModel viewModel, params string[] TagsSelectedOnView)
        {
            if (ModelState.IsValid)
            {
                Blog newBlog = new Blog();
                if (viewModel.MainImageNameFile != null)
                {

                    string fName = "";
                    HttpPostedFileBase file = viewModel.MainImageNameFile;
                    fName = viewModel.MainImageNameFile.FileName;
                    string ImageNameWithOutExtention = System.IO.Path.GetFileNameWithoutExtension(fName);
                    string extension = Path.GetExtension(fName);

                    var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\Blogs", Server.MapPath(@"\")));
                    string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "imagepath");
                    var fileName1 = Path.GetFileName(file.FileName);
                    bool isExists = System.IO.Directory.Exists(pathString);
                    if (!isExists)
                        System.IO.Directory.CreateDirectory(pathString);
                    var path = string.Format("{0}\\{1}", pathString, file.FileName);
                    file.SaveAs(path);


                    var versions = new Dictionary<string, string>();
                    var imagePath = string.Format("{0}\\{1}", pathString, ImageNameWithOutExtention);

                    versions.Add("_small", "maxwidth=100&maxheight=100&format=jpg");
                    versions.Add("_medium", "maxwidth=500&maxheight=500&format=jpg");
                    versions.Add("_large", "maxwidth=900&maxheight=900&format=jpg");
                    foreach (var suffix in versions.Keys)
                    {
                        file.InputStream.Seek(0, SeekOrigin.Begin);
                        ImageBuilder.Current.Build(
                            new ImageJob(
                                file.InputStream,
                               imagePath + suffix,
                                new Instructions(versions[suffix]),
                                false,
                                true));
                    }

                    newBlog.MainImageName = ImageNameWithOutExtention;
                    newBlog.ImageExtention = extension;
                }

                newBlog.Id = Guid.NewGuid();
                newBlog.UserId = viewModel.UserId;
                newBlog.Content = viewModel.Content;
                newBlog.Slug = viewModel.Slug;
                newBlog.Title = viewModel.Title;
                _dbContext.Blogs.Add(newBlog);
                var tagList = _dbContext.Tags;

                foreach (var tag in TagsSelectedOnView)
                {
                    Tag retriveTag = tagList.Where(t => t.Name == tag).FirstOrDefault();
                    // newBlog.Tags.Add(retriveTag);
                    retriveTag.Blogs.Add(newBlog);
                }

                _dbContext.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(viewModel);
        }
Ejemplo n.º 4
0
        public ActionResult Edit(BlogViewModel viewModel, params string[] TagsSelectedOnView)
        {
            if (ModelState.IsValid)
            {
                Blog blog = Mapper.Map<Blog>(viewModel);
                if (viewModel.MainImageNameFile != null)
                {

                    string fName = "";
                    HttpPostedFileBase file = viewModel.MainImageNameFile;
                    fName = viewModel.MainImageNameFile.FileName;
                    string ImageNameWithOutExtention = System.IO.Path.GetFileNameWithoutExtension(fName);
                    string extension = Path.GetExtension(fName);

                    var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\Blogs", Server.MapPath(@"\")));
                    string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "imagepath");
                    var fileName1 = Path.GetFileName(file.FileName);
                    bool isExists = System.IO.Directory.Exists(pathString);
                    if (!isExists)
                        System.IO.Directory.CreateDirectory(pathString);
                    var path = string.Format("{0}\\{1}", pathString, file.FileName);
                    file.SaveAs(path);


                    var versions = new Dictionary<string, string>();
                    var imagePath = string.Format("{0}\\{1}", pathString, ImageNameWithOutExtention);

                    versions.Add("_small", "maxwidth=100&maxheight=100&format=jpg");
                    versions.Add("_medium", "maxwidth=500&maxheight=500&format=jpg");
                    versions.Add("_large", "maxwidth=900&maxheight=900&format=jpg");
                    foreach (var suffix in versions.Keys)
                    {
                        file.InputStream.Seek(0, SeekOrigin.Begin);
                        ImageBuilder.Current.Build(
                            new ImageJob(
                                file.InputStream,
                               imagePath + suffix,
                                new Instructions(versions[suffix]),
                                false,
                                true));
                    }

                    blog.MainImageName = ImageNameWithOutExtention;
                    blog.ImageExtention = extension;
                }

                _dbContext.Entry(blog).State = EntityState.Modified;
                _dbContext.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(viewModel);
        }