Ejemplo n.º 1
0
        public async Task <IActionResult> Create(PlanGestionCambio PlanGestionCambio)
        {
            Response response = new Response();

            try
            {
                PlanGestionCambio.AprobadoPor  = 1;
                PlanGestionCambio.RealizadoPor = 2;

                response = await apiServicio.InsertarAsync(PlanGestionCambio,
                                                           new Uri(WebApp.BaseAddress),
                                                           "/api/PlanesGestionCambio/InsertarPlanGestionCambio");

                if (response.IsSuccess)
                {
                    var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                    {
                        ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                        ExceptionTrace       = null,
                        Message              = "Se ha creado un plan gestión cambio",
                        UserName             = "******",
                        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                        LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                        EntityID             = string.Format("{0} {1}", "Plan Gestión Cambio:", PlanGestionCambio.IdPlanGestionCambio),
                    });

                    return(RedirectToAction("Index"));
                }

                ViewData["Error"] = response.Message;

                return(View(PlanGestionCambio));
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                    Message              = "Creando el plan gestión cambio",
                    ExceptionTrace       = ex,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                return(BadRequest());
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(string id, PlanGestionCambio PlanGestionCambio)
        {
            Response response = new Response();

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

                    if (response.IsSuccess)
                    {
                        await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                        {
                            ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                            EntityID             = string.Format("{0} : {1}", "Plan gestión cambio", id),
                            LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit),
                            LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                            Message  = "Se ha actualizado un plan gestión el cambio",
                            UserName = "******"
                        });

                        return(RedirectToAction("Index"));
                    }
                    ViewData["Error"] = response.Message;

                    return(View(PlanGestionCambio));
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                    Message              = "Editando un plan gestión cambio",
                    ExceptionTrace       = ex,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                return(BadRequest());
            }
        }
Ejemplo n.º 3
0
        private Response Existe(PlanGestionCambio PlanGestionCambio)
        {
            var bdd = PlanGestionCambio.Titulo.ToUpper().TrimEnd().TrimStart();
            var PlanGestionCambiorespuesta = db.PlanGestionCambio.Where(p => p.Titulo.ToUpper().TrimStart().TrimEnd() == bdd && p.FechaInicio == PlanGestionCambio.FechaInicio && p.FechaFin == PlanGestionCambio.FechaFin && p.RealizadoPor == PlanGestionCambio.RealizadoPor && p.AprobadoPor == PlanGestionCambio.AprobadoPor).FirstOrDefault();

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

            return(new Response
            {
                IsSuccess = false,
                Resultado = PlanGestionCambiorespuesta,
            });
        }
Ejemplo n.º 4
0
        public async Task <Response> PostPlanGestionCambio([FromBody] PlanGestionCambio PlanGestionCambio)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = ""
                    });
                }

                if (PlanGestionCambio.FechaInicio <= DateTime.Today)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha de inicio no puede ser menor o igual que la fecha de hoy"
                    });
                }

                if (PlanGestionCambio.FechaFin <= DateTime.Today)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha fin no puede ser menor o igual que la fecha de hoy"
                    });
                }

                if (PlanGestionCambio.FechaInicio >= PlanGestionCambio.FechaFin)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha de inicio no puede ser mayor o igual que la fecha fin"
                    });
                }

                string fechaInicio = PlanGestionCambio.FechaInicio.DayOfWeek.ToString();

                if (fechaInicio.Equals("Saturday") || fechaInicio.Equals("Sunday"))
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha de inicio no puede ser fin de semana"
                    });
                }


                string fechaFin = PlanGestionCambio.FechaFin.DayOfWeek.ToString();

                if (fechaFin.Equals("Saturday") || fechaFin.Equals("Sunday"))
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha fin no puede ser fin de semana"
                    });
                }


                var respuesta = Existe(PlanGestionCambio);
                if (!respuesta.IsSuccess)
                {
                    db.PlanGestionCambio.Add(PlanGestionCambio);
                    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              = Mensaje.Excepcion,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "",
                });

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Error,
                });
            }
        }
Ejemplo n.º 5
0
        public async Task <Response> PutPlanGestionCambio([FromRoute] int id, [FromBody] PlanGestionCambio planGestionCambio)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ModeloInvalido
                    });
                }

                if (planGestionCambio.FechaInicio <= DateTime.Today)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha de inicio no puede ser menor o igual que la fecha de hoy"
                    });
                }

                if (planGestionCambio.FechaFin <= DateTime.Today)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha fin no puede ser menor o igual que la fecha de hoy"
                    });
                }

                if (planGestionCambio.FechaInicio >= planGestionCambio.FechaFin)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha de inicio no puede ser mayor o igual que la fecha fin"
                    });
                }

                string fechaInicio = planGestionCambio.FechaInicio.DayOfWeek.ToString();

                if (fechaInicio.Equals("Saturday") || fechaInicio.Equals("Sunday"))
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha de inicio no puede ser fin de semana"
                    });
                }


                string fechaFin = planGestionCambio.FechaFin.DayOfWeek.ToString();

                if (fechaFin.Equals("Saturday") || fechaFin.Equals("Sunday"))
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha fin no puede ser fin de semana"
                    });
                }



                var existe = Existe(planGestionCambio);
                var PlanGestionCambioActualizar = (PlanGestionCambio)existe.Resultado;
                if (existe.IsSuccess)
                {
                    if (PlanGestionCambioActualizar.IdPlanGestionCambio == planGestionCambio.IdPlanGestionCambio)
                    {
                        return(new Response
                        {
                            IsSuccess = true,
                        });
                    }
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ExisteRegistro,
                    });
                }
                var PlanGestionCambio = db.PlanGestionCambio.Find(planGestionCambio.IdPlanGestionCambio);

                PlanGestionCambio.Titulo       = planGestionCambio.Titulo;
                PlanGestionCambio.Descripcion  = planGestionCambio.Descripcion;
                PlanGestionCambio.FechaInicio  = planGestionCambio.FechaInicio;
                PlanGestionCambio.FechaFin     = planGestionCambio.FechaFin;
                PlanGestionCambio.RealizadoPor = planGestionCambio.RealizadoPor;
                PlanGestionCambio.AprobadoPor  = planGestionCambio.AprobadoPor;
                db.PlanGestionCambio.Update(PlanGestionCambio);
                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              = Mensaje.Excepcion,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "",
                });

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