public ActionResult Create(EstadoModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Estado estado = new Estado();
                    estado.Nome = model.Nome;
                    estado.Sigla = model.Sigla;
                    estado.Pais = model.Pais;
                    estado.Regiao = model.Regiao;

                    var business = new EstadoBusiness();
                    business.Salvar(estado);

                    ModelState.AddModelError(string.Empty, "Cadastro efetuado com sucesso.");

                    return RedirectToAction("Index");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, "Um erro ocorreu ao tentar salvar o Estado: " + ex.Message);
                    return View();
                }
            }
            else
            {
                return View();
            }
        }
 public JsonResult Delete(int id)
 {
     try
     {
         var business = new EstadoBusiness();
         business.Excluir(id);
         return Json(new { Data = string.Empty, Success = true }, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         return Json(new { Data = ex.Message, Success = false }, JsonRequestBehavior.AllowGet);
     }
 }
 public ActionResult Edit(int id)
 {
     EstadoModel estado = new EstadoModel();
     try
     {
         var business = new EstadoBusiness();
         estado = FromModelToView(business.GetById(id));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError(string.Empty, "Um erro ocorreu ao tentar recupearar o Estado: " + ex.Message);
         RedirectToAction("Index");
     }
     return View(estado);
 }
 private void AddListaEstado(int? IdSelecionado)
 {
     try
     {
         var business = new EstadoBusiness();
         SelectList lista = new SelectList(business.GetAll(), "IdEstado", "Nome", IdSelecionado.GetValueOrDefault());
         ViewBag.Estados = lista;
     }
     catch (Exception ex)
     {
         ModelState.AddModelError(string.Empty, "Não foi possível carregar a lista de estados. " + ex.Message);
     }
 }
        public ActionResult Edit(EstadoModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var business = new EstadoBusiness();
                    business.Salvar(FromViewToModel(model));

                    ModelState.AddModelError(string.Empty, "Alteração efetuada com sucesso.");

                    return RedirectToAction("Index");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, "Erro ao alterar Cidade: " + ex.Message);
                    return View();
                }
            }
            else
            {
                return View();
            }
        }
 public ActionResult Index()
 {
     IList<EstadoModel> estados = new List<EstadoModel>();
     try
     {
         var business = new EstadoBusiness();
         foreach(var item in business.GetAll())
         {
             estados.Add(FromModelToView(item));
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError(string.Empty, "Um erro ocorreu ao tentar recupearar os Estados: " + ex.Message);
     }
     return View(estados);
 }