コード例 #1
0
 public void ThenSeBorraElContenedor()
 {
     contenedor = contenedorCEN.BuscarPorId(id_contenedor);
     Assert.IsNull(contenedor);
 }
コード例 #2
0
        public HttpResponseMessage BuscarPorId(int idContenedor)
        {
            // CAD, CEN, EN, returnValue
            ContenedorRESTCAD contenedorRESTCAD = null;
            ContenedorCEN     contenedorCEN     = null;
            ContenedorEN      contenedorEN      = null;
            ContenedorDTOA    returnValue       = null;

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



                contenedorRESTCAD = new ContenedorRESTCAD(session);
                contenedorCEN     = new ContenedorCEN(contenedorRESTCAD);

                // Data
                contenedorEN = contenedorCEN.BuscarPorId(idContenedor);

                // Convert return
                if (contenedorEN != null)
                {
                    returnValue = ContenedorAssembler.Convert(contenedorEN, 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 404 - Not found
            if (returnValue == null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
            // Return 200 - OK
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue));
            }
        }