public async Task <Response> PostCapacitacionAreaConocimiento([FromBody] CapacitacionAreaConocimiento CapacitacionAreaConocimiento)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = ""
                    });
                }

                var respuesta = Existe(CapacitacionAreaConocimiento);
                if (!respuesta.IsSuccess)
                {
                    db.CapacitacionAreaConocimiento.Add(CapacitacionAreaConocimiento);
                    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. 2
0
        public async Task <IActionResult> Create(CapacitacionAreaConocimiento capacitacionAreaConocimiento)
        {
            if (!ModelState.IsValid)
            {
                InicializarMensaje(null);
                return(View(capacitacionAreaConocimiento));
            }
            Response response = new Response();

            try
            {
                response = await apiServicio.InsertarAsync(capacitacionAreaConocimiento,
                                                           new Uri(WebApp.BaseAddress),
                                                           "api/CapacitacionesAreasConocimientos/InsertarCapacitacionAreaConocimiento");

                if (response.IsSuccess)
                {
                    var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                    {
                        ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                        ExceptionTrace       = null,
                        Message              = "Se ha creado un capacitación de un área de conocimientos",
                        UserName             = "******",
                        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                        LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                        EntityID             = string.Format("{0} {1}", "Capacitación de Area de Conocimiento:", capacitacionAreaConocimiento.IdCapacitacionAreaConocimiento),
                    });

                    return(RedirectToAction("Index"));
                }

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

                return(BadRequest());
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(string id, CapacitacionAreaConocimiento capacitacionAreaConocimiento)
        {
            Response response = new Response();

            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    response = await apiServicio.EditarAsync(id, capacitacionAreaConocimiento, new Uri(WebApp.BaseAddress),
                                                             "api/CapacitacionesAreasConocimientos");

                    if (response.IsSuccess)
                    {
                        await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                        {
                            ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                            EntityID             = string.Format("{0} : {1}", "Capacitación de Area de Conocimiento", id),
                            LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit),
                            LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                            Message  = "Se ha actualizado un capacitación de un área de conocimientos",
                            UserName = "******"
                        });

                        return(RedirectToAction("Index"));
                    }
                    ViewData["Error"] = response.Message;
                    return(View(capacitacionAreaConocimiento));
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                    Message              = "Editando un capacitación de un área de conocimientos",
                    ExceptionTrace       = ex.Message,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                return(BadRequest());
            }
        }
        private Response Existe(CapacitacionAreaConocimiento CapacitacionAreaConocimiento)
        {
            var bdd = CapacitacionAreaConocimiento.Descripcion.ToUpper().TrimEnd().TrimStart();
            var CapacitacionAreaConocimientorespuesta = db.CapacitacionAreaConocimiento.Where(p => p.Descripcion.ToUpper().TrimStart().TrimEnd() == bdd).FirstOrDefault();

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

            return(new Response
            {
                IsSuccess = false,
                Resultado = CapacitacionAreaConocimientorespuesta,
            });
        }
        public async Task <Response> PutCapacitacionAreaConocimiento([FromRoute] int id, [FromBody] CapacitacionAreaConocimiento CapacitacionAreaConocimiento)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ModeloInvalido
                    });
                }

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

                var CapacitacionAreaConocimientoActualizar = await db.CapacitacionAreaConocimiento.Where(x => x.IdCapacitacionAreaConocimiento == id).FirstOrDefaultAsync();

                if (CapacitacionAreaConocimientoActualizar != null)
                {
                    try
                    {
                        CapacitacionAreaConocimientoActualizar.Descripcion = CapacitacionAreaConocimiento.Descripcion;
                        db.CapacitacionAreaConocimiento.Update(CapacitacionAreaConocimientoActualizar);
                        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
                });
            }
        }