コード例 #1
0
        public VinoDto AddVino(VinoDto vino)
        {
            Vino v = _bodega.Create <Vino>(DtoAVino(vino));

            vino.Id = v.Id;
            return(vino);
        }
コード例 #2
0
        AddVinoReturnCorrectVino()
        {
            //Arrange
            Vino vino = new Vino()
            {
                Nombre       = "Producto 4",
                Variedad     = It.IsAny <string>(),
                Crianza      = It.IsAny <string>(),
                Denominacion = It.IsAny <string>(),
                Color        = It.IsAny <string>(),
                Baja         = false,
                Capacidad    = 0.15m
            };

            VinoDto vinodto = new VinoDto()
            {
                Nombre       = "Producto 4",
                Variedad     = It.IsAny <string>(),
                Crianza      = It.IsAny <string>(),
                Denominacion = It.IsAny <string>(),
                Color        = It.IsAny <string>(),
                Baja         = false,
                Capacidad    = 0.15m
            };

            _bodegaRepository.Setup(x => x.Create(It.IsAny <Vino>())).Returns(vino);

            //Act
            var result = _service.AddVino(vinodto);

            //Assert
            Assert.AreEqual(result.Nombre, "Producto 4");
        }
コード例 #3
0
        public IActionResult Vino(VinoViewModel vino)
        {
            byte[] bytearray = null;
            if (ModelState.IsValid)
            {
                if (vino.Imagen != null)
                {
                    //var uploadFolder = Path.Combine(_host.WebRootPath, "images");
                    //var nombreArchivoIngresado = Path.GetFileName(vino.Imagen.FileName);
                    //var uniqueFileName = Guid.NewGuid().ToString() + "_" + nombreArchivoIngresado;
                    //var filePath = Path.Combine(uploadFolder, uniqueFileName);
                    //vino.Imagen.CopyTo(new FileStream(filePath, FileMode.Create));
                    bytearray = vino.TransformToByteArray();
                }
                var dbVino = new Vino()
                {
                    Nombre      = vino.Nombre,
                    PrecioVenta = vino.PrecioVenta,
                    IdBodega    = vino.IdBodega,
                    Imagen      = bytearray
                };

                _VinotecaData.AddVino(dbVino);
                _VinotecaData.Commit();
            }
            var IdBodegas = _VinotecaData.GetAllIdBodegas();

            ViewData["Ids"] = IdBodegas;
            return(View());
        }
コード例 #4
0
ファイル: VinoController.cs プロジェクト: SupergerAmadej/MVC
        public async Task <IActionResult> Edit(int id, [Bind("Id,Naziv,Alkohol")] Vino vino)
        {
            if (id != vino.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vino);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VinoExists(vino.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vino));
        }
コード例 #5
0
        }// end FormAggiungiVino

        // evento che aggiunge un elemento al db e chiude il form corrente tornando a quello precedente
        private void ButtonAggiungi_Click(object sender, EventArgs e)
        {
            int NrBottiglie;

            // if che fa in modo che il pulsante non faccia nulla finchè l'utente non avrà inserito tutti i dati
            if (this.comboBoxNome.Text != "" &&
                this.comboBoxTipologia.Text != "" &&
                this.comboBoxVigneto.Text != "" &&
                this.comboBoxBottiglie.Text != "" &&
                int.TryParse(this.comboBoxBottiglie.Text, out NrBottiglie))
            {
                // creazione di un oggetto di tipo vino e deefinizione di tutti i suoi attributi in modo da passare alla
                // query solo un oggetto e non tante stringhe che dovranno pure essere in ordine corretto
                Vino vino = new Vino();
                vino.SetNome(this.comboBoxNome.Text);
                vino.SetAnno(decimal.ToInt16(this.numericUpDown1.Value));
                vino.SetTipologia(this.comboBoxTipologia.Text);
                vino.SetVigneto(this.comboBoxVigneto.Text);
                vino.SetNrbottiglie(NrBottiglie);

                DbVino v = new DbVino();
                v.AddItem(vino);

                // chiusura del form attuale a apertura del form precedente
                this.formvino.Dispose();
                FormVino frm = new FormVino(this.home);
                frm.Show();
                this.Dispose();
            } // end if
        }     //end "ButtonAggiungiClick
コード例 #6
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            ETipoVino tipo   = (ETipoVino)this.cboTipoVino.SelectedItem;
            EBodega   bodega = (EBodega)this.cboBodega.SelectedItem;

            this.miVino = new Vino(tipo, bodega);

            this.DialogResult = DialogResult.OK;
        }
コード例 #7
0
        public int DeleteVino(int id)
        {
            //es un borrado lógico
            Vino vino = _bodega.Find <Vino>(x => x.Id == id);

            vino.Baja = true;
            vino      = _bodega.Update <Vino>(id, vino);
            return((vino.Baja) ? 1 : 0);
        }
コード例 #8
0
        // definizione del metodo che permette di aggiungere un elemento alla tabella 'vini' del database
        public void AddItem(object ob)
        {
            Vino v = (Vino)ob;

            // query per inserire i dati
            string str = "INSERT INTO vini VALUES (NULL,'" + v.GetNome() + "'," + v.GetAnno() + ",'" + v.GetTipologia() + "','" + v.GetVigneto() + "'," + v.GetNrbottiglie() + ");";

            // passo la stringa al metodo che mi effettuerà la query al db
            q.Query(str);
        }// end metodo AddItem
コード例 #9
0
ファイル: VinoController.cs プロジェクト: SupergerAmadej/MVC
        public async Task <IActionResult> Create([Bind("Id,Naziv,Alkohol")] Vino vino)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vino);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vino));
        }
コード例 #10
0
        public void AgregarVinos_Exception()
        {
            //Arrange
            Vinoteca v  = new Vinoteca(1);
            Vino     v1 = new Vino(ETipoVino.Merlot, EBodega.Zuccardi);
            Vino     v2 = new Vino(ETipoVino.Merlot, EBodega.Rippon);

            //Act
            v += v1;
            v += v2;
        }
コード例 #11
0
        public Vino UpdateVino(Vino updatedVino)
        {
            var vino = GetVinoById(updatedVino.Id);

            if (vino != null)
            {
                vino = updatedVino;
                return(vino);
            }
            return(vino);
        }
コード例 #12
0
        static void Main(string[] args)
        {
            Vino v1 = new Vino(ETipoVino.Malbec, EBodega.Zuccardi);
            Vino v2 = new Vino(ETipoVino.Malbec, EBodega.Garzón);
            Vino v3 = new Vino(ETipoVino.Merlot, EBodega.Marquéz_de_Riscal);
            Vino v4 = new Vino(ETipoVino.Malbec, EBodega.Zuccardi);

            if (v1 == v2)
            {
                Console.WriteLine("El vino {0} es igual al vino {1}", v1.Mostrar(), v2.Mostrar());
            }

            if (v1 != v2)
            {
                Console.WriteLine("El vino {0} es distinto al vino {1}", v1.Mostrar(), v2.Mostrar());
            }

            if (v1 == v4)
            {
                Console.WriteLine("El vino {0} es igual al vino {1}", v1.Mostrar(), v4.Mostrar());
            }

            if (v2 != v3)
            {
                Console.WriteLine("El vino {0} es distinto al vino {1}", v2.Mostrar(), v3.Mostrar());
            }

            //comparo contra null
            if (v1 != null)
            {
                Console.WriteLine("El vino {0} es distinto a null", v1.Mostrar());
            }

            if (null != v2)
            {
                Console.WriteLine("El valor null es distinto al vino {0}", v2.Mostrar());
            }

            Vinoteca vinoteca = new Vinoteca(3);

            vinoteca += v1;

            //verifico el buen funcionamiento del Mostrar.
            Console.WriteLine(vinoteca.Mostrar());

            vinoteca += v2;
            vinoteca += v3;
            vinoteca += v4;

            Console.WriteLine(vinoteca.Mostrar());

            Console.ReadLine();
        }
コード例 #13
0
        public void VerificarIgualdadVinos_Falla()
        {
            //Arrange
            Vino v1 = new Vino(ETipoVino.Merlot, EBodega.Zuccardi);
            Vino v2 = new Vino(ETipoVino.Merlot, EBodega.Rippon);

            //Act
            bool rta = v1 == v2;

            //Assert
            Assert.IsFalse(rta);
        }
コード例 #14
0
        public void VerificarIgualdadVinosNulos()
        {
            //Arrange
            Vino v1 = null;
            Vino v2 = null;

            //Act
            bool rta = v1 == v2;

            //Assert
            Assert.IsTrue(rta);
        }
コード例 #15
0
 private VinoDto VinoADto(Vino v)
 {
     if (v == null)
     {
         return(null);
     }
     return(new VinoDto()
     {
         Id = v.Id,
         Nombre = v.Nombre,
         Denominacion = v.Denominacion,
         Capacidad = v.Capacidad,
         Color = v.Color,
         Crianza = v.Crianza,
         Variedad = v.Variedad,
         Baja = v.Baja
     });
 }
コード例 #16
0
        public void AgregarVinos_Ok()
        {
            //Arrange
            Vinoteca v  = new Vinoteca(3);
            Vino     v1 = new Vino(ETipoVino.Merlot, EBodega.Zuccardi);
            Vino     v2 = new Vino(ETipoVino.Merlot, EBodega.Rippon);
            int      espacioLibreEsperado = 1;
            int      espacioLibre         = 0;

            //Act
            v += v1;
            v += v2;

            espacioLibre = v.EspacioLibre;

            //Assert
            Assert.AreEqual(espacioLibre, espacioLibreEsperado);
        }
コード例 #17
0
        public void AgregarVinos_Falla()
        {
            //Arrange
            Vinoteca v  = new Vinoteca(1);
            Vino     v1 = new Vino(ETipoVino.Merlot, EBodega.Zuccardi);
            Vino     v2 = new Vino(ETipoVino.Merlot, EBodega.Rippon);

            //Act
            try
            {
                v += v1;
                v += v2;
            }
            catch (Exception e)
            {
                //Assert
                Assert.IsInstanceOfType(e, typeof(VinotecaLlenaException));
            }
        }
コード例 #18
0
        DeleteVinoReturn1()
        {
            //Arrange
            Vino vino = new Vino()
            {
                Id           = 4,
                Nombre       = "Producto 4",
                Variedad     = It.IsAny <string>(),
                Crianza      = It.IsAny <string>(),
                Denominacion = It.IsAny <string>(),
                Color        = It.IsAny <string>(),
                Baja         = true,
                Capacidad    = It.IsAny <decimal>()
            };

            _bodegaRepository.Setup(x => x.Find <Vino>(It.IsAny <Expression <Func <Vino, bool> > >())).Returns(vino);
            _bodegaRepository.Setup(x => x.Update <Vino>(It.IsAny <int>(), It.IsAny <Vino>())).Returns(vino);
            //Act
            var result = _service.DeleteVino(4);

            //Assert
            Assert.AreEqual(result, 1);
        }
コード例 #19
0
        public void GetVinoNombreReturnCorrectVino()
        {
            //Arrange
            Vino vino = new Vino()
            {
                Id           = 4,
                Nombre       = "Producto 4",
                Variedad     = It.IsAny <string>(),
                Crianza      = It.IsAny <string>(),
                Denominacion = It.IsAny <string>(),
                Color        = It.IsAny <string>(),
                Baja         = true,
                Capacidad    = It.IsAny <decimal>()
            };

            _bodegaRepository.Setup(x => x.Find <Vino>(It.IsAny <Expression <Func <Vino, bool> > >())).Returns(vino);

            //Act
            var result = _service.GetVino("Producto 4");

            //Assert
            Assert.AreEqual(result.Id, 4);
            Assert.AreNotEqual(result.Id, 5);
        }
コード例 #20
0
        static void Main(string[] args)
        {
            #region EXCEPTION
            try
            {
                var ObjCantidad = new ClassException();
                var cantidad    = ObjCantidad.GetCantidad("NombreCerveza");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.WriteLine("Finally, siempre ejecuta cierra Recursos");
            }
            #endregion

            #region LINQ BASICO Consultas
            //Consulta datos
            List <int> numbers = new List <int> {
                1, 5, 3, 4, 2, 6, 7, 0, 9, 8
            };
            var num2 = numbers.Where(d => d == 7).FirstOrDefault();
            //Console.WriteLine("Consulta " + num2);

            //Ordena datos
            var NumOrden = numbers.OrderBy(d => d);
            for (int i = 0; i < numbers.Max(); i++)
            {
                //Console.WriteLine(i);
            }

            //Suma Datos
            var NumSuma = numbers.Sum(d => d);
            //Console.WriteLine("Suma: " + NumSuma);

            //Suma Promedio
            var NumProm = numbers.Average(d => d);
            //Console.WriteLine("Suma: " + NumProm);

            //Manejo Listas de Objetos
            List <Cervezas> Objcervezas = new List <Cervezas>()
            {
                new Cervezas()
                {
                    Alcohol = 10, Cantidad = 100, Marca = "Club", Nombre = "Negra"
                },
                new Cervezas()
                {
                    Alcohol = 20, Cantidad = 200, Marca = "Poker", Nombre = "October"
                },
                new Cervezas()
                {
                    Alcohol = 30, Cantidad = 300, Marca = "Heineken", Nombre = "Michelada"
                },
                new Cervezas()
                {
                    Alcohol = 40, Cantidad = 400, Marca = "Corona", Nombre = "White"
                }
            };

            var OrdCervezas = from d in Objcervezas
                              orderby d.Marca
                              select d;
            foreach (var a in OrdCervezas)
            {
                //  Console.WriteLine($"{a.Marca} {a.Nombre}");
            }
            #endregion

            #region LINQ COMPLEJO Subconsultas

            List <Bares> bar = new List <Bares>()
            {
                new Bares("RockBar")
                {
                    BarCerveza = new List <Cervezas>()
                    {
                        new Cervezas()
                        {
                            Alcohol = 10, Cantidad = 100, Marca = "Club", Nombre = "Negra"
                        },
                        new Cervezas()
                        {
                            Alcohol = 20, Cantidad = 200, Marca = "Poker", Nombre = "October"
                        },
                        new Cervezas()
                        {
                            Alcohol = 30, Cantidad = 300, Marca = "Heineken", Nombre = "Michelada"
                        }
                    }
                },
                new Bares("Rockheavy")
                {
                    BarCerveza = new List <Cervezas>()
                    {
                        new Cervezas()
                        {
                            Alcohol = 40, Cantidad = 400, Marca = "Corona", Nombre = "White"
                        },
                        new Cervezas()
                        {
                            Alcohol = 20, Cantidad = 200, Marca = "Poker", Nombre = "October"
                        },
                        new Cervezas()
                        {
                            Alcohol = 30, Cantidad = 300, Marca = "Heineken", Nombre = "Michelada"
                        }
                    }
                },
                new Bares("RockSoft")
            };

            var Bar = (from d in bar
                       where d.BarCerveza.Where(a => a.Nombre == "October").Count() > 0
                       select d).ToList();


            var DataBar = (from d in bar
                           where d.BarCerveza.Where(a => a.Nombre == "October").Count() > 0
                           select new BaresData(d.Nombre)
            {
                bebidas = (from b in d.BarCerveza
                           select new Bebidas(b.Nombre, b.Cantidad)
                           ).ToList()
            }).ToList();


            #endregion

            #region SERIALIZACION Objetos DESERIALIZACION Json
            {
                //Serializa objeto a Json
                Cervezas cervezas = new Cervezas(2000, "SerializaJson");
                cervezas.Marca   = "Objeto a Json";
                cervezas.Alcohol = 10;
                string MiJsonSerialize = JsonSerializer.Serialize(cervezas);

                // Crea un archivo con el objeto en formato Json en la ruta FundamentosCSharp\bin\Debug\netcoreapp2.1
                //File.WriteAllText("NombreArchivo.txt", MiJsonSerialize);
            }

            {
                //Deserializa Json a Objeto
                string   MiJsonDeserialize = File.ReadAllText("NombreArchivo.txt");
                Cervezas cervezas          = JsonSerializer.Deserialize <Cervezas>(MiJsonDeserialize);
            }
            #endregion

            #region CRUD SQLConnection
            DBCerveza db = new DBCerveza();

            #region METODO POST
            {
                Cervezas cervezas = new Cervezas(25, "Cerveza POST");
                cervezas.Marca   = "Cerveza Objeto cerveza";
                cervezas.Alcohol = 35;
                //db.Add(cervezas);
            }
            #endregion

            #region METODO PUT
            {
                Cervezas cervezas = new Cervezas(250, "Cerveza Edit");
                cervezas.Marca   = "Cerveza Put";
                cervezas.Alcohol = 25;
                //db.Edit(cervezas, 4);
            }
            #endregion

            #region METODO DELETE
            {
                //db.Delete(4);
            }
            #endregion

            #region METODO GET
            var Cervezas = db.Get();

            foreach (var result in Cervezas)
            {
                //Console.WriteLine(result.Nombre + " " + result.Marca + " " + result.Cantidad + " " + result.Alcohol);
            }
            #endregion

            #endregion

            #region TIPOS DE DATOS

            byte     bnumero  = 255;          //Va desde 0 a 255 no permite negativos  1 byte
            sbyte    snumero  = 127;          //Va desde -128 a 127 si permite negativos
            int      inumero  = -10;          //Permite numeros positivos y negativos 4 bytes
            uint     unumero  = 1;            //No permite numeros negativos
            long     lnumero  = 100;          //Permite numeros positivos y negativos muy largos 8 bytes
            ulong    ulnumero = 100;          //No permite numeros negativos muy largos
            float    fnumero  = 13.8f;        //4 bytes
            double   dnumero  = 13.8d;        //8 bytes
            decimal  denumero = 13.8m;        //16 bytes
            char     cletra   = 'A';          //una letra 2 byte
            string   sletra   = "Cadena";     //cadena de caracteres
            DateTime date     = DateTime.Now; //Tipos de fecha
            bool     SioNO    = true;         //Tipo Booleano
            var      persona  = "Ronald";     //Tipo var Toma el valor que se define a la derecha

            //Por defecto tiene un cero
            int numero = new int();
            //Console.WriteLine(numero.ToString());

            //Agregar el ? para hacerlo null
            int?NumeroVacio = null;
            //Console.WriteLine(numero.ToString());

            //Tipo Objeto
            object Animales =
                new { Nombre = "Animal", Tipo = "Salvaje" };

            //Console.WriteLine(Animales);

            //Tipo Objeto Atributo
            var AnimalesAtributos =
                new { Nombre = "Animal", Tipo = "Salvaje" };

            //Console.WriteLine(AnimalesAtributos.Nombre);
            #endregion

            #region OBJETOS CLASES Y CONSTRUCTORES

            //Objeto sin Constructor eliminar el Constructor en la clase
            //Bebidas ObjBebida = new Bebidas();
            //ObjBebida.Nombre = "Agua";
            //ObjBebida.Cantidad = 5000;


            //Objeto con Constructor
            Bebidas ObjConstBebida = new Bebidas("Agua", 5000);
            ObjConstBebida.Beber(1000);
            //Console.WriteLine(ObjConstBebida.Cantidad);


            Cervezas ObjCerveza = new Cervezas(3000);
            ObjCerveza.Beber(200);
            #endregion

            #region ARREGLOS
            int[] Anumeros = new int[10] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 0
            };
            int array = Anumeros[0];

            for (int i = 0; i < Anumeros.Length; i++)
            {
                //Console.WriteLine("Iteracion: " + i + "Valor: " + Anumeros[i]);
            }

            foreach (var num in Anumeros)
            {
                //Console.WriteLine(num);
            }
            #endregion

            #region LISTAS
            List <int> lst = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8
            };
            lst.Add(9);
            lst.Add(0);
            lst.Remove(1);

            foreach (var num in lst)
            {
                // Console.WriteLine(num);
            }


            List <Cervezas> ObjCervezas = new List <Cervezas>()
            {
                new Cervezas(200, "Corona")
            };
            ObjCervezas.Add(new Cervezas(100, "Poker"));
            Cervezas ClubColombia = new Cervezas(1000, "Club Trigo");
            ObjCervezas.Add(ClubColombia);

            foreach (var cerveza in ObjCervezas)
            {
                //Console.WriteLine(cerveza.Nombre);
            }
            #endregion

            #region INTERFACES
            //Contrato que deben cumplir las clases que impementen la inteface
            //Organizar codigo, resolver multiple herencia, Base de los patrones de diseño
            var bebidaAlcoholica = new Vino(100);
            MostrarInterface(bebidaAlcoholica);
            #endregion
        }
コード例 #21
0
 public Vino AddVino(Vino newVino)
 {
     _ctx.Add(newVino);
     return(newVino);
 }
コード例 #22
0
        public VinoDto GetVino(int Id)
        {
            Vino vino = _bodega.Find <Vino>(x => x.Id == Id);

            return(VinoADto(vino));
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: JAvila30/PracticaC-
        static void Main(string[] args)

        {
            //Clases
            bebida bebida = new bebida("Coca cola", 1000);

            bebida.Beberse(500);
            Console.WriteLine("Ustede bebió " + bebida.Cantidad + " de bebida");

            //Herencia
            Cerveza cerveza = new Cerveza(700);

            cerveza.Beberse(10);
            Console.WriteLine("Ustede bebió " + cerveza.Cantidad + " de cerveza");

            //Arreglos
            int[] numeros = new int[10] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };

            int numerop = numeros[0];

            //Recorrer un arreglo con for
            for (int i = 0; i < numeros.Length; i++)
            {
                Console.WriteLine("Recorrido FOR... Iteración: " + i + " número: " + numeros[i]);
            }

            //Recorrido con FOREACH
            foreach (var numero in numeros)
            {
                Console.WriteLine("Recorrido FOREACH... Iteración: " + numero);
            }

            Console.WriteLine("--------------------------------------------------------");

            //Listas
            List <int> lista = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8
            };

            //Añadir en lista
            lista.Add(9);
            lista.Add(10);

            //Eliminar en lista
            lista.Remove(2);

            foreach (var numero in lista)
            {
                Console.WriteLine("Elemento reccorid de una lista: " + numero);
            }

            Console.WriteLine("*********************************************************");

            //Lista creada utlizando parametros de clase
            List <Cerveza> cervezas = new List <Cerveza>()
            {
                new Cerveza(10, "Cerveza premiun")
            };

            //Agregado
            cervezas.Add(new Cerveza(500));

            //Crear objeto para entrar en lista
            Cerveza erdinger = new Cerveza(500, "Cerveza de trigo");

            //Se añade a la lista
            cervezas.Add(erdinger);

            //Recorrido de la lista de la clase
            foreach (var cerverza in cervezas)
            {
                Console.WriteLine("Cerveza: " + cerverza.Nombre);
            }

            Console.WriteLine("***************************************************");
            //Interfaces
            var bebidaAlcoholica = new Vino(100);

            MostrarRecomendaciones(bebidaAlcoholica);
        }
コード例 #24
0
        public VinoDto GetVino(string nombre)
        {
            Vino v = _bodega.Find <Vino>(x => x.Nombre == nombre);

            return(VinoADto(v));
        }