예제 #1
0
        public HttpResponseMessage BuscarPorTipoContenedor(ReciclaUAGenNHibernate.Enumerated.ReciclaUA.TipoContenedorEnum?tipo_contenedor)
        {
            // CAD, CEN, EN, returnValue

            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;


            System.Collections.Generic.List <MaterialEN> en;

            System.Collections.Generic.List <MaterialDTOA> returnValue = null;

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



                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);

                // CEN return



                en = materialCEN.BuscarPorTipoContenedor(tipo_contenedor).ToList();



                // Convert return
                if (en != null)
                {
                    returnValue = new System.Collections.Generic.List <MaterialDTOA>();
                    foreach (MaterialEN entry in en)
                    {
                        returnValue.Add(MaterialAssembler.Convert(entry, session));
                    }
                }
            }

            catch (Exception e)
            {
                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 204 - Empty
            if (returnValue == null || returnValue.Count == 0)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NoContent));
            }
            // Return 200 - OK
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue));
            }
        }
 public void WhenBuscoEsosMaterialPorSuTipoContenedor()
 {
     materiales = materialCEN.BuscarPorTipoContenedor(TipoContenedorEnum.papel);
 }