public async Task <IActionResult> Editar(int Id) { var prod = await _categoriaRepository.GetAsync(Id); var vm = new CategoriaAddEditVM() { Id = Id, Nome = prod.Nome }; return(View(vm)); }
public async Task <IActionResult> AddEdit(int Id) { var model = new CategoriaAddEditVM(); if (Id != 0) { var data = await _categoriaRepository.GetAsync(Id); model = data.ToCategoriaAddEditVM(); } return(View(model)); }
public IActionResult Salvar(CategoriaAddEditVM model) { if (!ModelState.IsValid) { return(View("Adicionar", model)); } var prod = new Categoria() { Id = model.Id, Nome = model.Nome }; if (model.Id == 0) { _categoriaRepository.Add(prod); } else { _categoriaRepository.Update(prod); } return(RedirectToAction("Index")); }
public async Task <IActionResult> AddEdit(int Id, CategoriaAddEditVM model) { if (!ModelState.IsValid) { return(View(model)); } var cat = model.ToData(); if (Id == 0) { _categoriaRepository.Add(cat); } else { cat.Id = Id; cat.DataAlteracao = DateTime.Now; _categoriaRepository.Update(cat); } await _uow.CommitAsync(); return(RedirectToAction("Index")); }