public async Task <IActionResult> Edit(int postId, EditPostInputModel editPostInputModel) { if (postId == 0) { postId = editPostInputModel.Id; } var editPostViewModel = await this.postService.GetPostByIdAsync <EditPostViewModel>(postId); if (!this.ModelState.IsValid) { this.TempData["img"] = editPostViewModel?.PageHeader?.Image?.CloudUrl; editPostInputModel = this.FillThePost(editPostViewModel, editPostInputModel); editPostInputModel.Id = postId; return(this.View(editPostInputModel)); } int pageHeaderId = await this.postService.GetPageHeaderIdAsync(postId); var img = editPostInputModel.PageHeader.Image; await this.pageHeaderService.UpdateAsync(pageHeaderId, new PageHeaderInputModel { Image = img, MainTitle = editPostInputModel.PageHeader.MainTitle, SubTitle = editPostInputModel.PageHeader.SubTitle, }); return(this.RedirectToAction("Edit", "Posts", new { postId })); }
public async Task <IActionResult> Edit(int postId) { var editPostViewModel = await this.postService.GetPostByIdAsync <EditPostViewModel>(postId); if (editPostViewModel == null) { this.TempData["alert"] = NotExistingPostErrorMsg; return(this.RedirectToAction("Index", "Home")); } var img = editPostViewModel?.PageHeader?.Image; var editPostInputModel = new EditPostInputModel { PageHeader = new PageHeaderInputModel { Image = new ImageInputModel { CloudUrl = img?.CloudUrl, }, MainTitle = editPostViewModel?.PageHeader.Title, SubTitle = editPostViewModel?.PageHeader.SubTitle, }, Sections = editPostViewModel?.Sections.Where(s => s.SectionIsDeleted == false).Select(s => new EditSectionInputModel { Id = s.SectionId, SectionContent = s.SectionContent, SectionTitle = s.SectionTitle, }).ToList(), Id = postId, }; this.TempData["img"] = editPostInputModel?.PageHeader?.Image?.CloudUrl; return(this.View(editPostInputModel)); }
public async Task <IActionResult> Edit(EditPostInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } if (!await this.postsService.PostExists(input.Id)) { return(this.NotFound()); } var user = await this.userManager.GetUserAsync(this.User); var isAdmin = await this.userManager.IsInRoleAsync(user, GlobalConstants.AdministratorRoleName); if (!await this.postsService.IsUserPostAuthor(input.Id, user.Id) && !isAdmin) { return(this.BadRequest()); } await this.postsService.EditAsync(input.Title, input.Content, input.CategoryId, input.Id); return(this.RedirectToAction("ById", "Posts", new { Id = input.Id })); }
public IActionResult Edit(int id) { EditPostInputModel editPostInputModel = this.postsService.GetById <EditPostInputModel>(id); editPostInputModel.CourseItems = this.coursesService.GetAllAsSelectListItems(); return(this.View(editPostInputModel)); }
public async Task <IActionResult> EditPost(EditPostInputModel model) { await this.postsService.EditPost(model.Id, model.Title, model.Content); //var post = this.postsService.GetById(model.Id); return(this.RedirectToAction("Index", "Posts", new { id = model.Id })); }
public EditViewModel(EditPostInputModel inputModel) { Id = inputModel.Id; CategoryName = inputModel.CategoryName; InstanceName = inputModel.InstanceName; CounterName = inputModel.CounterName; Duration = inputModel.Duration; SampleInterval = inputModel.SampleInterval; Threshold = inputModel.Threshold; ThresholdWhen = inputModel.ThresholdWhen; }
public async Task <IActionResult> EditPost(EditPostInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.postsService.EditPost(input.UserId, input); return(this.RedirectToAction("Index", "ManagePosts", new { area = "Administration" })); }
public async Task UpdateAsync(EditPostInputModel inputModel) { Post post = this.postRepository .All() .FirstOrDefault(p => p.Id == inputModel.PostId); post.Content = inputModel.Content; post.Title = inputModel.Title; post.CourseId = inputModel.CourseId; await this.postRepository.SaveChangesAsync(); }
public async Task <IActionResult> Edit(EditPostInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var userId = this.userManager.GetUserId(this.User); await this.postsService.EditPost(userId, input); return(this.RedirectToAction("Posts", "Profiles", new { userId = userId })); }
public IActionResult Edit(int id) { var post = this.postsService.GetById(id); var model = new EditPostInputModel { Id = post.Id, Title = post.Title, Content = post.Content, CreatedOn = post.CreatedOn, }; return(this.View(model)); }
public async Task <IActionResult> EditPost(EditPostInputModel model) { if (this.ModelState.IsValid) { var currentUser = await this.userManager.GetUserAsync(this.User); var tuple = await this.blogService.EditPost(model, currentUser); this.TempData[tuple.Item1] = tuple.Item2; return(this.RedirectToAction("Index", "Post", new { postId = model.Id })); } this.TempData["Error"] = ErrorMessages.InvalidInputModel; return(this.View(model)); }
public async Task <IActionResult> EditPost(string id) { if (!await this.blogService.IsPostExist(id)) { return(this.NotFound()); } EditPostInputModel model = await this.blogService.ExtractPost(id); model.Categories = await this.blogService.ExtractAllCategoryNames(); model.Tags = await this.blogService.ExtractAllTagNames(); return(this.View(model)); }
public async Task <IActionResult> EditNewsFeedPost(EditPostInputModel model) { var sanitizer = new HtmlSanitizer(); var content = sanitizer.Sanitize(model.Content); var post = new NewsFeedPost { Id = model.Id, Content = content, }; await this.administratorService.UpdateNewsFeedPostAsync(post); return(this.RedirectToAction(nameof(this.NewsFeedPost))); }
public IActionResult Edit(EditPostInputModel model) { var forumsIds = this.forumService.GetAllForumsIds(this.User, this.ModelState, model.ForumId); this.postService.Edit(model, this.User, this.ModelState); if (this.ModelState.IsValid) { return(this.Redirect($"/Post/Details?Id={model.Id}")); } else { var result = this.View("Error", this.ModelState); result.StatusCode = (int)HttpStatusCode.BadRequest; return(result); } }
public async Task <IActionResult> Edit(EditPostInputModel inputModel, int id) { if (!this.ModelState.IsValid) { inputModel = this.postsService.GetById <EditPostInputModel>(id); inputModel.CourseItems = this.coursesService.GetAllAsSelectListItems(); return(this.View(inputModel)); } ApplicationUser user = await this.userManager.GetUserAsync(this.User); inputModel.AuthorId = user.Id; inputModel.PostId = id; await this.postsService.UpdateAsync(inputModel); return(this.RedirectToAction("All", "Posts")); }
private EditPostInputModel FillThePost(EditPostViewModel editPostViewModel, EditPostInputModel editPostInputModel) { if (editPostInputModel.PageHeader?.Image?.CloudUrl == null) { editPostInputModel.PageHeader.Image = new ImageInputModel { CloudUrl = this.TempData["img"].ToString(), }; } editPostInputModel.Sections = editPostViewModel?.Sections.Where(s => s.SectionIsDeleted == false).Select(s => new EditSectionInputModel { Id = s.SectionId, SectionContent = s.SectionContent, SectionTitle = s.SectionTitle, }).ToList(); return(editPostInputModel); }
public async Task <IActionResult> EditPost(string id) { if (!await this.blogService.IsPostExist(id)) { return(this.NotFound()); } var currentUser = await this.userManager.GetUserAsync(this.User); var isBlocked = this.blogService.IsBlocked(currentUser); if (isBlocked) { this.TempData["Error"] = ErrorMessages.YouAreBlock; return(this.RedirectToAction("Index", "Blog")); } var isApproved = await this.blogService.IsPostBlocked(id, currentUser); if (isApproved) { this.TempData["Error"] = ErrorMessages.CannotEditBlogPost; return(this.RedirectToAction("Index", "Blog")); } var isInRole = await this.blogService.IsInPostRole(currentUser, id); if (!isInRole) { this.TempData["Error"] = ErrorMessages.NotInEditPostRoles; return(this.RedirectToAction("Index", "Blog")); } EditPostInputModel model = await this.blogService.ExtractPost(id, currentUser); model.Categories = await this.blogService.ExtractAllCategoryNames(); model.Tags = await this.blogService.ExtractAllTagNames(); return(this.View(model)); }
//[HandleError, OrchardAuthorization(PermissionName = ApplicationFrameworkPermissionStrings.EditConfigurationSettings)] public ActionResult EditPost(EditPostInputModel inputModel) { EditInputModel newEditInputModel = new EditInputModel() { Id = inputModel.Id, CategoryName = inputModel.CategoryName, InstanceName = inputModel.InstanceName, CounterName = inputModel.CounterName, Duration = inputModel.Duration, SampleInterval = inputModel.SampleInterval }; if (!ModelState.IsValid) { EditViewModel viewModel = _performanceMonitorWorkerService.Edit(newEditInputModel); return(View("Edit", viewModel)); } _performanceMonitorWorkerService.EditPost(inputModel); return(RedirectToAction("Index")); }
public async Task <IActionResult> EditNewsFeedPost(EditPostInputModel model) { var user = await this.userManager.GetUserAsync(this.User); if (!await this.newsFeedService.ExistsAndOwnerAsync(model.Id, user.Id)) { return(this.RedirectToAction(nameof(this.NotOwner))); } var sanitizer = new HtmlSanitizer(); var content = sanitizer.Sanitize(model.Content); var post = new NewsFeedPost { Id = model.Id, Content = content, }; await this.newsFeedService.UpdateAsync(post); return(this.RedirectToAction(nameof(this.NewsFeedContent))); }
public async Task EditPost(string userId, EditPostInputModel input) { var postToEdit = this.posts .All() .FirstOrDefault(p => p.Id == input.Id); var postImageUrls = new List <string>(); if (input.Images != null) { var postImagesUrls = await CloudinaryExtension.UploadAsync(this.cloudinary, input.Images); foreach (var url in postImagesUrls) { postImageUrls.Add(url); } var postImage = this.postImages.All().FirstOrDefault(p => p.PostId == postToEdit.Id); postImage.ImageUrl = postImageUrls[0]; } postToEdit.Description = input.Description; await this.posts.SaveChangesAsync(); }
// GET: Posts/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var query = from p in _context.Post.Include(p => p.Images). Include(p => p.PostTags).ThenInclude(pt => pt.Tag) where p.Id == id select p; var post = await query.SingleOrDefaultAsync(); if (post is null) { return(NotFound()); } var input = new EditPostInputModel() { Id = post.Id, Content = post.Content, ImagesToRemove = new List <string>(), ImageUrls = new List <string>(), Files = new List <IFormFile>(), Tags = new List <string>() }; foreach (var tag in post.PostTags) { input.Tags.Add(tag.Tag.Name); } foreach (var image in post.Images) { input.ImageUrls.Add(image.Url); } return(View(input)); }
public bool EditPost(EditPostInputModel inputModel) { string performanceCounterReading = _performanceCounterService.GetPerformanceCounterReading(inputModel.CategoryName, inputModel.InstanceName, inputModel.CounterName); if (performanceCounterReading == String.Empty) { _notifier.Error(T("Error: Not able to perform a reading on this type of counter")); return(false); } PerformanceMonitorRecord record = new PerformanceMonitorRecord() { Id = inputModel.Id, CategoryName = inputModel.CategoryName, InstanceName = inputModel.InstanceName, CounterName = inputModel.CounterName, InitialValue = performanceCounterReading, Duration = inputModel.Duration, SampleInterval = inputModel.SampleInterval, Threshold = inputModel.Threshold, ThresholdWhen = inputModel.ThresholdWhen }; var result = _performanceMonitorDataService.SetPerformanceMonitorRecord(record); if (result) { PerformanceMonitorRecord activeRecord = _performanceMonitorDataService.PerformanceMonitorRecords.FirstOrDefault(r => r.IsEnabled == true); //threshold check bool passedThreshold; var passedThresholdValue = 0; double countervalue = double.Parse(activeRecord.InitialValue); passedThreshold = _performanceMonitorService.CheckThreshold(activeRecord.Threshold, activeRecord.ThresholdWhen, countervalue, ref passedThresholdValue); PerformanceMonitorDataRecord datarecord = new PerformanceMonitorDataRecord() { PerformanceMonitorRecord_Id = activeRecord.Id, Count = activeRecord.InitialValue, HeartBeat = activeRecord.Created, PassedThreshold = passedThreshold, PassedThresholdValue = passedThresholdValue, //duration count(ticks in nanoseconds from starttime (created)) should initially be set to startvalue (zero) Ticks = "0" }; var dataResult = _performanceMonitorDataService.WriteDataRecord(datarecord); if (dataResult) { _notifier.Information(T("New counter records added succesfully")); } else { _notifier.Warning(T("New counter record added succesfully, but failed to write initial datarecord")); } } else { _notifier.Error(T("Error: Failed to add new counter")); } return(result); }
public async Task <Tuple <string, string> > EditPost(EditPostInputModel model, ApplicationUser user) { var post = await this.db.Posts .Include(x => x.ApplicationUser) .AsSplitQuery() .FirstOrDefaultAsync(x => x.Id == model.Id); var contentWithoutTags = Regex.Replace(model.SanitizeContent, "<.*?>", string.Empty); if (post != null) { var category = await this.db.Categories.FirstOrDefaultAsync(x => x.Name == model.CategoryName); var postUser = await this.db.Users.FirstOrDefaultAsync(x => x.Id == post.ApplicationUserId); post.Category = category; post.Title = model.Title; post.UpdatedOn = DateTime.UtcNow; post.Content = model.SanitizeContent; post.ShortContent = contentWithoutTags.Length <= 347 ? contentWithoutTags : $"{contentWithoutTags.Substring(0, 347)}..."; if (model.CoverImage != null) { var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, model.CoverImage, string.Format( GlobalConstants.CloudinaryPostCoverImageName, post.Id), GlobalConstants.PostBaseImageFolder); if (imageUrl != null) { post.ImageUrl = imageUrl; } } if (model.TagsNames.Count > 0) { List <PostTag> oldTagsIds = this.db.PostsTags.Where(x => x.PostId == model.Id).ToList(); this.db.PostsTags.RemoveRange(oldTagsIds); List <PostTag> postTags = new List <PostTag>(); foreach (var tagName in model.TagsNames) { var tag = await this.db.Tags.FirstOrDefaultAsync(x => x.Name.ToUpper() == tagName.ToUpper()); if (tag != null) { postTags.Add(new PostTag { PostId = post.Id, TagId = tag.Id, }); } } post.PostsTags = postTags; } if (user.Id == postUser.Id) { this.nonCyclicActivity.AddUserAction(new EditOwnPostUserAction { ApplicationUser = user, ApplicationUserId = user.Id, Post = post, PostId = post.Id, }); } else { this.nonCyclicActivity.AddUserAction(new EditPostUserAction { ApplicationUser = user, ApplicationUserId = user.Id, Post = post, PostId = post.Id, }); this.nonCyclicActivity.AddUserAction(new EditedPostUserAction { EditorApplicationUser = user, EditorApplicationUserId = user.Id, ApplicationUser = post.ApplicationUser, ApplicationUserId = post.ApplicationUser.Id, Post = post, PostId = post.Id, }); } this.db.Posts.Update(post); await this.db.SaveChangesAsync(); return(Tuple.Create("Success", SuccessMessages.SuccessfullyEditedPost)); } return(Tuple.Create("Error", ErrorMessages.InvalidInputModel)); }
public async Task <IActionResult> Edit(int id, [Bind] EditPostInputModel input) { if (id != input.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var query = from pst in _context.Post.Include(p => p.Images) .Include(p => p.PostTags).ThenInclude(pt => pt.Tag) where pst.Id == id select pst; var p = await query.SingleAsync(); if (p != null) { if (input.Tags != null) { LinkedList <string> tagList = new LinkedList <string>(); foreach (var pt in p.PostTags) { tagList.AddLast(pt.Tag.Name); } foreach (var tagName in input.Tags) { var tag = await _context.Tag.Where(t => t.Name == tagName).SingleOrDefaultAsync(); if (tag is null) { tag = new Tag() { Name = tagName }; _context.Tag.Add(tag); p.PostTags.Add(new PostTag() { Post = p, Tag = tag }); } else { var postTag = await _context.PostTag.Include(pt => pt.Tag).Include(pt => pt.Post) .Where(pt => pt.TagId == tag.Id && pt.PostId == p.Id).SingleOrDefaultAsync(); if (postTag is null) { p.PostTags.Add(new PostTag() { Post = p, Tag = tag }); } else { tagList.Remove(tag.Name); } } } foreach (var t in tagList) { var postTag = await _context.PostTag.Include(pt => pt.Tag).Include(pt => pt.Post) .Where(pt => pt.Tag.Name == t && pt.PostId == p.Id).SingleOrDefaultAsync(); _context.PostTag.Remove(postTag); } } if (input.ImagesToRemove != null) { foreach (var url in input.ImagesToRemove) { var path = Path.Combine(_environment.WebRootPath, url.Substring(1)); System.IO.File.Delete(path); var image = _context.PostImage.AsQueryable().Where(i => i.Url == url).FirstOrDefault(); _context.Remove(image); } } if (input.Files != null) { foreach (var file in input.Files) { _logger.LogInformation($"FileName = {file.FileName}"); } for (var i = 0; i < input.Files.Count; ++i) { var file = input.Files[i]; Image image; using (var stream = file.OpenReadStream()) { image = Image.FromStream(stream); // Read image } var extension = image.RawFormat.GetFileExtension(); var fileName = extension.GenerateRandomFileName(); var path = Path.Combine(_environment.WebRootPath, _configuration["PostImagesPath"], fileName); image.Save(path, image.RawFormat); var url = Path.Combine("/", _configuration["PostImagesPath"], fileName); p.Images.Add(new PostImage() { Url = url, Index = i }); } } var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Asia/Tokyo"); // For Linux p.LastModifiedTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZoneInfo); p.Content = input.Content; await _context.SaveChangesAsync(); return(RedirectToAction("Details", new { id })); } return(NotFound()); } catch (DbUpdateConcurrencyException) { if (!PostExists(input.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(RedirectToAction("Edit", new { id })); }