public IActionResult Edit(int id) { Post post = _postrepo.FindById(id); if (post.Owner != _userManager.GetUserAsync(User).Result) { return(RedirectToAction(nameof(Index))); } EditPostVM model = _mapper.Map <EditPostVM>(post); model.Movie.AvailableGenres = new List <SelectListItem>(); // Add available genres var availableGenres = _genrerepo.FindAll(); foreach (var g in availableGenres) { model.Movie.AvailableGenres.Add(new SelectListItem { Text = g.Name, Value = g.GenreId.ToString(), Selected = post.Movie.Genres.Exists(q => q.GenreId == g.GenreId) }); } // Add owner's rating. model.Movie.Rating = _ratingrepo.FindAllByUserId(_userManager.GetUserId(User)) .Single(r => r.Movie.MovieId == model.Movie.MovieId); return(View(model)); }
public IActionResult Edit(EditPostVM model) { if (!ModelState.IsValid) { return(View(model)); } Post newPost = _mapper.Map <Post>(model); Post oldPost = _postrepo.FindById(model.PostID); if (oldPost.Owner != _userManager.GetUserAsync(User).Result) { return(RedirectToAction(nameof(Index))); } if (newPost.Movie.Title != null) { oldPost.Movie.Title = newPost.Movie.Title; } if (newPost.Movie.SortDescription != null) { oldPost.Movie.SortDescription = newPost.Movie.SortDescription; } if (newPost.Movie.LongDescription != null) { oldPost.Movie.LongDescription = newPost.Movie.LongDescription; } var newRating = newPost.Movie.Ratings.First(); var oldRating = oldPost.Movie.Ratings.Single(r => r.RaterId == oldPost.OwnerId); if (newRating.Value != oldRating.Value) { oldRating.Value = newRating.Value; oldRating.DateRated = DateTime.Now; } if (model.Movie.Poster != null) { oldPost.Movie.PosterPath = _posterservice.UploadImage(model.Movie.Poster); } var newUrl = newPost.Movie.YoutubeId; var oldUrl = oldPost.Movie.YoutubeId; if (newUrl != oldUrl) { oldPost.Movie.YoutubeId = newUrl; } oldPost.Movie.Genres = newPost.Movie.Genres; _postrepo.Update(oldPost); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> EditPost(int?id) { var model = new EditPostVM() { postEdit = await _context.Post.FindAsync(id) }; return(View(model)); }
public IActionResult EditPost([FromRoute] int?projectId, [FromRoute] int?postId) { var editpost = new EditPostVM() { Post = _postservices.FindPostById(projectId.Value, postId.Value), Project = _projectservices.FindMyProjectById(projectId.Value) }; return(View(editpost)); }
public IActionResult Edit(int id) { var postModel = _postRepo.GetUserPost(id, User.Id()); var editPostModel = new EditPostVM { Id = postModel.Id, AuthorUserId = postModel.AuthorUser.Id, Title = postModel.Title, Body = postModel.Body }; return(View(editPostModel)); }
public async Task <IActionResult> SpasiPromjene(EditPostVM model, IFormFile slika) { Post p = await _context.Post.FindAsync(model.postEdit.Id); p.AutorId = model.postEdit.AutorId; p.DatumObjave = DateTime.Now; p.Naslov = model.postEdit.Naslov; p.Sadrzaj = model.postEdit.Sadrzaj; if (slika != null) { if (slika.Length > 0) { var extension_delete = Path.GetExtension(p.ImageLocation); //var path_delete = _hostingEnvironment.WebRootPath // + "\\pictures\\oglasi\\" + "Oglas-" + model.postEdit.Id + extension_delete; var path_delete = Path.Combine(_hostingEnvironment.WebRootPath, "pictures", "oglasi", "Oglas-" + model.postEdit.Id + extension_delete); if (System.IO.File.Exists(path_delete)) { System.IO.File.Delete(path_delete); } //var path = _hostingEnvironment.WebRootPath + "\\pictures\\oglasi"; var path = Path.Combine(_hostingEnvironment.WebRootPath, "pictures", "oglasi"); var filename = "Oglas-" + _context.Post .Where(x => x.Id == model.postEdit.Id) .FirstOrDefault().Id.ToString() + Path.GetExtension(slika.FileName); await using (var stream = new FileStream(Path.Combine(path, filename), FileMode.Create)) { await slika.CopyToAsync(stream); } p.ImageLocation = "/pictures/oglasi/" + filename; } } await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Post")); }
public IActionResult Edit(int id, EditPostVM editPostModel) { if (!ModelState.IsValid) { return(View(editPostModel)); } if (id != editPostModel.Id || editPostModel.AuthorUserId != User.Id()) { return(NotFound()); } var postModel = _postRepo.GetById(id); postModel.Title = editPostModel.Title; postModel.Body = editPostModel.Body; postModel.UpdatedAt = DateTime.Now; _postRepo.Context().SaveChanges(); return(RedirectToAction(nameof(Manage), new { id })); }
public ActionResult Edit(int id, EditPostVM model) { try { var blogPost = new BlogPost(); blogPost = model.EditPost; blogPost.BlogPostID = id; blogPost.PostContent = model.HtmlContent; if (model.EditPost.Status == null) { blogPost.Status = new Status() { StatusID = 1 }; } else { blogPost.Status.StatusID = model.EditPost.Status.StatusID; } var ops = OperationsFactory.CreateBlogPostOps(); var categoryOps = OperationsFactory.CreateCategoryOps(); ops.SaveBlogPost(blogPost); categoryOps.SaveBlogPostCategory(model.SelectedCategoryIds, blogPost); return RedirectToAction("Index", "ContentManager"); } catch { return RedirectToAction("Index", "ContentManager"); } }
public ActionResult Edit(int id) { var blogOps = OperationsFactory.CreateBlogPostOps(); var categoryOps = OperationsFactory.CreateCategoryOps(); var hashOps = OperationsFactory.CreateHashtagOps(); var statusOps = OperationsFactory.CreateStatusOps(); var categoryList = categoryOps.ListAllCategories(); var hastagList = hashOps.ListAllHashtags(); var statusList = statusOps.ListAllStatuses(); var model = new EditPostVM(); { model.EditPost = blogOps.GetBlogPostById(id); //SelectedCategoryIds = new List<int>() }; model.GenerateHashtagsList(hastagList); model.GenerateCategoriesList(categoryList); model.GenerateStatusList(statusList); model.HtmlContent = model.EditPost.PostContent; return View(model); }