Esempio n. 1
0
        public void ValidarItem(int p_oid, int p_puntuacion)
        {
            /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CEN.ReciclaUA_Item_validarItem) ENABLED START*/
            ItemCAD cad  = new ItemCAD();
            ItemEN  item = cad.BuscarPorId(p_oid);



            if (item.EsValido != Enumerated.ReciclaUA.EstadoEnum.enProceso)
            {
                throw new ModelException("No se puede validar un item que no est? en proceso de validaci?n");
            }

            item.EsValido   = Enumerated.ReciclaUA.EstadoEnum.verificado;
            item.Puntuacion = p_puntuacion;

            cad.Modificar(item);

            ItemCP cp = new ItemCP();

            cp.CrearAccionItem(p_oid);

            //throw new NotImplementedException ("Method ValidarItem() not yet implemented.");

            /*PROTECTED REGION END*/
        }
Esempio n. 2
0
        public static ItemDTOA Convert(ItemEN en, NHibernate.ISession session = null)
        {
            ItemDTOA    dto         = null;
            ItemRESTCAD itemRESTCAD = null;
            ItemCEN     itemCEN     = null;
            ItemCP      itemCP      = null;

            if (en != null)
            {
                dto         = new ItemDTOA();
                itemRESTCAD = new ItemRESTCAD(session);
                itemCEN     = new ItemCEN(itemRESTCAD);
                itemCP      = new ItemCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Nombre = en.Nombre;


                dto.Descripcion = en.Descripcion;


                dto.Imagen = en.Imagen;


                dto.EsValido = en.EsValido;


                dto.Puntuacion = en.Puntuacion;


                //
                // TravesalLink

                /* Rol: Item o--> Material */
                dto.MaterialItem = MaterialAssembler.Convert((MaterialEN)en.Material, session);


                //
                // Service
            }

            return(dto);
        }
        public HttpResponseMessage CrearCP([FromBody] ItemDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            ItemRESTCAD itemRESTCAD = null;
            ItemCEN     itemCEN     = null;
            ItemDTOA    returnValue = null;
            ItemCP      itemCP      = null;
            int         returnOID   = -1;

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

            try
            {
                SessionInitializeTransaction();


                itemRESTCAD = new ItemRESTCAD(session);
                itemCEN     = new ItemCEN(itemRESTCAD);
                itemCP      = new ItemCP(session);

                // Create
                returnOID = itemCEN.Crear(dto.Nombre, dto.Descripcion, dto.Imagen, dto.Usuario_oid, dto.Material_oid);
                itemCP.CrearAccionItem(returnOID);

                SessionCommit();

                // Convert return
                returnValue = ItemAssembler.Convert(itemRESTCAD.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);
        }