コード例 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            try
            {
                var daoEstados = new DAOEstado();

                if (daoEstados.Delete(id))
                {
                    TempData["message"] = "Registro excluído com sucesso!";
                    TempData["type"]    = "sucesso";
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                TempData["message"] = "O registro não pode ser excluído, pois está associado a uma cidade!";
                TempData["type"]    = "erro";
                return(RedirectToAction("Index"));
            }
        }
コード例 #2
0
        private IQueryable <dynamic> Find(int?id, string q)
        {
            var daoEstados = new DAOEstado();
            var list       = daoEstados.GetEstados();
            var select     = list.Select(u => new
            {
                id             = u.idEstado,
                text           = u.nmEstado,
                uf             = u.uf,
                dtCadastro     = u.dtCadastro,
                dtUltAlteracao = u.dtAtualizacao
            }).OrderBy(u => u.text).ToList();

            if (id != null)
            {
                return(select.Where(u => u.id == id).AsQueryable());
            }
            else
            {
                return(select.AsQueryable());
            }
        }
コード例 #3
0
        public JsonResult JsCreate(Estado estado)
        {
            var dtAtual = DateTime.Today;

            estado.dtCadastro    = dtAtual;
            estado.dtAtualizacao = dtAtual;
            try
            {
                var daoEstados = new DAOEstado();
                daoEstados.Create(estado);
                var result = new
                {
                    type    = "success",
                    message = "Estado adicionado",
                    model   = estado
                };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }