예제 #1
0
        public async Task <IActionResult> DeleteCamion([FromRoute] int id)
        {
            try
            {
                LCamion.EliminarCamion(id, _context);
                return(Json(new { success = true, message = "Camión eliminado correctamente" }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
예제 #2
0
        public async Task <IActionResult> GetCamionesActivos()
        {
            try
            {
                List <Camion> lstCamiones = LCamion.ConsultarCamionesActivos(_context);
                return(Json(new { success = true, message = lstCamiones }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
예제 #3
0
        public async Task <IActionResult> PostCamion([FromBody] Camion Camion)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                LCamion.GuardarCamion(Camion, _context);
                return(Json(new { success = true, message = "Camión guardado correctamente" }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
예제 #4
0
        public async Task <IActionResult> GetCamionById([FromRoute] int id)
        {
            try
            {
                Camion Camion = LCamion.ConsultarCamionPorId(id, _context);

                if (Camion == null)
                {
                    return(Json(new { success = false, message = "Camion no encontrado" }));
                }

                return(Json(new { success = true, message = Camion }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
예제 #5
0
        public async Task <IActionResult> PutCamion([FromRoute] int id, [FromBody] Camion Camion)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                if (Camion.Id != id)
                {
                    return(Json(new { success = false, message = "No se pude editar el id del Camión" }));
                }

                LCamion.EditarCamion(Camion, _context);
                return(Json(new { success = true, message = "Camión editado correctamente" }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }