private Response Existe(ActividadesGestionCambio ActividadesGestionCambio)
        {
            var bdd = ActividadesGestionCambio.FechaInicio;
            var ActividadesGestionCambiorespuesta = db.ActividadesGestionCambio.Where(p => p.FechaInicio == ActividadesGestionCambio.FechaInicio &&
                                                                                      p.FechaFin == ActividadesGestionCambio.FechaFin &&
                                                                                      p.Descripcion == ActividadesGestionCambio.Descripcion &&
                                                                                      p.IdPlanGestionCambio == ActividadesGestionCambio.IdPlanGestionCambio
                                                                                      ).FirstOrDefault();

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

            return(new Response
            {
                IsSuccess = false,
                Resultado = ActividadesGestionCambiorespuesta,
            });
        }
Exemple #2
0
        public async Task <Response> AvanceGestionCambioSumaIndicadorReal([FromBody] ActividadesGestionCambio actividadesGestionCambio)
        {
            try
            {
                var sumaAvance = new AvanceGestionCambioModel
                {
                    Suma = db.AvanceGestionCambio.Where(m => m.IdActividadesGestionCambio == actividadesGestionCambio.IdActividadesGestionCambio).Sum(m => m.Indicadorreal)
                };

                var response = new Response
                {
                    IsSuccess = true,
                    Resultado = sumaAvance,
                };

                return(response);
            }
            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 {
                });
            }
        }
        public async Task <Response> ActividadesGestionCambioconIdActividad([FromBody] ActividadesGestionCambio actividadesGestionCambio)
        {
            try
            {
                var actividadesGestionCambioResultado = await db.ActividadesGestionCambio.SingleOrDefaultAsync(m => m.IdActividadesGestionCambio == actividadesGestionCambio.IdActividadesGestionCambio);

                var response = new Response
                {
                    IsSuccess = true,
                    Resultado = actividadesGestionCambioResultado,
                };

                return(response);
            }
            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 {
                });
            }
        }
        public async Task <IActionResult> Create(int IdPlanGestionCambio)
        {
            var actividadesGestionCambio = new ActividadesGestionCambio
            {
                IdPlanGestionCambio = IdPlanGestionCambio,
                FechaInicio         = DateTime.Now,
                FechaFin            = DateTime.Now,
            };

            return(View(actividadesGestionCambio));
        }
        public async Task <Response> InsertarActividadesGestionCambio([FromBody] ActividadesGestionCambioViewModel actividadesGestionCambioViewModel)
        {
            try {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ModeloInvalido,
                    });
                }

                var modelo = new ActividadesGestionCambio {
                    IdDependencia = actividadesGestionCambioViewModel.IdDependencia,
                    IdEmpleado    = actividadesGestionCambioViewModel.IdEmpleado,

                    Avance = actividadesGestionCambioViewModel.Avance,
                    EstadoActividadesGestionCambio = actividadesGestionCambioViewModel.ValorEstado,
                    Tarea         = actividadesGestionCambioViewModel.Tarea,
                    FechaInicio   = actividadesGestionCambioViewModel.FechaInicio,
                    FechaFin      = actividadesGestionCambioViewModel.FechaFin,
                    Observaciones = (String.IsNullOrEmpty(actividadesGestionCambioViewModel.Observaciones)) ? "" : actividadesGestionCambioViewModel.Observaciones
                };



                if (Existe(modelo).Result.IsSuccess)
                {
                    return(new Response {
                        IsSuccess = false,
                        Message = Mensaje.ExisteRegistro
                    });
                }

                db.ActividadesGestionCambio.Add(modelo);
                await db.SaveChangesAsync();


                return(new Response
                {
                    IsSuccess = true,
                    Message = Mensaje.GuardadoSatisfactorio
                });
            }
            catch (Exception ex)
            {
                return(new Response {
                    IsSuccess = false,
                    Message = Mensaje.Excepcion
                });
            }
        }
        public async Task <IActionResult> Edit(string id, ActividadesGestionCambio ActividadesGestionCambio)
        {
            Response response = new Response();

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

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

                        return(RedirectToAction("Index", new { IdPlanGestionCambio = ActividadesGestionCambio.IdPlanGestionCambio }));
                    }
                    ViewData["Error"] = response.Message;

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

                return(BadRequest());
            }
        }
        public async Task <IActionResult> Create(ActividadesGestionCambio ActividadesGestionCambio)
        {
            Response response = new Response();

            try
            {
                response = await apiServicio.InsertarAsync(ActividadesGestionCambio,
                                                           new Uri(WebApp.BaseAddress),
                                                           "/api/ActividadesGestionCambio/InsertarActividadesGestionCambio");

                if (response.IsSuccess)
                {
                    var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                    {
                        ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                        ExceptionTrace       = null,
                        Message              = "Se ha creado una actividad gestión de cambio",
                        UserName             = "******",
                        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                        LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                        EntityID             = string.Format("{0} {1}", "Actividad gestión de cambio:", ActividadesGestionCambio.IdActividadesGestionCambio),
                    });

                    return(RedirectToAction("Index", new { IdPlanGestionCambio = ActividadesGestionCambio.IdPlanGestionCambio }));
                }

                ViewData["Error"] = response.Message;

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

                return(BadRequest());
            }
        }
        private async Task <Response> Existe(ActividadesGestionCambio modelo)
        {
            try
            {
                var lista = await db.ActividadesGestionCambio
                            .Where(x =>
                                   x.Tarea.ToUpper().TrimEnd().TrimStart() == modelo.Tarea.ToUpper().TrimEnd().TrimStart()
                                   //&& x.FechaInicio.ToString("dd-mm-yyyy") == modelo.FechaInicio.ToString("dd-mm-yyyy")
                                   //&& x.FechaFin.ToString("dd-mm-yyyy") == modelo.FechaFin.ToString("dd-mm-yyyy")
                                   && x.IdDependencia == modelo.IdDependencia &&
                                   x.IdEmpleado == modelo.IdEmpleado
                                   )
                            .ToListAsync();

                if (
                    lista != null &&
                    lista.Count > 0 &&
                    modelo.IdActividadesGestionCambio != lista.FirstOrDefault().IdActividadesGestionCambio
                    )
                {
                    return(new Response
                    {
                        IsSuccess = true,
                        Message = Mensaje.ExisteRegistro
                    });
                }

                return(new Response
                {
                    IsSuccess = false
                });
            }
            catch (Exception)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Excepcion
                });
            }
        }
        public async Task <IActionResult> Index(int IdPlanGestionCambio, int IdActividadesGestionCambio)
        {
            try
            {
                if (IdPlanGestionCambio != 0 && IdActividadesGestionCambio == 0)
                {
                    var actividadesGestionCambio = new ActividadesGestionCambioViewModel
                    {
                        IdPlanGestionCambio = Convert.ToInt32(IdPlanGestionCambio),
                    };

                    var viewModelActividadesGestionCambio = new ActividadesGestionCambioViewModel
                    {
                        IdPlanGestionCambio           = Convert.ToInt32(IdPlanGestionCambio),
                        ListaActividadesGestionCambio = await apiServicio.Listar <ActividadesGestionCambioIndex>(actividadesGestionCambio, new Uri(WebApp.BaseAddress), "/api/ActividadesGestionCambio/ListarActividadesGestionCambioconIdPlan")
                    };

                    return(View(viewModelActividadesGestionCambio));
                }

                if (IdPlanGestionCambio == 0 && IdActividadesGestionCambio != 0)
                {
                    var actividadesGestionCambio = new ActividadesGestionCambio
                    {
                        IdActividadesGestionCambio = Convert.ToInt32(IdActividadesGestionCambio),
                    };


                    var respuesta = await apiServicio.ObtenerElementoAsync <ActividadesGestionCambio>(actividadesGestionCambio, new Uri(WebApp.BaseAddress),
                                                                                                      "/api/ActividadesGestionCambio/ActividadesGestionCambioconIdActividad");

                    var actividades = JsonConvert.DeserializeObject <ActividadesGestionCambio>(respuesta.Resultado.ToString());

                    var actividadesGestionCambioViewModel = new ActividadesGestionCambioViewModel
                    {
                        IdPlanGestionCambio = Convert.ToInt32(actividades.IdPlanGestionCambio),
                    };


                    var viewModelActividadesGestionCambio = new ActividadesGestionCambioViewModel
                    {
                        IdPlanGestionCambio           = Convert.ToInt32(actividades.IdPlanGestionCambio),
                        ListaActividadesGestionCambio = await apiServicio.Listar <ActividadesGestionCambioIndex>(actividadesGestionCambioViewModel, new Uri(WebApp.BaseAddress), "/api/ActividadesGestionCambio/ListarActividadesGestionCambioconIdPlan")
                    };


                    return(View(viewModelActividadesGestionCambio));
                }


                ViewData["Mensaje"] = "Ir a la página de Plan Gestión Cambio";
                return(View("NoExisteElemento"));
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                    Message              = "Listando una actividad de gestión de cambio",
                    ExceptionTrace       = ex,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.NetActivity),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                return(BadRequest());
            }
        }
Exemple #10
0
        public async Task <Response> PostAvanceGestionCambio([FromBody] AvanceGestionCambio AvanceGestionCambio)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = ""
                    });
                }


                if (AvanceGestionCambio.Indicadorreal == 0)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "El indicador real no puede ser cero"
                    });
                }


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

                string fecha = AvanceGestionCambio.Fecha.DayOfWeek.ToString();

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

                ActividadesGestionCambio Actividades = db.ActividadesGestionCambio.Find(AvanceGestionCambio.IdActividadesGestionCambio);

                if (Actividades.FechaInicio > AvanceGestionCambio.Fecha)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha del avance no puede ser menor a la fecha inicio de las actividades"
                    });
                }

                var respuesta = Existe(AvanceGestionCambio);
                if (!respuesta.IsSuccess)
                {
                    db.AvanceGestionCambio.Add(AvanceGestionCambio);
                    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,
                });
            }
        }
        public async Task <List <ActividadesGestionCambioIndex> > ListarActividadesGestionCambioconIdPlan([FromBody] ActividadesGestionCambio actividadesGestionCambio)
        {
            try
            {
                List <ActividadesGestionCambioIndex> listaActividadesGestionCambioTotal = new List <ActividadesGestionCambioIndex>();

                List <ActividadesGestionCambioIndex> ListaActividadGestionCambioAvance = await db.ActividadesGestionCambio
                                                                                         .Join(db.PlanGestionCambio
                                                                                               , actividades => actividades.IdPlanGestionCambio, planes => planes.IdPlanGestionCambio,
                                                                                               (actividades, planes) => new { ActividadesGestionCambio = actividades, PlanGestionCambio = planes })
                                                                                         .Join(db.AvanceGestionCambio
                                                                                               , actividades => actividades.ActividadesGestionCambio.IdActividadesGestionCambio, avance => avance.IdActividadesGestionCambio,
                                                                                               (actividades, avance) => new { ActividadesGestion = actividades, AvanceGestionCambio = avance })
                                                                                         .GroupBy(
                    x =>
                    new
                {
                    x.ActividadesGestion.ActividadesGestionCambio.IdPlanGestionCambio,
                    x.ActividadesGestion.ActividadesGestionCambio.IdActividadesGestionCambio,
                    x.ActividadesGestion.ActividadesGestionCambio.FechaInicio,
                    x.ActividadesGestion.ActividadesGestionCambio.FechaFin,
                    x.ActividadesGestion.ActividadesGestionCambio.Indicador,
                    x.ActividadesGestion.ActividadesGestionCambio.Porciento,
                    x.ActividadesGestion.ActividadesGestionCambio.Descripcion
                })
                                                                                         .Select(index => new ActividadesGestionCambioIndex
                {
                    IdPlanGestionCambio        = index.Key.IdPlanGestionCambio,
                    IdActividadesGestionCambio = index.Key.IdActividadesGestionCambio,
                    FechaInicio = index.Key.FechaInicio,
                    FechaFin    = index.Key.FechaFin,
                    Indicador   = index.Key.Indicador,
                    Porciento   = index.Key.Porciento,
                    Descripcion = index.Key.Descripcion,
                    Suma        = ((decimal?)index.Sum(actividades => actividades.AvanceGestionCambio.Indicadorreal)) ?? 0,
                    Porcentaje  = ((decimal?)(index.Sum(actividades => actividades.AvanceGestionCambio.Indicadorreal) * 100) / index.Key.Indicador) ?? 0
                })
                                                                                         .Where(x => x.IdPlanGestionCambio == actividadesGestionCambio.IdPlanGestionCambio)
                                                                                         .ToListAsync();

                var ListaActividadGestionCambioPlan = db.ActividadesGestionCambio
                                                      .Where(x => x.IdPlanGestionCambio == actividadesGestionCambio.IdPlanGestionCambio);

                if (ListaActividadGestionCambioAvance.Count != 0)
                {
                    foreach (var elementoPlan in ListaActividadGestionCambioPlan)
                    {
                        foreach (var elementoAvance in ListaActividadGestionCambioAvance)
                        {
                            bool existeConsulta = ListaActividadGestionCambioAvance.Exists(x => x.IdActividadesGestionCambio == elementoPlan.IdActividadesGestionCambio);

                            bool existeLista = listaActividadesGestionCambioTotal.Exists(x => x.IdActividadesGestionCambio == elementoPlan.IdActividadesGestionCambio);

                            if (!existeConsulta)
                            {
                                if (!existeLista)
                                {
                                    ActividadesGestionCambioIndex actividad = new ActividadesGestionCambioIndex();
                                    actividad.IdPlanGestionCambio        = elementoPlan.IdPlanGestionCambio;
                                    actividad.IdActividadesGestionCambio = elementoPlan.IdActividadesGestionCambio;
                                    actividad.FechaInicio = elementoPlan.FechaInicio;
                                    actividad.FechaFin    = elementoPlan.FechaFin;
                                    actividad.Indicador   = elementoPlan.Indicador;
                                    actividad.Porciento   = elementoPlan.Porciento;
                                    actividad.Descripcion = elementoPlan.Descripcion;
                                    actividad.Suma        = 0;
                                    actividad.Porcentaje  = 0;
                                    listaActividadesGestionCambioTotal.Add(actividad);
                                }
                            }
                            else
                            {
                                if (!existeLista)
                                {
                                    if (elementoAvance.IdActividadesGestionCambio == elementoPlan.IdActividadesGestionCambio)
                                    {
                                        ActividadesGestionCambioIndex actividad = new ActividadesGestionCambioIndex();
                                        actividad.IdPlanGestionCambio        = elementoAvance.IdPlanGestionCambio;
                                        actividad.IdActividadesGestionCambio = elementoAvance.IdActividadesGestionCambio;
                                        actividad.FechaInicio = elementoAvance.FechaInicio;
                                        actividad.FechaFin    = elementoAvance.FechaFin;
                                        actividad.Indicador   = elementoAvance.Indicador;
                                        actividad.Porciento   = elementoAvance.Porciento;
                                        actividad.Descripcion = elementoAvance.Descripcion;
                                        actividad.Suma        = elementoAvance.Suma;
                                        actividad.Porcentaje  = elementoAvance.Porcentaje;

                                        listaActividadesGestionCambioTotal.Add(actividad);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (ListaActividadGestionCambioAvance.Count == 0)
                    {
                        foreach (var elementoPlan in ListaActividadGestionCambioPlan)
                        {
                            ActividadesGestionCambioIndex actividad = new ActividadesGestionCambioIndex();
                            actividad.IdPlanGestionCambio        = elementoPlan.IdPlanGestionCambio;
                            actividad.IdActividadesGestionCambio = elementoPlan.IdActividadesGestionCambio;
                            actividad.FechaInicio = elementoPlan.FechaInicio;
                            actividad.FechaFin    = elementoPlan.FechaFin;
                            actividad.Indicador   = elementoPlan.Indicador;
                            actividad.Porciento   = elementoPlan.Porciento;
                            actividad.Descripcion = elementoPlan.Descripcion;
                            actividad.Suma        = 0;
                            actividad.Porcentaje  = 0;
                            listaActividadesGestionCambioTotal.Add(actividad);
                        }
                    }
                }
                return(listaActividadesGestionCambioTotal);
            }
            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 List <ActividadesGestionCambioIndex>());
            }
        }
        public async Task <Response> PutActividadesGestionCambio([FromRoute] int id, [FromBody] ActividadesGestionCambio actividadesGestionCambio)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ModeloInvalido
                    });
                }

                if (actividadesGestionCambio.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 (actividadesGestionCambio.Indicador == 0)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "El indicador no puede ser cero"
                    });
                }

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

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

                string fechaInicio = actividadesGestionCambio.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 = actividadesGestionCambio.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"
                    });
                }


                PlanGestionCambio Planes = db.PlanGestionCambio.Find(actividadesGestionCambio.IdPlanGestionCambio);

                if (Planes.FechaInicio > actividadesGestionCambio.FechaInicio)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = "La fecha inicio del plan no puede ser mayor a la fecha inicio de actividades"
                    });
                }
                var existe = Existe(actividadesGestionCambio);
                var ActividadesGestionCambioActualizar = (ActividadesGestionCambio)existe.Resultado;
                if (existe.IsSuccess)
                {
                    if (ActividadesGestionCambioActualizar.IdActividadesGestionCambio == actividadesGestionCambio.IdActividadesGestionCambio)
                    {
                        return(new Response
                        {
                            IsSuccess = true,
                        });
                    }
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ExisteRegistro,
                    });
                }
                var ActividadesGestionCambio = db.ActividadesGestionCambio.Find(actividadesGestionCambio.IdActividadesGestionCambio);

                ActividadesGestionCambio.FechaInicio = actividadesGestionCambio.FechaInicio;
                ActividadesGestionCambio.FechaFin    = actividadesGestionCambio.FechaFin;
                ActividadesGestionCambio.Indicador   = actividadesGestionCambio.Indicador;
                ActividadesGestionCambio.Porciento   = actividadesGestionCambio.Porciento;
                ActividadesGestionCambio.Descripcion = actividadesGestionCambio.Descripcion;

                db.ActividadesGestionCambio.Update(ActividadesGestionCambio);
                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,
                });
            }
        }
Exemple #13
0
        public async Task <IActionResult> Create(AvanceGestionCambio AvanceGestionCambio)
        {
            Response response = new Response();

            try
            {
                var actividadesGestionCambio = new ActividadesGestionCambio
                {
                    IdActividadesGestionCambio = AvanceGestionCambio.IdActividadesGestionCambio,
                };

                var respuestaActividades = await apiServicio.ObtenerElementoAsync <ActividadesGestionCambio>(actividadesGestionCambio, new Uri(WebApp.BaseAddress),
                                                                                                             "/api/ActividadesGestionCambio/ActividadesGestionCambioconIdActividad");

                var actividades = JsonConvert.DeserializeObject <ActividadesGestionCambio>(respuestaActividades.Resultado.ToString());

                var respuestaSuma = await apiServicio.ObtenerElementoAsync <ActividadesGestionCambio>(actividadesGestionCambio, new Uri(WebApp.BaseAddress),
                                                                                                      "/api/AvancesGestionCambio/AvanceGestionCambioSumaIndicadorReal");

                var suma = JsonConvert.DeserializeObject <AvanceGestionCambioModel>(respuestaSuma.Resultado.ToString());

                if ((suma.Suma + AvanceGestionCambio.Indicadorreal) <= actividades.Indicador)
                {
                    response = await apiServicio.InsertarAsync(AvanceGestionCambio,
                                                               new Uri(WebApp.BaseAddress),
                                                               "/api/AvancesGestionCambio/InsertarAvanceGestionCambio");

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

                        return(RedirectToAction("Index", new { IdActividadesGestionCambio = AvanceGestionCambio.IdActividadesGestionCambio }));
                    }
                    else
                    {
                        ViewData["Error"] = response.Message;
                        return(View(AvanceGestionCambio));
                    }
                }
                else
                {
                    string mensaje = "No se puede crear el avance de control cambio ya que el indicador de la actividad es " + actividades.Indicador + " y la suma del indicador real es de " + suma.Suma + "  y al aumentarle " + AvanceGestionCambio.Indicadorreal + " sobrepasaría en " + ((suma.Suma + AvanceGestionCambio.Indicadorreal) - actividades.Indicador);
                    ViewData["Error"] = mensaje;
                    return(View(AvanceGestionCambio));
                }
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppTh),
                    Message              = "Creando un avance gestión de cambio",
                    ExceptionTrace       = ex,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                return(BadRequest());
            }
        }