예제 #1
0
        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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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"));
        }
예제 #4
0
        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"));
        }