Пример #1
0
        public ActionResult Check(int id)
        {
            // TODO comprobar que pertecene a usuario actual

            // Utilizando session no funciona
            //SessionInitialize();
            //LineaListaCompraCAD lineaListaCompraCad = new LineaListaCompraCAD(session);
            //LineaListaCompraCEN lineaListaCompraCen = new LineaListaCompraCEN(lineaListaCompraCad);
            //LineaListaCompraEN en = lineaListaCompraCad.ReadOIDDefault(id);
            ////lineaListaCompraCen.Modify(en.Id, en.Cantidad, en.Unidad, !en.Comprado);
            ////lineaListaCompraEn.Comprado = !lineaListaCompraEn.Comprado;
            ////lineaListaCompraCad.Modify(lineaListaCompraEn);
            //SessionClose();

            int idListaCompra = -1;

            LineaListaCompraCAD cad = new LineaListaCompraCAD();
            LineaListaCompraEN en = new LineaListaCompraEN();

            en = cad.ReadOIDDefault(id);
            idListaCompra = en.ListaCompra.Id;  // No da lazyException... Solo se puede acceder al ID para que no dé.

            en.Comprado = !en.Comprado;
            cad.Modify(en);

            return RedirectToAction("Index", new { id = idListaCompra });
        }
Пример #2
0
        public void CrearLineaListaCompra(int p_oid, int p_cantidad, EnMiNeveraGenNHibernate.Enumerated.EnMiNevera.UnidadesEnum p_unidad, string p_ingrediente)
        {
            IngredienteEN ingredienteEN = null;
            LineaListaCompraEN lineaListaCompraEN = null;

            int oid_ingrediente;

            try
            {
                SessionInitializeTransaction();

                IngredienteCAD ingredienteCAD = new IngredienteCAD(session);

                ingredienteEN = ingredienteCAD.GetPorNombre(p_ingrediente.ToLower());

                if (ingredienteEN == null)
                {
                    // Creamos el ingrediente si no existe
                    ingredienteEN = new IngredienteEN();
                    ingredienteEN.Nombre = p_ingrediente.ToLower();
                    oid_ingrediente = ingredienteCAD.New_(ingredienteEN);
                    ingredienteEN = ingredienteCAD.ReadOIDDefault(oid_ingrediente);
                } else
                {
                    oid_ingrediente = ingredienteEN.Id;
                }

                LineaListaCompraCAD lineaListaCompraCAD = new LineaListaCompraCAD(session);
                lineaListaCompraEN = new LineaListaCompraEN();
                lineaListaCompraEN.Ingrediente = ingredienteCAD.ReadOIDDefault(oid_ingrediente);
                lineaListaCompraEN.Cantidad = p_cantidad;
                lineaListaCompraEN.Unidad = p_unidad;
                lineaListaCompraEN.Comprado = false;

                lineaListaCompraEN.Ingrediente.Nombre = p_ingrediente.ToLower();

                lineaListaCompraCAD.New_(lineaListaCompraEN);

                SessionCommit();
            }
            catch (Exception ex)
            {
                SessionRollBack();
                throw ex;
            }
            finally
            {
                SessionClose();
            }
        }
Пример #3
0
        public ActionResult Remove(int id)
        {
            // TODO comprobar que pertecene a usuario actual

            // Obtengo en que lista de la compra estoy
            LineaListaCompraCAD cad = new LineaListaCompraCAD();
            LineaListaCompraEN en = cad.ReadOIDDefault(id);

            int idListaCompra = en.ListaCompra.Id;

            cad.Destroy(id);

            return RedirectToAction("Index", new { id = idListaCompra });
        }