Ejemplo n.º 1
0
        public List <EdificioDTO> getListarEdificio_X_Sede(int cod_sede)
        {
            List <EdificioDTO> ListaEdificioDTO = new List <EdificioDTO>();
            //ListaUsuarioEmpresaDTO = null;
            string        cnxString = _appDBContext.Database.GetConnectionString();
            SqlConnection cnx       = new SqlConnection(cnxString);

            try
            {
                cnx.Open();
                using (SqlCommand Sqlcmd = new SqlCommand())
                {
                    Sqlcmd.Connection  = cnx;
                    Sqlcmd.CommandType = CommandType.StoredProcedure;
                    Sqlcmd.CommandText = "SP_S_Listar_Edificio_X_Sede_21";
                    Sqlcmd.Parameters.Clear();
                    Sqlcmd.Parameters.Add("@Cod_Sede", SqlDbType.Int).Value = cod_sede;
                    SqlDataReader oDataReader = Sqlcmd.ExecuteReader();
                    while (oDataReader.Read())
                    {
                        EdificioDTO EdificioDTO = new EdificioDTO();
                        EdificioDTO.cod_edificio  = int.Parse(oDataReader["cod_edificio"].ToString());
                        EdificioDTO.cod_sede      = int.Parse(oDataReader["cod_sede"].ToString());
                        EdificioDTO.des_sede      = oDataReader["des_sede"].ToString();
                        EdificioDTO.des_edificio  = oDataReader["des_edificio"].ToString();
                        EdificioDTO.des_direccion = oDataReader["des_direccion"].ToString();
                        EdificioDTO.activo        = bool.Parse(oDataReader["flag_activo"].ToString());
                        ListaEdificioDTO.Add(EdificioDTO);
                    }
                }
            }
            catch (SqlException sex)
            {
                eErrorLog mensajeLogError = new eErrorLog(
                    sex.Message, "EdificioRepository/getListarEdificio_X_Sede(). SQL." + sex, "Error Sql");
                mensajeLogError.RegisterLog();
            }
            catch (Exception ex)
            {
                eErrorLog mensajeLogError = new eErrorLog(ex.Message, "EdificioRepository/getListarEdificio_X_Sede() EX." + ex, "Error");
                mensajeLogError.RegisterLog();
            }
            finally
            {
                if (cnx.State == System.Data.ConnectionState.Open)
                {
                    cnx.Close();
                }
            }


            return(ListaEdificioDTO);
        }
Ejemplo n.º 2
0
        public static EdificioEN Convert(EdificioDTO dto)
        {
            EdificioEN newinstance = null;

            try
            {
                if (dto != null)
                {
                    newinstance = new EdificioEN();



                    newinstance.Nombre = dto.Nombre;
                    newinstance.Id     = dto.Id;
                    if (dto.Estancias_oid != null)
                    {
                        ReciclaUAGenNHibernate.CAD.ReciclaUA.IEstanciaCAD estanciaCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.EstanciaCAD();

                        newinstance.Estancias = new System.Collections.Generic.List <ReciclaUAGenNHibernate.EN.ReciclaUA.EstanciaEN>();
                        foreach (string entry in dto.Estancias_oid)
                        {
                            newinstance.Estancias.Add(estanciaCAD.ReadOIDDefault(entry));
                        }
                    }
                    if (dto.Plantas_oid != null)
                    {
                        ReciclaUAGenNHibernate.CAD.ReciclaUA.IPlantaCAD plantaCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.PlantaCAD();

                        newinstance.Plantas = new System.Collections.Generic.List <ReciclaUAGenNHibernate.EN.ReciclaUA.PlantaEN>();
                        foreach (int entry in dto.Plantas_oid)
                        {
                            newinstance.Plantas.Add(plantaCAD.ReadOIDDefault(entry));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
Ejemplo n.º 3
0
        public HttpResponseMessage Modificar(int idEdificio, [FromBody] EdificioDTO dto)
        {
            // CAD, CEN, returnValue
            EdificioRESTCAD edificioRESTCAD = null;
            EdificioCEN     edificioCEN     = null;
            EdificioDTOA    returnValue     = null;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();
                string token = "";
                if (Request.Headers.Authorization != null)
                {
                    token = Request.Headers.Authorization.ToString();
                }
                int id = new UsuarioCEN().CheckToken(token);



                edificioRESTCAD = new EdificioRESTCAD(session);
                edificioCEN     = new EdificioCEN(edificioRESTCAD);

                // Modify
                edificioCEN.Modificar(idEdificio,
                                      dto.Nombre
                                      );

                // Return modified object
                returnValue = EdificioAssembler.Convert(edificioRESTCAD.ReadOIDDefault(idEdificio), session);

                SessionCommit();
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 404 - Not found
            if (returnValue == null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
            // Return 200 - OK
            else
            {
                response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue);

                return(response);
            }
        }
Ejemplo n.º 4
0
        public HttpResponseMessage Crear([FromBody] EdificioDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            EdificioRESTCAD edificioRESTCAD = null;
            EdificioCEN     edificioCEN     = null;
            EdificioDTOA    returnValue     = null;
            int             returnOID       = -1;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();
                string token = "";
                if (Request.Headers.Authorization != null)
                {
                    token = Request.Headers.Authorization.ToString();
                }
                int id = new UsuarioCEN().CheckToken(token);



                edificioRESTCAD = new EdificioRESTCAD(session);
                edificioCEN     = new EdificioCEN(edificioRESTCAD);

                // Create
                returnOID = edificioCEN.Crear(
                    //Atributo Primitivo: p_nombre
                    dto.Nombre,                                                                                                                                             //Atributo Primitivo: p_id
                    dto.Id);
                SessionCommit();

                // Convert return
                returnValue = EdificioAssembler.Convert(edificioRESTCAD.ReadOIDDefault(returnOID), session);
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 201 - Created
            response = this.Request.CreateResponse(HttpStatusCode.Created, returnValue);

            // Location Header

            /*
             * Dictionary<string, object> routeValues = new Dictionary<string, object>();
             *
             * // TODO: y rolPaths
             * routeValues.Add("id", returnOID);
             *
             * uri = Url.Link("GetOIDEdificio", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }