public async Task <IActionResult> Edit(PostViewModel model) { var entity = await _postManager.FindByIdAsync(model.Id); if (ModelState.IsValid) { entity = model.ToEntity(entity); // parse slug entity.Slug = entity.GetSeName(); // categories await UpdatePostCategories(model, entity); // tags await UpdatePostTags(model, entity); // updte await _postManager.UpdateAsync(entity); AlertSuccess("修改成功。"); return(RedirectToAction(nameof(List))); } PrepareViewModel(model, entity); return(View(model)); }
public async Task <IActionResult> Create(PostViewModel model) { if (ModelState.IsValid) { var entity = model.ToEntity(); // parse slug entity.Slug = entity.GetSeName(); // parse slug entity.Slug = entity.GetSeName(); // categories await UpdatePostCategories(model, entity); // tags await UpdatePostTags(model, entity); // author var currentUser = await _userManager.GetUserAsync(User); entity.UserId = currentUser.Id; await _postManager.CreateAsync(entity); AlertSuccess("添加成功。"); return(RedirectToAction(nameof(List))); } PrepareViewModel(model, null); return(View(model)); }