public async Task <IActionResult> Edit(Post post, IFormFile Image, int[] tags) { if (Image != null) { var path = await FileUploadHelper.UploadAsync(Image); post.ImageUrl = path; } post.Date = DateTime.Now; context.Posts.Update(post); await context.SaveChangesAsync(); context.UpdateManyToMany( context.PostTags.Where(x => x.PostId == post.Id), tags.Select(x => new PostTag { PostId = post.Id, TagId = x }), x => x.TagId); await context.SaveChangesAsync(); TempData["Status"] = "Post edited!"; return(RedirectToAction("Index")); }