示例#1
0
        public ActionResult Edit(EditorAutorViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Autor autor = _repositorio.ObterPorId(model.Id);

            autor.Nome = model.Nome;

            try
            {
                if (_repositorio.Atualizar(autor))
                {
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Mensagem", ex.Message);
                return(View(model));
            }

            return(View(autor));
        }
示例#2
0
        public ActionResult Create(EditorAutorViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Autor autor = new Autor {
                Nome = model.Nome
            };

            try
            {
                if (_repositorio.Inserir(autor))
                {
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Mensagem", ex.Message);
                return(View(model));
            }

            return(View(autor));
        }
示例#3
0
        public ActionResult Edit(int id)
        {
            EditorAutorViewModel model = PreencherAutorModel(id);

            ViewData.Add(nameof(eStatusForm), (int)eStatusForm.Alterar);
            return(View(model));
        }
示例#4
0
        public ActionResult View(int id)
        {
            ViewData.Add(nameof(eStatusForm), (int)eStatusForm.Visualizar);
            EditorAutorViewModel model = PreencherAutorModel(id);

            return(View(model));
        }
示例#5
0
        public ActionResult Delete(int id)
        {
            ViewData.Add(nameof(eStatusForm), (int)eStatusForm.Excluir);
            EditorAutorViewModel model = PreencherAutorModel(id);

            return(View(model));
        }
示例#6
0
        public ActionResult Create()
        {
            var model = new EditorAutorViewModel {
                Nome = ""
            };

            ViewData.Add(nameof(eStatusForm), (int)eStatusForm.Novo);
            return(View(model));
        }
示例#7
0
        private EditorAutorViewModel PreencherAutorModel(int id)
        {
            var autor = _repositorio.ObterPorId(id);
            var model = new EditorAutorViewModel {
                Id = autor.Id, Nome = autor.Nome
            };

            return(model);
        }
示例#8
0
        public ActionResult DeleteConfirm(EditorAutorViewModel model)
        {
            Autor autor = _repositorio.ObterPorId(model.Id);

            if (_repositorio.Excluir(autor.Id))
            {
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }