コード例 #1
0
ファイル: IngredienteCAD.cs プロジェクト: Narukage/DSM
        public IngredienteEN ReadOIDDefault(int id
                                            )
        {
            IngredienteEN ingredienteEN = null;

            try
            {
                SessionInitializeTransaction();
                ingredienteEN = (IngredienteEN)session.Get(typeof(IngredienteEN), id);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is PracticaGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new PracticaGenNHibernate.Exceptions.DataLayerException("Error in IngredienteCAD.", ex);
            }


            finally
            {
                SessionClose();
            }

            return(ingredienteEN);
        }
コード例 #2
0
ファイル: IngredienteCAD.cs プロジェクト: Narukage/DSM
// Modify default (Update all attributes of the class)

        public void ModifyDefault(IngredienteEN ingrediente)
        {
            try
            {
                SessionInitializeTransaction();
                IngredienteEN ingredienteEN = (IngredienteEN)session.Load(typeof(IngredienteEN), ingrediente.Id);

                session.Update(ingredienteEN);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is PracticaGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new PracticaGenNHibernate.Exceptions.DataLayerException("Error in IngredienteCAD.", ex);
            }


            finally
            {
                SessionClose();
            }
        }
コード例 #3
0
        public void Destroy(int id)
        {
            try
            {
                SessionInitializeTransaction();
                IngredienteEN ingredienteEN = (IngredienteEN)session.Load(typeof(IngredienteEN), id);
                session.Delete(ingredienteEN);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is EnMiNeveraGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new EnMiNeveraGenNHibernate.Exceptions.DataLayerException("Error in IngredienteCAD.", ex);
            }


            finally
            {
                SessionClose();
            }
        }
コード例 #4
0
ファイル: IngredienteCAD.cs プロジェクト: Narukage/DSM
        public int New_(IngredienteEN ingrediente)
        {
            try
            {
                SessionInitializeTransaction();

                session.Save(ingrediente);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is PracticaGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new PracticaGenNHibernate.Exceptions.DataLayerException("Error in IngredienteCAD.", ex);
            }


            finally
            {
                SessionClose();
            }

            return(ingrediente.Id);
        }
コード例 #5
0
        public ActionResult Add(LineaListaCompra lineaListaCompra, int idListaCompra)
        {
            // TODO comprobar que pertecene a usuario actual

            // Siempre en minusculas
            lineaListaCompra.NombreIngrediente = lineaListaCompra.NombreIngrediente.ToLower();

            IngredienteCEN ingredienteCen = new IngredienteCEN();
            IngredienteEN  ingredienteEn  = ingredienteCen.GetPorNombre(lineaListaCompra.NombreIngrediente);

            int idIngrediente;

            // Buscamos el NombreIngrediente en ingredientes, si no existe creamos
            if (ingredienteEn == null)
            {
                idIngrediente = ingredienteCen.New_(lineaListaCompra.NombreIngrediente);
            }
            else
            {
                idIngrediente = ingredienteEn.Id;
            }

            LineaListaCompraCEN lineaListaCompraCen = new LineaListaCompraCEN();

            lineaListaCompraCen.New_(lineaListaCompra.Cantidad, lineaListaCompra.Unidad, idIngrediente, idListaCompra, false);


            return(RedirectToAction("Index", new { id = idListaCompra }));
        }
コード例 #6
0
ファイル: IngredienteCEN.cs プロジェクト: Narukage/DSM
        public IngredienteEN ReadOID(int id
                                     )
        {
            IngredienteEN ingredienteEN = null;

            ingredienteEN = _IIngredienteCAD.ReadOID(id);
            return(ingredienteEN);
        }
コード例 #7
0
        public void Modify(int p_Ingrediente_OID, string p_nombre)
        {
            IngredienteEN ingredienteEN = null;

            //Initialized IngredienteEN
            ingredienteEN        = new IngredienteEN();
            ingredienteEN.Id     = p_Ingrediente_OID;
            ingredienteEN.Nombre = p_nombre;
            //Call to IngredienteCAD

            _IIngredienteCAD.Modify(ingredienteEN);
        }
コード例 #8
0
        public Ingrediente ConvertENToModelUI(IngredienteEN en)
        {
            Ingrediente model = new Ingrediente();

            model.id     = en.Id;
            model.Nombre = en.Nombre;
            //model.LineasIngrediente = en.LineasIngrediente.ToList();
            //model.LineasListaCompra = en.LineasListaCompra.ToList();


            return(model);
        }
コード例 #9
0
ファイル: ListaCompraCP.cs プロジェクト: ruben2m/EnMiNevera
        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();
            }
        }
コード例 #10
0
        public int New_(string p_nombre)
        {
            IngredienteEN ingredienteEN = null;
            int           oid;

            //Initialized IngredienteEN
            ingredienteEN        = new IngredienteEN();
            ingredienteEN.Nombre = p_nombre;

            //Call to IngredienteCAD

            oid = _IIngredienteCAD.New_(ingredienteEN);
            return(oid);
        }
コード例 #11
0
ファイル: IngredienteCEN.cs プロジェクト: Narukage/DSM
        public void Modify(int p_Ingrediente_OID, double p_precio, string p_nombre, string p_foto, int p_numVeces)
        {
            IngredienteEN ingredienteEN = null;

            //Initialized IngredienteEN
            ingredienteEN          = new IngredienteEN();
            ingredienteEN.Id       = p_Ingrediente_OID;
            ingredienteEN.Precio   = p_precio;
            ingredienteEN.Nombre   = p_nombre;
            ingredienteEN.Foto     = p_foto;
            ingredienteEN.NumVeces = p_numVeces;
            //Call to IngredienteCAD

            _IIngredienteCAD.Modify(ingredienteEN);
        }
コード例 #12
0
        public Ingrediente ConvertENToModelUI(IngredienteEN en, NHibernate.ISession session)
        {
            Ingrediente ing = new Ingrediente();

            ing.Id             = en.Id;
            ing.lineaPedido    = en.LineaPedido;
            ing.personalizable = en.Personalizable;
            double precio = Convert.ToDouble(ing.precio);

            precio       = en.Precio;
            ing.Nombre   = en.Nombre;
            ing.Foto     = en.Foto;
            ing.NumVeces = en.NumVeces;
            return(ing);
        }
コード例 #13
0
        public void CrearLineaIngrediente(int p_oid, int p_cantidad, EnMiNeveraGenNHibernate.Enumerated.EnMiNevera.UnidadesEnum p_unidad, string p_nombre)
        {
            /*PROTECTED REGION ID(EnMiNeveraGenNHibernate.CEN.EnMiNevera_Receta_crearLineaIngrediente) ENABLED START*/

            // Write here your custom code...

            RecetaEN           receta      = _IRecetaCAD.ReadOIDDefault(p_oid);
            LineaIngredienteEN linea       = new LineaIngredienteEN();
            IngredienteEN      ingrediente = new IngredienteEN();

            linea.Cantidad    = p_cantidad;
            linea.Unidad      = p_unidad;
            linea.Ingrediente = ingrediente;


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

            /*PROTECTED REGION END*/
        }
コード例 #14
0
ファイル: IngredienteCEN.cs プロジェクト: Narukage/DSM
        public int New_(double p_precio, string p_nombre, string p_foto, int p_numVeces)
        {
            IngredienteEN ingredienteEN = null;
            int           oid;

            //Initialized IngredienteEN
            ingredienteEN        = new IngredienteEN();
            ingredienteEN.Precio = p_precio;

            ingredienteEN.Nombre = p_nombre;

            ingredienteEN.Foto = p_foto;

            ingredienteEN.NumVeces = p_numVeces;

            //Call to IngredienteCAD

            oid = _IIngredienteCAD.New_(ingredienteEN);
            return(oid);
        }
コード例 #15
0
        public ActionResult BuscaPorIngrediente(string[] ingredientes)
        {
            SessionInitialize();

            // Buscamos ingrediente a ingrediente
            IList <int>    idsIngredientes = new List <int>();
            IngredienteCAD ingredienteCad  = new IngredienteCAD(session);
            IngredienteEN  ingredienteEn   = null;

            foreach (string ing in ingredientes)
            {
                // Solo si existe, añado a la lista. Solo buscamos por ingredientes que existen
                ingredienteEn = ingredienteCad.GetPorNombre(ing.ToLower());
                if (ingredienteEn != null)
                {
                    idsIngredientes.Add(ingredienteEn.Id);
                }
            }

            IList <Receta> list = null;

            if (idsIngredientes.Count() > 0)
            {
                RecetaCAD        cad    = new RecetaCAD(session);
                RecetaCEN        cen    = new RecetaCEN(cad);
                IList <RecetaEN> listEn = cen.BuscarPorIngrediente(idsIngredientes);
                list = new AssemblerReceta().ConvertListENToModel(listEn);
            }
            else
            {
                list = new List <Receta>();
            }


            SessionClose();

            ViewData["ingredientes"] = ingredientes;

            return(View(list));
        }
コード例 #16
0
        //public ActionResult Crear(Receta rec, HttpPostedFileBase file, FormCollection datos)
        public ActionResult Crear(Receta rec, HttpPostedFileBase file, int[] canIngrediente, UnidadesEnum[] uniIngrediente, string[] nomIngrediente, int[] numPaso, string[] desPaso)
        {
            string imagesDir = "Images/Uploads";

            string fileName = "", path = "";

            // Verify that the user selected a file
            if (file != null && file.ContentLength > 0)
            {
                // extract only the fielname
                fileName = Path.GetFileName(file.FileName);
                // store the file inside ~/App_Data/uploads folder
                path = Path.Combine(Server.MapPath("~/" + imagesDir), fileName);
                //string pathDef = path.Replace(@"\\", @"\");
                file.SaveAs(path);
            }

            try
            {
                fileName = "/" + imagesDir + "/" + fileName;

                // Parametros por defecto
                rec.FechaCreacion = DateTime.Now;
                rec.Estado        = EnMiNeveraGenNHibernate.Enumerated.EnMiNevera.EstadosEnum.publicado;
                rec.Foto          = fileName;

                // Obtenemos los pasos
                IList <Paso> pasos = new List <Paso>();
                Paso         paso  = null;
                for (int i = 0; i < numPaso.Count(); i++)
                {
                    paso             = new Paso();
                    paso.NumeroPaso  = numPaso[i];
                    paso.Descripcion = desPaso[i];
                    pasos.Add(paso);
                }

                // Obtenemos las lineas de ingrediente
                IList <LineaIngrediente> lineasIng = new List <LineaIngrediente>();
                LineaIngrediente         lin       = null;
                for (int i = 0; i < canIngrediente.Count(); i++)
                {
                    lin                   = new LineaIngrediente();
                    lin.Cantidad          = canIngrediente[i];
                    lin.NombreIngrediente = nomIngrediente[i];
                    lin.Unidad            = uniIngrediente[i];
                    lineasIng.Add(lin);
                }


                SessionInitialize();
                using (var transaction = session.BeginTransaction())
                {
                    // Obtengo el id del usuario
                    int idUsuario = new UsuarioCAD(session).GetByNick(User.Identity.Name).Id;

                    RecetaCAD cad = new RecetaCAD(session);
                    RecetaCEN cen = new RecetaCEN(cad);

                    int idReceta = cen.New_(rec.Nombre, rec.Descripcion, rec.Foto, idUsuario, rec.FechaCreacion, rec.Estado);

                    // Creamos los pasos
                    PasosCAD pasosCad = new PasosCAD(session);
                    PasosCEN pasosCen = new PasosCEN(pasosCad);
                    foreach (Paso p in pasos)
                    {
                        pasosCen.New_(p.Descripcion, idReceta, p.NumeroPaso);
                    }

                    // Creamos las lineas de ingrediente
                    LineaIngredienteCAD lineaIngredienteCad = new LineaIngredienteCAD(session);
                    LineaIngredienteCEN lineaIngredienteCen = new LineaIngredienteCEN(lineaIngredienteCad);

                    IngredienteCAD ingredienteCad = new IngredienteCAD(session);
                    IngredienteEN  ingredienteEn;

                    foreach (LineaIngrediente l in lineasIng)
                    {
                        // por cada linea, si no existe el ingrediente, lo creamos
                        ingredienteEn = ingredienteCad.GetPorNombre(l.NombreIngrediente);
                        if (ingredienteEn == null)
                        {
                            ingredienteEn        = new IngredienteEN();
                            ingredienteEn.Nombre = l.NombreIngrediente;
                            ingredienteEn.Id     = ingredienteCad.New_(ingredienteEn);
                        }

                        lineaIngredienteCen.New_(l.Cantidad, l.Unidad, ingredienteEn.Id, idReceta);
                    }

                    transaction.Commit();
                }
                SessionClose();



                //RecetaCEN cen = new RecetaCEN();

                //// Obtengo el id del usuario
                //int idUsuario = new UsuarioCAD().GetByNick(User.Identity.Name).Id;

                //rec.FechaCreacion = DateTime.Now;
                //rec.Estado = EnMiNeveraGenNHibernate.Enumerated.EnMiNevera.EstadosEnum.publicado;

                //cen.New_(rec.Nombre, rec.Descripcion, fileName, idUsuario, rec.FechaCreacion, rec.Estado);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }