public ActionResult Edit(EditBlogViewModel viewModel)
        {
            if (viewModel.Image != null)
            {
                string fileName  = Path.GetFileNameWithoutExtension(viewModel.Image.FileName);
                string extension = Path.GetExtension(viewModel.Image.FileName);
                fileName       = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                viewModel.Path = "~/Image/" + fileName;
                fileName       = Path.Combine(Server.MapPath("~/Image/"), fileName);
                viewModel.Image.SaveAs(fileName);
            }

            var  existingBlog = blogBS.GetByID(viewModel.BlogId);
            Blog blog         = new Blog();

            blog.BlogId    = viewModel.BlogId;
            blog.Title     = viewModel.Title;
            blog.Content   = viewModel.Content;
            blog.ImagePath = viewModel.Path ?? existingBlog.ImagePath;
            blog.userId    = existingBlog.userId;
            blog.Status    = existingBlog.Status;
            blog.StatusId  = existingBlog.StatusId;
            blogBS.Update(blog);
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> EditBlog(int BlogId)
        {
            // Get blog from DB
            var blog = _blogRepository.GetBlog(BlogId);

            if (blog == null)
            {
                ViewBag.ErrorTitle   = "Blog cannot be found!";
                ViewBag.ErrorMessage = "No blog with such ID was found.";
                return(View("Error"));
            }

            var author = await userManager.FindByIdAsync(blog.UserId);

            // Prevent editing someone else's blog
            if (!author.UserName.Equals(User.Identity.Name) && !User.IsInRole("Admin"))
            {
                return(RedirectToAction("AccessDenied", "Account"));
            }

            // Build model
            EditBlogViewModel model = new EditBlogViewModel
            {
                Title            = blog.Title,
                BriefDescription = blog.BriefDescription,
                Topic            = blog.Topic,
                Date             = blog.Date,
                BlogContent      = blog.BlogContent,
                BlogId           = BlogId,
                UserId           = blog.UserId
            };

            return(View(model));
        }
Beispiel #3
0
        public ActionResult Edit(EditBlogViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            EditBlogCommand command = new EditBlogCommand
            {
                Id             = vm.Id,
                Title          = vm.Title,
                PreviewContent = vm.PreviewContent,
                HtmlContent    = vm.HtmlContent,
                IsPublished    = vm.IsPublished
            };

            if (vm.Image != null)
            {
                var result = SaveAs(vm.Image, PlatformConfiguration.UploadedBlogPath);

                if (result.ResultCode == CommandResultCode.Success && result.File != null)
                {
                    command.FileId = result.File.Id;
                }
            }

            Command.Execute(command);

            return(RedirectToAction("Details", new { id = vm.Id }));
        }
Beispiel #4
0
        public IActionResult EditBlog(EditBlogViewModel model)
        {
            if (ModelState.IsValid)
            {
                var blog = _blogRepository.GetBlog(model.BlogId);

                if (blog == null)
                {
                    ViewBag.ErrorTitle   = "Error in finding the blog!";
                    ViewBag.ErrorMessage = "No blog with such ID was found.";
                    return(View("Error"));
                }

                // Update all fields
                blog.Title            = model.Title;
                blog.BriefDescription = model.BriefDescription;
                blog.Topic            = model.Topic;
                blog.BlogContent      = model.BlogContent;
                blog.Date             = DateTime.Today;
                blog.Approved         = false;

                var updatedBlog = _blogRepository.Update(blog);
                if (updatedBlog != null)
                {
                    // Success alert
                    TempData["Alert"]      = $"Blog with title \"{updatedBlog.Title}\" has been updated";
                    TempData["AlertClass"] = "alert-success";
                    return(RedirectToAction("Author", "Profile", new { username = User.Identity.Name }));
                }
            }

            return(View(model));
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(EditBlogViewModel editBlogViewModel)
        {
            var entity = await _mappingManager.UpdateBlog(editBlogViewModel, User);

            return(RedirectToAction(nameof(Index), "Home"));
            //return View(entity);
        }
Beispiel #6
0
        public async Task <EditBlogViewModel> UpdateBlog(EditBlogViewModel editBlogViewModel, ClaimsPrincipal claimsPrincipal)
        {
            var blog = _blogService.GetBlogById(editBlogViewModel.Blog.Id);

            blog.Tag       = editBlogViewModel.Blog.Tag;
            blog.Title     = editBlogViewModel.Blog.Title;
            blog.Content   = editBlogViewModel.Blog.Content;
            blog.CreatedOn = DateTime.Now;

            if (editBlogViewModel.BlogImage != null)
            {
                string webRootPath = _webHostEnvironment.WebRootPath;
                string pathToImage = $@"{webRootPath}\UserFiles\Blogs\{blog.Id}\BlogImage.jpg";
                EnsureFolder(pathToImage);
                using (var fileStream = new FileStream(pathToImage, FileMode.Create))
                {
                    await editBlogViewModel.BlogImage.CopyToAsync(fileStream);
                }
            }

            return(new EditBlogViewModel
            {
                Blog = await _blogService.Update(blog)
            });
        }
Beispiel #7
0
        public ActionResult Edit()
        {
            var viewModel = new EditBlogViewModel()
            {
                Blog = SetupBlogService.ReadBlogGeneralSettings(User.Blogs.First().Id)
            };

            return(View(viewModel));
        }
        public ActionResult Edit(int id)
        {
            var blog = blogBS.GetByID(id);
            var editBlogViewModel = new EditBlogViewModel();

            editBlogViewModel.Content   = blog.Content;
            editBlogViewModel.Path      = blog.ImagePath;
            editBlogViewModel.Title     = blog.Title;
            editBlogViewModel.BlogId    = blog.BlogId;
            editBlogViewModel.ImageName = blog.ImagePath.Split('/')[blog.ImagePath.Split('/').Length - 1];
            return(View(editBlogViewModel));
        }
Beispiel #9
0
 public ActionResult EditBlog(string id)
 {
     try
     {
         var model = new EditBlogViewModel(id);
         return(View(model));
     }
     catch (Exception)
     {
         return(Redirect("/admin/blog/manageblogs/"));
     }
 }
Beispiel #10
0
        public ActionResult Edit(int id)
        {
            GetBlogByIdQueryResult result = Query.For <GetBlogByIdQueryResult>().ById(id);

            if (!result.IsFound)
            {
                return(RedirectToAction("Index"));
            }

            EditBlogViewModel vm = ToEditViewModel(result.Blog);

            return(View(vm));
        }
Beispiel #11
0
        public IHttpActionResult PutBlog(int id, EditBlogViewModel blog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != blog.Id)
            {
                return(BadRequest());
            }

            Models.Blog blogModel = db.Blogs.Find(id);

            if (blogModel == null)
            {
                return(NotFound());
            }

            if (!BelongsToCurrentUser(blogModel))
            {
                return(Unauthorized());
            }

            Mapper.Map(blog, blogModel);

            db.Entry(blogModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BlogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #12
0
        public IActionResult Edit(EditBlogViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Blog blog = new Blog()
                {
                    Id          = viewModel.Id,
                    Title       = viewModel.Title,
                    Description = viewModel.Description
                };
                _blogService.Edit(blog);

                return(RedirectToRoute(new { controller = "Blog", action = "Show", id = blog.Id }));
            }

            return(View(viewModel));
        }
Beispiel #13
0
        public async Task <IActionResult> Put([FromBody] EditBlogViewModel blog)
        {
            BlogModel data = await _context.Blogs.FirstOrDefaultAsync(data => data.Id == blog.Id);

            if (data != null)
            {
                data.Description = blog.Description;
                data.Name        = blog.Name;
                data.PostedBy    = blog.PostedBy;
                data.PostedOn    = blog.PostedOn;
                _context.Blogs.Update(data);
                await _context.SaveChangesAsync();

                _context.Entry(data).State = EntityState.Modified;
            }

            return(Ok(new { }));
        }
Beispiel #14
0
        public IActionResult Edit(int?id)
        {
            Blog blog = _blogService.GetBlog(id, User);

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

            EditBlogViewModel viewModel = new EditBlogViewModel()
            {
                Id          = blog.Id,
                Title       = blog.Title,
                Description = blog.Description
            };

            return(View(viewModel));
        }
        public ActionResult EditBlog(string id)
        {
            var model = new EditBlogViewModel(id);

            return(View(model));
        }
Beispiel #16
0
 public ActionResult Edit(EditBlogViewModel viewModel)
 {
     SetupBlogService.UpdateBlogGeneralSettings(User.Blogs.First().Id, viewModel.Blog);
     return(Json(""));
 }