Esempio n. 1
0
        public async Task <IActionResult> Create(CeseFuncion ceseFuncion)
        {
            if (!ModelState.IsValid)
            {
                InicializarMensaje(null);
                return(View(ceseFuncion));
            }
            Response response = new Response();

            try
            {
                ceseFuncion.Fecha = DateTime.Now;
                response          = await apiServicio.InsertarAsync(ceseFuncion,
                                                                    new Uri(WebApp.BaseAddress),
                                                                    "api/CeseFunciones/InsertarCeseFuncion");

                if (response.IsSuccess)
                {
                    var empleado = new Empleado
                    {
                        IdEmpleado = ceseFuncion.IdEmpleado,
                    };
                    response = await apiServicio.EditarAsync(ceseFuncion.IdEmpleado.ToString(), empleado, new Uri(WebApp.BaseAddress),
                                                             "api/Empleados");

                    var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                    {
                        ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                        ExceptionTrace       = null,
                        Message              = "Se ha creado un cese de funciones",
                        UserName             = "******",
                        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                        LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                        EntityID             = string.Format("{0} {1}", "Cese de Funciones:", ceseFuncion.IdCeseFuncion),
                    });

                    return(RedirectToAction("SeleccionarDependencia"));
                }

                ViewData["Error"] = response.Message;
                return(View(ceseFuncion));
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                    Message              = "Creando Cese de Funciones",
                    ExceptionTrace       = ex.Message,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                return(BadRequest());
            }
        }
Esempio n. 2
0
        public async Task <Response> PostCeseFuncion([FromBody] CeseFuncion CeseFuncion)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = ""
                    });
                }

                var respuesta = Existe(CeseFuncion);
                if (!respuesta.IsSuccess)
                {
                    db.CeseFuncion.Add(CeseFuncion);
                    await db.SaveChangesAsync();

                    return(new Response
                    {
                        IsSuccess = true,
                        Message = Mensaje.Satisfactorio
                    });
                }

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.SwTH),
                    ExceptionTrace       = ex.Message,
                    Message              = Mensaje.Excepcion,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "",
                });

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Error,
                });
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Create(int id, string mensaje)
        {
            try
            {
                if (id != 0)
                {
                    //var respuesta = await apiServicio.SeleccionarAsync<Response>(id.ToString(), new Uri(WebApp.BaseAddress),
                    //                                              "api/CeseFunciones");

                    //if (respuesta.IsSuccess && respuesta.Resultado != null)
                    //{
                    //    respuesta.Resultado = JsonConvert.DeserializeObject<CeseFuncion>(respuesta.Resultado.ToString());
                    //    ViewData["IdTipoCesacionFuncion"] = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await apiServicio.Listar<TipoCesacionFuncion>(new Uri(WebApp.BaseAddress), "api/TipoCesacionFunciones/ListarTipoCesacionFunciones"), "IdTipoCesacionFuncion", "Nombre");
                    //    return View(respuesta.Resultado);
                    //}
                    //else
                    //{

                    var empleadoEnviar = new Empleado
                    {
                        IdEmpleado = id,
                    };
                    var empleado = await apiServicio.ObtenerElementoAsync1 <EmpleadoSolicitudViewModel>(empleadoEnviar, new Uri(WebApp.BaseAddress), "api/Empleados/ObtenerDatosEmpleadoSeleccionado");

                    ViewData["IdTipoCesacionFuncion"] = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await apiServicio.Listar <TipoCesacionFuncion>(new Uri(WebApp.BaseAddress), "api/TipoCesacionFunciones/ListarTipoCesacionFunciones"), "IdTipoCesacionFuncion", "Nombre");
                    ViewData["NombresApellidos"]      = empleado.NombreApellido;
                    ViewData["Identificacion"]        = empleado.Identificacion;

                    var ceseFuncion = new CeseFuncion
                    {
                        IdEmpleado = id,
                    };
                    InicializarMensaje(mensaje);
                    return(View(ceseFuncion));
                    //}
                }



                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Esempio n. 4
0
        private Response Existe(CeseFuncion CeseFuncion)
        {
            var bdd = CeseFuncion.IdEmpleado;
            var cesefuncionrespuesta = db.CeseFuncion.Where(p => p.IdEmpleado == bdd).FirstOrDefault();

            if (cesefuncionrespuesta != null)
            {
                return(new Response
                {
                    IsSuccess = true,
                    Message = Mensaje.ExisteRegistro,
                    Resultado = null,
                });
            }

            return(new Response
            {
                IsSuccess = false,
                Resultado = cesefuncionrespuesta,
            });
        }
Esempio n. 5
0
        public async Task <Response> PutCeseFuncion([FromRoute] int id, [FromBody] CeseFuncion ceseFuncion)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ModeloInvalido
                    });
                }

                var existe = Existe(ceseFuncion);
                if (existe.IsSuccess)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ExisteRegistro,
                    });
                }

                var ceseFuncionActualizar = await db.CeseFuncion.Where(x => x.IdCeseFuncion == id).FirstOrDefaultAsync();

                if (ceseFuncionActualizar != null)
                {
                    try
                    {
                        ceseFuncionActualizar.IdEmpleado            = ceseFuncion.IdEmpleado;
                        ceseFuncionActualizar.IdTipoCesacionFuncion = ceseFuncion.IdTipoCesacionFuncion;
                        ceseFuncionActualizar.Fecha       = ceseFuncion.Fecha;
                        ceseFuncionActualizar.Observacion = ceseFuncion.Observacion;
                        await db.SaveChangesAsync();

                        return(new Response
                        {
                            IsSuccess = true,
                            Message = Mensaje.Satisfactorio,
                        });
                    }
                    catch (Exception ex)
                    {
                        await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                        {
                            ApplicationName      = Convert.ToString(Aplicacion.SwTH),
                            ExceptionTrace       = ex.Message,
                            Message              = Mensaje.Excepcion,
                            LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                            LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                            UserName             = "",
                        });

                        return(new Response
                        {
                            IsSuccess = false,
                            Message = Mensaje.Error,
                        });
                    }
                }



                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Excepcion
                });
            }
        }