示例#1
0
        // GET: DeduccionesIndividuales/Edit/5
        public ActionResult Edit(int?id)
        {
            db.Configuration.ProxyCreationEnabled = false;
            tbDeduccionesIndividuales tbDeduccionesIndividualesJSON = db.tbDeduccionesIndividuales.Find(id);

            return(Json(tbDeduccionesIndividualesJSON, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public ActionResult Create(string dei_Motivo, int emp_Id, decimal dei_MontoInicial, decimal dei_MontoRestante, decimal dei_Cuota, bool dei_PagaSiempre)
        {
            tbDeduccionesIndividuales tbDeduccionesIndividuales = new tbDeduccionesIndividuales
            {
                dei_Motivo        = dei_Motivo,
                emp_Id            = emp_Id,
                dei_MontoInicial  = dei_MontoInicial,
                dei_MontoRestante = dei_MontoRestante,
                dei_Cuota         = dei_Cuota,
                dei_PagaSiempre   = dei_PagaSiempre
            };

            //LLENAR LA DATA DE AUDITORIA, DE NO HACERLO EL MODELO NO SERÍA VÁLIDO Y SIEMPRE CAERÍA EN EL CATCH
            tbDeduccionesIndividuales.dei_UsuarioCrea = 1;
            tbDeduccionesIndividuales.dei_FechaCrea   = DateTime.Now;
            //VARIABLE PARA ALMACENAR EL RESULTADO DEL PROCESO Y ENVIARLO AL LADO DEL CLIENTE
            string response = String.Empty;
            IEnumerable <object> listDeduccionIndividuales = null;
            string MensajeError = "";

            //VALIDAR SI EL MODELO ES VÁLIDO
            if (ModelState.IsValid)
            {
                try
                {
                    //EJECUTAR PROCEDIMIENTO ALMACENADO
                    listDeduccionIndividuales = db.UDP_Plani_tbDeduccionesIndividuales_Insert(tbDeduccionesIndividuales.dei_Motivo,
                                                                                              tbDeduccionesIndividuales.emp_Id,
                                                                                              tbDeduccionesIndividuales.dei_MontoInicial,
                                                                                              tbDeduccionesIndividuales.dei_MontoRestante,
                                                                                              tbDeduccionesIndividuales.dei_Cuota,
                                                                                              tbDeduccionesIndividuales.dei_PagaSiempre,
                                                                                              tbDeduccionesIndividuales.dei_UsuarioCrea,
                                                                                              tbDeduccionesIndividuales.dei_FechaCrea);
                    //RECORRER EL TIPO COMPLEJO DEL PROCEDIMIENTO ALMACENADO PARA EVALUAR EL RESULTADO DEL SP
                    foreach (UDP_Plani_tbDeduccionesIndividuales_Insert_Result Resultado in listDeduccionIndividuales)
                    {
                        MensajeError = Resultado.MensajeError;
                    }

                    if (MensajeError.StartsWith("-1"))
                    {
                        //EN CASO DE OCURRIR UN ERROR, IGUALAMOS LA VARIABLE "RESPONSE" A ERROR PARA VALIDARLO EN EL CLIENTE
                        ModelState.AddModelError("", "No se pudo ingresar el registro, contacte al administrador");
                        response = "error";
                    }
                }
                catch (Exception Ex)
                {
                    //EN CASO DE CAER EN EL CATCH, IGUALAMOS LA VARIABLE "RESPONSE" A ERROR PARA VALIDARLO EN EL CLIENTE
                    response = Ex.Message.ToString();
                }
                //SI LA EJECUCIÓN LLEGA A ESTE PUNTO SIGNIFICA QUE NO OCURRIÓ NINGÚN ERROR Y EL PROCESO FUE EXITOSO
                //IGUALAMOS LA VARIABLE "RESPONSE" A "BIEN" PARA VALIDARLO EN EL CLIENTE
                response = "bien";
            }
            else
            {
                //SI EL MODELO NO ES VÁLIDO, IGUALAMOS LA VARIABLE "RESPONSE" A ERROR PARA VALIDARLO EN EL CLIENTE
                response = "error";
            }
            //RETORNAMOS LA VARIABLE RESPONSE AL CLIENTE PARA EVALUARLA

            return(Json(response, JsonRequestBehavior.AllowGet));
        }