これについて私を助けてください、私は本当に混乱しています!
何か更新したい!これは私のコントローラーです(ポストアクション):
[HttpPost]
public ActionResult Edit(CategoryViewModel categoryViewModel)
{
if(ModelState.IsValid)
{
_categoryService.UpdateCategory(categoryViewModel.Id);
}
return View();
}
これは私のサービスクラスです(私の質問はこのクラスに関するもので、更新方法がわかりません)
public CategoryViewModel UpdateCategory(Guid categoryId)
{
var category = _unitOfWork.CategoryRepository.FindBy(categoryId);
var categoryViewModel = category.ConvertToCategoryViewModel();
_unitOfWork.CategoryRepository.Update(category);
_unitOfWork.SaveChanges();
return categoryViewModel;
}
そして最後に、このような私のベースリポジトリ:
private readonly DbSet<T> _entitySet;
public void Update(T entity)
{
_entitySet.Attach(entity);
}
私UnitOfWork
もこれです:
public class UnitOfWork : IUnitOfWork
{
private IRepository<Category> _categoryRepository;
public IRepository<Category> CategoryRepository
{
get { return _categoryRepository ?? (_categoryRepository = new Repository<Category>(_statosContext)); }
}
}