public HttpResponseMessage createNorma([FromBody] NormaEntity normaEntity, [FromUri] int[] normaSectorArray)
        {
            var  idNormaObject = _normaServices.CreateNorma(normaEntity);
            bool sector        = false;

            if (idNormaObject != null && idNormaObject[0].Equals("0000"))
            {
                var idNorma = (int)idNormaObject.ElementAt(1);

                foreach (int idSectorServicio in normaSectorArray)
                {
                    var flagObject = _normaSectorServices.CreateNormaSector(idSectorServicio, idNorma);
                    if (flagObject[0].Equals("0000"))
                    {
                        bool flag = (bool)flagObject.ElementAt(1);

                        if (!flag)
                        {
                            return(Request.CreateResponse(HttpStatusCode.InternalServerError, false));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.InternalServerError, flagObject));
                    }
                }
                return(Request.CreateResponse(HttpStatusCode.OK, true));
            }
            return(Request.CreateResponse(HttpStatusCode.InternalServerError, idNormaObject));
        }
        public HttpResponseMessage byId([FromBody] IdEntity entity)
        {
            int id = 0;

            if (entity != null)
            {
                id = entity.Id;
            }

            var norma = _normaServices.GetNormaById(id);

            if (norma != null && norma[0].Equals("0000"))
            {
                NormaEntity normaEnt    = (NormaEntity)norma.ElementAt(1);
                var         normaSector = _normaSectorServices.GetNormaSectorById(normaEnt.IdNorma).ToList();

                if (normaSector != null && normaSector[0].Equals("0000"))
                {
                    List <NormaSectorEntity> normasSectorEnt = (List <NormaSectorEntity>)normaSector.ElementAt(1);
                    var normaFinal = _tablaValorServices.setDescripcion(normaEnt, normasSectorEnt);

                    //object[] jsonArray = { norma, normaSector };

                    return(Request.CreateResponse(HttpStatusCode.OK, normaFinal));
                }
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, normaSector));
            }
            return(Request.CreateResponse(HttpStatusCode.InternalServerError, norma));
        }
        public HttpResponseMessage create([FromBody] NormaEntity normaEntity)
        {
            //    if (normaEntity != null)
            //    {
            var create = _normaServices.CreateNorma(normaEntity);

            return(Request.CreateResponse(HttpStatusCode.OK, create));
            //}
            //return 0;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Validate the normaSector asociated with Norma
        /// </summary>
        /// <returns></returns>
        public object[] ValidateSector(NormaEntity normaEntity, IEnumerable <NormaSectorEntity> normaSectorById)
        {
            int match = 0;

            try
            {
                if (normaSectorById != null)
                {
                    foreach (NormaSectorEntity sectorExistente in normaSectorById)
                    {
                        foreach (DataModel.NORMA_SECTOR sectorNuevo in normaEntity.NORMA_SECTOR)
                        {
                            if (sectorNuevo.IdSector.Equals(sectorExistente.IdSector))
                            {
                                match++;
                            }
                        }
                        //Si el sector existente no se encuentra en los seleccionados
                        //valida que dicho sector no tenga relaciones para poderlo borrar
                        if (match == 0)
                        {
                            //Valido relaciones
                            var flagObject = ExistSectorFormato(sectorExistente.IdSector);
                            if (flagObject[0].Equals("0000"))
                            {
                                bool flag = (bool)flagObject.ElementAt(1);
                                if (flag)
                                {
                                    object[] resultado2 = { "0000", false };
                                    return(resultado2);
                                }
                            }
                            else
                            {
                                return(flagObject);
                            }
                        }
                        else
                        {
                            match = 0;
                        }
                    }
                }
                object[] resultado = { "0000", true };
                return(resultado);
            }
            catch (Exception e)
            {
                var      cod         = new CodigoError();
                var      codigoError = cod.Error(e.ToString());
                object[] resultado   = { codigoError, e.ToString() };
                return(resultado);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Edit all the normaSector asociated with IdNorma
        /// </summary>
        /// <returns></returns>

        public NormaEntity EditNormaSector(NormaEntity normaEntity, IEnumerable <NormaSectorEntity> normaSectorById)
        {
            int match = 0;

            //var normaSectorById = GetNormaSectorById(normaEntity.IdNorma);

            if (normaSectorById != null)
            {
                foreach (DataModel.NORMA_SECTOR sectorNuevo in normaEntity.NORMA_SECTOR)
                {
                    foreach (NormaSectorEntity sectorExistente in normaSectorById)
                    {
                        if (sectorNuevo.IdSector.Equals(sectorExistente.IdSector))
                        {
                            ActivateNormaSector(sectorExistente.IdNormaSector);
                        }
                        match++;
                    }

                    if (match == 0)
                    {
                        //ATLA***********************cuando existe en 1 o 0 no se crea, se actualiza
                        CreateNormaSector(sectorNuevo.IdSector, normaEntity.IdNorma);
                    }
                    else
                    {
                        match = 0;
                    }
                }

                foreach (NormaSectorEntity sectorExistente in normaSectorById)
                {
                    foreach (DataModel.NORMA_SECTOR sectorNuevo in normaEntity.NORMA_SECTOR)
                    {
                        if (sectorNuevo.IdSector.Equals(sectorExistente.IdSector))
                        {
                            match++;
                        }
                    }
                    if (match == 0)
                    {
                        InactivateNormaSector(sectorExistente.IdNormaSector);
                    }
                    else
                    {
                        match = 0;
                    }
                }
            }

            normaEntity.NORMA_SECTOR = null;

            return(normaEntity);
        }
Exemplo n.º 6
0
        public void InserirNormaIsInvalid(string codigo,
                                          string descricao,
                                          byte area,
                                          string orgaoLegal)
        {
            DateTime emVigorDesde = DateTime.Now;
            DateTime?emVigorAte   = null;

            var normaEntity = new NormaEntity(codigo,
                                              descricao,
                                              area,
                                              emVigorDesde,
                                              emVigorAte,
                                              orgaoLegal);

            Assert.True(normaEntity.Invalid);
            Assert.True(normaEntity.Notifications.Any());
        }
Exemplo n.º 7
0
        public object[] setDescripcion(NormaEntity norma, List <NormaSectorEntity> normaSector)
        {
            try
            {
                var valor = GetTablaValorById(norma.IdTipoNorma);
                if (valor != null)
                {
                    norma.DescripcionTipoNorma = valor.ValorAlfanumerico;
                }

                var entidad = _entidadServices.GetEntidadById(norma.IdEntidadEmite);
                if (entidad != null)
                {
                    norma.DescripcionEntidadEmite = entidad.Nombre;
                }

                if (normaSector != null)
                {
                    Mapper.Initialize(cfg =>
                    {
                        cfg.CreateMap <NormaSectorEntity, NORMA_SECTOR>();
                    });
                    var sectorModel = Mapper.Map <List <NormaSectorEntity>, List <NORMA_SECTOR> >(normaSector);

                    foreach (NORMA_SECTOR sector in sectorModel)
                    {
                        norma.NORMA_SECTOR.Add(sector);
                    }
                }
                object[] resultado = { "0000", norma };
                return(resultado);
            }
            catch (Exception e)
            {
                var      cod         = new CodigoError();
                var      codigoError = cod.Error(e.ToString());
                object[] resultado   = { codigoError, e.ToString() };
                return(resultado);
            }
        }
Exemplo n.º 8
0
        public async Task <Result <NormaEntity> > Alterar(NormaEntity normaEntity)
        {
            if (normaEntity.Invalid)
            {
                return(Result <NormaEntity> .Error(normaEntity.Notifications));
            }

            var normaModel   = _mapper.Map <NormaEntity, NormaModel>(normaEntity);
            var normaMessage = _mapper.Map <NormaModel, NormaMessage>(normaModel);

            _unitOfWork.BeginTransaction();

            try
            {
                await _normaWriteOnlyRepository.Alterar(normaModel);

                normaMessage.Operacao = (byte)EOperacao.Alterar;

                await _momAdapter.Publicar(normaMessage);

                _unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback();

                _logger.LogError(ex.Message);

                var notifications = new List <Notification>
                {
                    new Notification("Exception", ex.Message)
                };

                return(Result <NormaEntity> .Error(notifications));
            }

            return(Result <NormaEntity> .Ok(normaEntity));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Find when the norma has changed the state
        /// </summary>
        /// <returns></returns>
        public object[] changeNormaState(NormaEntity normaEntity)
        {
            try
            {
                if (normaEntity.IdNorma > 0)
                {
                    //Obtiene Norma almacenada
                    var norma = _unitOfWork.NormaRepository.GetByID(normaEntity.IdNorma);

                    if (norma != null)
                    {
                        //Encuentra si la Norma cambio de estado con respecto a la norma a actualizar
                        if (!(norma.IdEstado == normaEntity.IdEstado))
                        {
                            //Si la Norma a actualizar tiene estado activo, activa todas sus relaciones
                            if (normaEntity.IdEstado == 1)
                            {
                                var flagObject = ActivateNormaRelations(normaEntity.IdNorma);
                                if (flagObject[0].Equals("0000"))
                                {
                                    bool flag = (bool)flagObject.ElementAt(1);
                                    if (flag)
                                    {
                                        //Y activa los sectores nuevos a almacenar
                                        foreach (var item in normaEntity.NORMA_SECTOR)
                                        {
                                            item.IdEstado = 1;
                                        }
                                    }
                                }
                                else
                                {
                                    return(flagObject);
                                }
                            }
                            else
                            {
                                var flagObject = InactivateNormaRelations(normaEntity.IdNorma);
                                if (flagObject[0].Equals("0000"))
                                {
                                    bool flag = (bool)flagObject.ElementAt(1);
                                    if (flag)
                                    {
                                        foreach (var item in normaEntity.NORMA_SECTOR)
                                        {
                                            item.IdEstado = 0;
                                        }
                                    }
                                }
                                else
                                {
                                    return(flagObject);
                                }
                            }
                        }
                    }
                }
                object[] resultado = { "0000", normaEntity };
                return(resultado);
            }
            catch (Exception e)
            {
                var      cod         = new CodigoError();
                var      codigoError = cod.Error(e.ToString());
                object[] resultado   = { codigoError, e.ToString() };
                return(resultado);
            }
        }
        public HttpResponseMessage updateNorma([FromBody] NormaEntity normaEntity)
        {
            if (normaEntity == null)
            {
                object[] resultado = { "0000", false };
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, resultado));
            }

            bool deleteSector = false;

            //Busca las normas sectores relacionadas con la norma
            var normaSectorByIdObject = _normaSectorServices.GetNormaSectorById(normaEntity.IdNorma);

            if (normaSectorByIdObject != null && normaSectorByIdObject[0].Equals("0000"))
            {
                var normaSectorById = (List <NormaSectorEntity>)normaSectorByIdObject.ElementAt(1);

                var flagObject = _normaServices.ValidateSector(normaEntity, normaSectorById);
                if (flagObject[0].Equals("0000"))
                {
                    bool flag = (bool)flagObject.ElementAt(1);
                    //si existe relacion del sector en la tabla formato_servicio no la borra
                    if (flag)
                    {
                        foreach (NormaSectorEntity sector in normaSectorById)
                        {
                            //Si no existe relacion borra los sectores directamente de la tabla NormaSector
                            var deleteSectorObject = _normaSectorServices.DeleteNormaSector(sector.IdNormaSector);
                            if (deleteSectorObject[0].Equals("0000"))
                            {
                                bool flagDelete = (bool)deleteSectorObject.ElementAt(1);
                                if (!flagDelete)
                                {
                                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, false));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.InternalServerError, deleteSectorObject));
                            }
                        }
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, flagObject));
                }

                //Reconoce cuando cambia el estado de la norma
                //y actualiza todas sus relaciones al nuevo estado
                var normaEntityObject = _normaServices.changeNormaState(normaEntity);

                if (normaEntityObject != null && normaEntityObject[0].Equals("0000"))
                {
                    normaEntity = (NormaEntity)normaEntityObject.ElementAt(1);
                    var updateObject = _normaServices.UpdateNorma(normaEntity.IdNorma, normaEntity);

                    return(Request.CreateResponse(HttpStatusCode.OK, updateObject));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, normaEntityObject));
                }
            }
            else
            {
                object[] resultado = { "0000", false };
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, normaSectorByIdObject));
            }
        }