示例#1
0
        public static void InitializeData()
        {
            contenedorId = contenedorCEN.Crear(ReciclaUAGenNHibernate.Enumerated.ReciclaUA.TipoContenedorEnum.cristal, -1);
            itemId       = -1;
            user         = -1;

            accionReciclarId = accionReciclarCEN.Crear(user, contenedorId, itemId, cantidad);
        }
        public HttpResponseMessage CrearCP([FromBody] AccionReciclarDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            AccionReciclarRESTCAD accionReciclarRESTCAD = null;
            AccionReciclarCEN     accionReciclarCEN     = null;
            AccionReciclarDTOA    returnValue           = null;
            AccionReciclarCP      cp = null;
            int returnOID            = -1;

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

            try
            {
                SessionInitializeTransaction();

                accionReciclarRESTCAD = new AccionReciclarRESTCAD(session);
                accionReciclarCEN     = new AccionReciclarCEN(accionReciclarRESTCAD);
                cp = new AccionReciclarCP(session);

                // Create
                returnOID = accionReciclarCEN.Crear(dto.Usuario_oid, dto.Contenedor_oid, dto.Item_oid, dto.Cantidad);
                cp.CrearAccion(returnOID);

                SessionCommit();

                // Convert return
                returnValue = AccionReciclarAssembler.Convert(accionReciclarRESTCAD.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);

            return(response);
        }
        public HttpResponseMessage Crear([FromBody] AccionReciclarDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            AccionReciclarRESTCAD accionReciclarRESTCAD = null;
            AccionReciclarCEN     accionReciclarCEN     = null;
            AccionReciclarDTOA    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);



                accionReciclarRESTCAD = new AccionReciclarRESTCAD(session);
                accionReciclarCEN     = new AccionReciclarCEN(accionReciclarRESTCAD);

                // Create
                returnOID = accionReciclarCEN.Crear(
                    //Atributo OID: p_usuario
                    // attr.estaRelacionado: true
                    dto.Usuario_oid                  // association role

                    ,                                //Atributo OID: p_contenedor
                    // attr.estaRelacionado: true
                    dto.Contenedor_oid               // association role

                    ,                                //Atributo OID: p_item
                    // attr.estaRelacionado: true
                    dto.Item_oid                     // association role

                    ,                                //Atributo Primitivo: p_cantidad
                    dto.Cantidad);
                SessionCommit();

                // Convert return
                returnValue = AccionReciclarAssembler.Convert(accionReciclarRESTCAD.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("GetOIDAccionReciclar", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
 public void WhenCreoLaAccionDeReciclaje()
 {
     accionReciclarId = accionReciclarCEN.Crear(user, contenedorId, itemId, cantidad);
 }