public async Task <bool> UpdateBlogAsync(BlogServiceModel serviceModel) { var oldBlog = await AllBlog.FirstOrDefaultAsync(o => o.Id == serviceModel.Blog.Id); var blogEntry = _context.Entry(oldBlog); serviceModel.Blog.LastUpdateByUserId = serviceModel.User.Id; serviceModel.Blog.LastUpdateDate = DateTime.Now; blogEntry.CurrentValues.SetValues(serviceModel.Blog); _context.Entry(oldBlog).Property(o => o.CreateByUserId).IsModified = false; _context.Entry(oldBlog).Property(o => o.CreateDate).IsModified = false; foreach (var newDetail in serviceModel.Blog.Details) { var oldDetail = oldBlog.Details.FirstOrDefault(o => o.ForCurrentRequestLanguage()); if (oldDetail.Language == newDetail.Language) { newDetail.Id = oldDetail.Id; _context.Entry(oldDetail).CurrentValues.SetValues(newDetail); } } _context.TryUpdateManyToMany(oldBlog.EntityFiles, serviceModel.Blog.EntityFiles, o => o.FileEntityId); var updateResultCount = await _context.SaveChangesAsync(); return(updateResultCount > 0); }