private Cesta GetCesta(HttpContextBase httpContext, bool crearIfNull) { HttpCookie cookie = httpContext.Request.Cookies.Get(NombreCesta); Cesta cesta = new Cesta(); if (cookie != null) { string IdCesta = cookie.Value; if (!string.IsNullOrEmpty(IdCesta)) { cesta = cestaContext.Buscar(IdCesta); } else { if (crearIfNull) { cesta = CrearNuevaCesta(httpContext); } } } else { if (crearIfNull) { cesta = CrearNuevaCesta(httpContext); } } return(cesta); }
public IActionResult Cesta(int id) { List <Cesta> listacesta = session.GetObject <List <Cesta> >("CESTA"); List <Cesta> cestita = new List <Cesta>(); Cesta cestanueva; Cesta cestaantes; Pelicula peli = this.repository.FindPeliculaById(id); cestanueva = new Cesta(); cestanueva.IdPelicula = peli.Id; cestanueva.Precio = peli.Precio; cestita.Add(cestanueva); if (listacesta != null) { foreach (Cesta c in listacesta) { cestaantes = new Cesta(); cestaantes.Precio = c.Precio; cestaantes.IdPelicula = c.IdPelicula; if (c.IdPelicula != cestanueva.IdPelicula) { cestita.Add(cestaantes); } } } session.SetObject("CESTA", cestita); return(RedirectToAction("detalles", peli)); }
public void AgregarACesta(HttpContextBase httpContext, string productoId) { Cesta cesta = new Cesta(); cesta = GetCesta(httpContext, true); ItemCesta item = cesta.ItemsCesta.FirstOrDefault(i => i.IdProducto == productoId); if (item == null) { item = new ItemCesta() { IdCesta = cesta.Id, IdProducto = productoId, Cantidad = 1 }; cesta.ItemsCesta.Add(item); } else { //item.BasketId = bas; //item.ProductId = prroductId; item.Cantidad = item.Cantidad + 1; } cestaContext.Commit(); }
public ActionResult Index(Cesta cesta) { try { PedidoCEN pedCEN = new PedidoCEN(); PedidoCP ped = new PedidoCP(); pedCEN.Modify(cesta.pedido.Id, PracticaGenNHibernate.Enumerated.Practica.EstadoPedidoEnum.pendiente, DateTime.Now, cesta.pedido.PrecioTotal, cesta.pedido.TipoPago, true, cesta.pedido.valoracion); PedidoEN p = pedCEN.ReadOID(cesta.pedido.Id); //Aqui faltaria pillar la direccion a través de su id pero como no servia para na pues GG pedCEN.AnyadirDireccion(cesta.pedido.Id, cesta.usuario.direccion[0].id); PedidoCEN nuevo = new PedidoCEN(); nuevo.New_(PracticaGenNHibernate.Enumerated.Practica.EstadoPedidoEnum.pendiente, DateTime.Now, 0.0, PracticaGenNHibernate.Enumerated.Practica.TipoPagoEnum.contrarreembolso, cesta.usuario.id, false, 0.0); ped.Confirmar(p.Id); Session["Clineas"] = 0; return(RedirectToAction("PedidosUsuario", "Account")); } catch { return(View()); } }
public void CanAddBasketItem() { //setup IRepositorio <Cesta> baskets = new MockContext <Cesta>(); IRepositorio <Producto> products = new MockContext <Producto>(); IRepositorio <OrdenEnvio> orders = new MockContext <OrdenEnvio>(); IRepositorio <Cliente> customers = new MockContext <Cliente>(); var httpContext = new MockHttpContext(); ISCesta basketService = new SCesta(products, baskets); ISOrden orderService = new SOrden(orders); var controller = new CestaController(basketService, orderService, customers); controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); //Act //basketService.AddToBasket(httpContext, "1"); controller.AgregarACesta("1"); Cesta basket = baskets.Collection().FirstOrDefault(); //Assert Assert.IsNotNull(basket); Assert.AreEqual(1, basket.ItemsCesta.Count); Assert.AreEqual("1", basket.ItemsCesta.ToList().FirstOrDefault().IdProducto); }
/// <summary> /// Vэstavba zбstavky pre cestnй vozidlб /// </summary> /// <param name="upresnenieCinnosti">ktorб z nich</param> public void PostavZastavku(int upresnenieCinnosti) { Spolocnost spol = Hra.DajInstanciu().Spolocnost; try { Zastavka zast; if (aZastavane != null) { Cesta c = (Cesta)aZastavane; if (upresnenieCinnosti == (int)SmerZast.horizontalny && c.Orientacia == SmerCesty.vodorovne) { zast = new Zastavka(aPoloha, SmerZast.horizontalny); } else { zast = new Zastavka(aPoloha, SmerZast.vertikalny); } if (spol.OverVydavok(-zast.Cena) && OverOkolieStaniceZoskupenia(zast, 1, 1)) { aZastavane = zast; Hra.DajInstanciu().DajHernuPlochu().PrejdiPolicka(); spol.UpravFinancie(-zast.Cena); } } }catch (InvalidCastException e) { Sprava.Info("Nie je mozne postavit zastavku"); } }
public void Drive() { drive = true; string aktdruhces = ""; string mindruhces = ""; Pozice = 0; while (drive) { if (Pozice == Cesta.Length - 1) { Console.WriteLine("dojebali jsme 8=====D"); Stop(); } System.Threading.Thread.Sleep((int)((5m / CestovniRychlost) * 1000m)); aktdruhces = Cesta.Substring(Pozice, 1); road.TypeOfRoad = aktdruhces; if (aktdruhces != mindruhces) { if (mindruhces != "") { change(this, road); } } mindruhces = aktdruhces; Pozice++; } }
public List <ItemCestaViewModel> GetItemCesta(HttpContextBase httpContext) { Cesta cesta = GetCesta(httpContext, false); if (cesta != null) { var resultados = (from b in cesta.ItemsCesta join p in productoContext.Collection() on b.IdProducto equals p.Id select new ItemCestaViewModel() { Id = b.Id, Cantidad = b.Cantidad, NombreProducto = p.Nombre, Imagen = p.Imagen, Precio = p.Precio } ).ToList(); return(resultados); } else { return(new List <ItemCestaViewModel>()); } }
public void LimpiarCesta(HttpContextBase httpContext) { Cesta cesta = GetCesta(httpContext, false); cesta.ItemsCesta.Clear(); cestaContext.Commit(); }
/// <summary> /// Obsluhuje udalost kliku na bod v mape (zastavka, odpocivadlo nebo krizovatka). /// Vyuziva se na urceni pocatecniho a koncoveho vrcholu pro vyhledavani nejkratsi trasy v mape /// nebo pro pridani nove cesty do mapy. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnEllipseMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var dot = (Ellipse)sender; string klicVrcholu = dot.Name.Replace("_", " "); DataVrcholu hledanyVrcholvMape = mapa.NajdiVrcholSemA(klicVrcholu); if (hledanyVrcholvMape != null) { if (urcenPocatecniBod) { pocatek = hledanyVrcholvMape; urcenPocatecniBod = false; urcenKonecnyBod = true; //sdelim ye obsah v Label1 je typu textblock a tim dosahnu zalamovani textu vLabel1 NastavTextLabelu("Pocateční bod je " + pocatek.ToString() + ".\n Vyber cíl."); } else if (urcenKonecnyBod) { konec = hledanyVrcholvMape; urcenKonecnyBod = false; NastavTextLabelu("Pocatecni bod je: " + pocatek.ToString() + ".\n" + "Konečný bod je: " + konec.ToString() + ". Hledám nejkratší cestu..."); Cesta cesta = mapa.NajdiCestu(pocatek.NazevVrcholu, konec.NazevVrcholu); if (cesta == null) { NastavTextLabelu("Cestu se nepodařilo nalézt."); return; } string vypisCesty = "Počáteční bod je " + pocatek.ToString() + ". \n" + "Konecny bod je " + konec.ToString() + ". \n"; foreach (DataHran h in cesta.NavstiveneHrany) { h.OznaceniHrany = true; vypisCesty += "(" + h.PocatekHrany + ", " + h.KonecHrany + "), "; } VykresliMapu(); NastavTextLabelu(vypisCesty); } // pro ulozeni pocatecniho vrcholu cesty, vytvoreni a vykresleni hrany else if (stisknutoVytvorCestu) { if (pocatek == null) { pocatek = hledanyVrcholvMape; NastavTextLabelu("Vyberte konečný bod."); } else { konec = hledanyVrcholvMape; DataHran novaHrana = mapa.VytvorHranu(pocatek.NazevVrcholu, konec.NazevVrcholu, (short)SpocitejDelkuHrany(pocatek, konec)); KresliSilnici(novaHrana); stisknutoVytvorCestu = false; NastavTextLabelu("Cesta byla vytvořena."); } } } }
public ContaCorrente(string numeroAgencia, string numeroConta, string nomeCliente, decimal saldoInicial, decimal limite, Cesta cesta) { this.NumeroAgencia = numeroAgencia; this.NumeroConta = numeroConta; this.NomeCliente = nomeCliente; this.Saldo = saldoInicial; this.Limite = limite; this.Cesta = cesta; }
public ActionResult ExcluirItem(int id) { Cesta c = (Cesta)Session["cesta"]; c.ItensCesta.RemoveAll(i => i.Produto.IdProduto == id); c.ValorTotal = c.ItensCesta.Sum(i => i.ValorTotal); return(View("Cesta")); }
public void RemoverDeCesta(HttpContextBase httpContext, string itemId) { Cesta cesta = GetCesta(httpContext, true); ItemCesta item = cesta.ItemsCesta.FirstOrDefault(i => i.Id == itemId); if (item != null) { cesta.ItemsCesta.Remove(item); cestaContext.Commit(); } }
public ActionResult AumentarQuantidade(int id) { Cesta c = (Cesta)Session["cesta"]; ItemCesta item = c.ItensCesta.Where(i => i.Produto.IdProduto == id) .FirstOrDefault(); item.Quantidade++; c.ValorTotal = c.ItensCesta.Sum(i => i.ValorTotal); return(View("Cesta")); }
private Cesta CrearNuevaCesta(HttpContextBase httpContext) { Cesta cesta = new Cesta(); cestaContext.Insertar(cesta); cestaContext.Commit(); HttpCookie cookie = new HttpCookie(NombreCesta); cookie.Value = cesta.Id; cookie.Expires = DateTime.Now.AddDays(1); httpContext.Response.Cookies.Add(cookie); return(cesta); }
public void CanGetSummaryViewModel() { IRepositorio <Cesta> baskets = new MockContext <Cesta>(); IRepositorio <Producto> products = new MockContext <Producto>(); IRepositorio <OrdenEnvio> orders = new MockContext <OrdenEnvio>(); IRepositorio <Cliente> customers = new MockContext <Cliente>(); products.Insertar(new Producto() { Id = "1", Precio = 10.00m }); products.Insertar(new Producto() { Id = "2", Precio = 5.00m }); Cesta basket = new Cesta(); basket.ItemsCesta.Add(new ItemCesta() { IdProducto = "1", Cantidad = 2 }); basket.ItemsCesta.Add(new ItemCesta() { IdProducto = "2", Cantidad = 1 }); baskets.Insertar(basket); ISCesta basketService = new SCesta(products, baskets); ISOrden orderService = new SOrden(orders); var controller = new CestaController(basketService, orderService, customers); var httpContext = new MockHttpContext(); httpContext.Request.Cookies.Add(new System.Web.HttpCookie("PrimussCesta") { Value = basket.Id }); controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); var result = controller.ResumenCesta() as PartialViewResult; var basketSummary = (ResumenCestaViewModel)result.ViewData.Model; Assert.AreEqual(3, basketSummary.Recuento); Assert.AreEqual(25.00m, basketSummary.TotalCesta); }
public ActionResult AdicionarItem(int id) { try { ProdutoRepositorio rep = new ProdutoRepositorio(); Cesta c = new Cesta(); if (Session["cesta"] != null) { c = (Cesta)Session["cesta"]; } else { c = new Cesta(); c.ItensCesta = new List <ItemCesta>(); } ItemCesta itemExistente = c.ItensCesta .Where(i => i.Produto.IdProduto == id) .FirstOrDefault(); if (itemExistente != null) { itemExistente.Quantidade++; } else { ItemCesta item = new ItemCesta(); item.Quantidade = 1; item.Produto = rep.ObterPorId(id); c.ItensCesta.Add(item); } c.ValorTotal = c.ItensCesta.Sum(i => i.ValorTotal); Session.Add("cesta", c); } catch (Exception e) { ViewBag.Mensagem = e.Message; } return(View("Cesta")); }
public IActionResult EliminarPeli(int id) { List <Cesta> listacesta = session.GetObject <List <Cesta> >("CESTA"); List <Cesta> cestita = new List <Cesta>(); foreach (Cesta c in listacesta) { if (c.IdPelicula != id) { Cesta cesta = new Cesta(); cesta.IdPelicula = c.IdPelicula; cesta.Precio = c.Precio; cestita.Add(cesta); } } session.SetObject("CESTA", cestita); return(RedirectToAction("vercesta")); }
/// <summary> /// vэstavby cersty /// </summary> /// <param name="paSmer">smer</param> public void PostavCestu(int paSmer) { Spolocnost spol = Hra.DajInstanciu().Spolocnost; if (paSmer > 0 && paSmer <= Enum.GetNames(typeof(SmerCesty)).Length) { if (this.MozemStavat()) { this.Zburaj(false); Cesta cest = new Cesta((SmerCesty)paSmer, aPoloha); if(spol.UpravFinancie(-cest.Cena)){ aZastavane = cest; Hra.DajInstanciu().DajHernuPlochu().PrejdiPolicka(); } } } else { Console.WriteLine("Nie je mozne stavat"); } }
public Cesta fabricaCesta(Usuario usuario) { Cesta cesta = new Cesta(usuario); string[] datosTxTCestas = File.ReadAllLines(CFichero.rutaCestas); if (datosTxTCestas[0].Split(':')[0] != "") { string datosCestaUsuario = datosTxTCestas.Where(linea => linea.Split(':')[1] == usuario.nombre && linea.Split(':')[0] == "1").SingleOrDefault(); if (datosCestaUsuario == null) { StreamWriter sw = new StreamWriter(new FileStream(CFichero.rutaCestas, FileMode.Append)); sw.WriteLine(cesta.activa + ":" + usuario.nombre); sw.Close(); } else { for (int i = 2; i < datosCestaUsuario.Split(':').Count(); i++) { cesta.listaLibros.Add(fabricaLibros(datosCestaUsuario.Split(':')[i], false)); } } } return(cesta); }
public ResumenCestaViewModel GetResumenCesta(HttpContextBase httpContext) { Cesta cesta = GetCesta(httpContext, false); ResumenCestaViewModel model = new ResumenCestaViewModel(0, 0); if (cesta != null) { int?recuento = (from item in cesta.ItemsCesta select item.Cantidad).Sum(); decimal?totalCcesta = (from item in cesta.ItemsCesta join p in productoContext.Collection() on item.IdProducto equals p.Id select item.Cantidad *p.Precio).Sum(); model.Recuento = recuento ?? 0; model.TotalCesta = totalCcesta ?? decimal.Zero; return(model); } else { return(model); } }
static void Main(string[] args) { // Polimorfismo Veiculo[] veiculo = new Veiculo[2]; veiculo[0] = new Automovel("Ferrari"); veiculo[1] = new Aeronave("Tucano"); veiculo[0].Mover(); veiculo[1].Mover(); // Abstração var quadrado = new Quadrado(10); quadrado.CalcularArea(); quadrado.CalcularPerimetro(); Console.WriteLine($"Area: {quadrado.Area}"); Console.WriteLine($"Perímetro: {quadrado.Perimetro}"); // Encapsulamento var conta = new Conta(); // conta.Saldo = 100; -Não consido usar conta.Depositar(100); // IDisposable: Fornece um mecanismo para liberar recursos não gerenciados. LogWriter log = new LogWriter("ArquivoLog.txt"); log.Dispose(); // IComparable: Define um método de comparação de tipo específico generalizado que implementa uma classe ou um tipo de valor para solicitar ou classificar suas instâncias. var listaTemperaturas = new List <Temperatura>(); Random rnd = new Random(); for (int i = 0; i < 10; i++) { int temperatura = rnd.Next(0, 100); Temperatura temp = new Temperatura(); temp.Fahrenheit = temperatura; listaTemperaturas.Add(temp); } listaTemperaturas.Sort(); // O comparador padrão agora é o que implementamos foreach (Temperatura temp in listaTemperaturas) { Console.WriteLine(temp.Fahrenheit); } // ICloneable var jose = new Pessoa("José", "Santana", 33); var joseClone = jose.Clone(); // IEnumerable var cesta = new Cesta(new string[] { "Banana", "Abacaxi", "Uva" }); foreach (var fruta in cesta) { Console.WriteLine(fruta); } }
private void generarCesta(Cesta cesta) { table_Cesta.Controls.Clear(); // Cabecera TableRow fila = new TableRow(); table_Cesta.Rows.Add(fila); TableCell columna = new TableCell(); Label label = new Label(); label.Text = "Tu cesta"; label.Style.Add("text-align", "center"); label.Font.Bold = true; label.Style.Add("display", "block"); columna.Controls.Add(label); table_Cesta.Rows[0].Cells.Add(columna); // Libros fila = new TableRow(); table_Cesta.Rows.Add(fila); columna = new TableCell(); foreach (Libro libro in cesta.listaLibros.Distinct(ayudante.comparadorTitulos()).OrderBy(libro => libro.titulo)) { VCestas vC = LoadControl("~/ControladoresObjetos/VCestas.ascx") as VCestas; vC.crearVCestas(libro.titulo); vC.cantidad = ayudante.librosRepetidos(libro, cesta.listaLibros); vC.getButton().ID = vC.getButton().ID + "$" + libro.ISBN10; columna.Controls.Add(vC); } table_Cesta.Rows[1].Cells.Add(columna); // Coste fila = new TableRow(); table_Cesta.Rows.Add(fila); columna = new TableCell(); label = new Label(); label.Text = "Total : "; double total = 0; foreach (Libro libro in cesta.listaLibros) { total += libro.precio; } label.Text += total + " €"; label.Font.Bold = true; label.Style.Add("display", "block"); table_Cesta.Rows[2].Cells.Add(columna); columna.Controls.Add(label); // Comprar fila = new TableRow(); table_Cesta.Rows.Add(fila); columna = new TableCell(); Button pagar_button = new Button(); pagar_button.ID = "button_Pagar"; pagar_button.Text = "Pagar"; pagar_button.Click += new EventHandler(pagar_boton_Click); columna.HorizontalAlign = HorizontalAlign.Center; table_Cesta.Rows[3].Cells.Add(columna); columna.Controls.Add(pagar_button); int cont = 0; foreach (TableRow filaSeleccionada in table_Cesta.Rows) { filaSeleccionada.Cells[0].ControlStyle.BorderColor = System.Drawing.Color.FromArgb(Convert.ToInt32("ff9966", 16)); filaSeleccionada.Cells[0].ControlStyle.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32("ff9966", 16)); if (cont == 1) { filaSeleccionada.Cells[0].ControlStyle.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32("ffcc99", 16)); } filaSeleccionada.Cells[0].ControlStyle.BorderStyle = BorderStyle.Solid; cont++; } }
public void CanCheckoutAndCreateOrder() { IRepositorio <Cliente> customers = new MockContext <Cliente>(); IRepositorio <Producto> products = new MockContext <Producto>(); products.Insertar(new Producto() { Id = "1", Precio = 10.00m }); products.Insertar(new Producto() { Id = "2", Precio = 5.00m }); IRepositorio <Cesta> baskets = new MockContext <Cesta>(); Cesta basket = new Cesta(); basket.ItemsCesta.Add(new ItemCesta() { IdProducto = "1", Cantidad = 2, IdCesta = basket.Id }); basket.ItemsCesta.Add(new ItemCesta() { IdProducto = "1", Cantidad = 1, IdCesta = basket.Id }); baskets.Insertar(basket); ISCesta basketService = new SCesta(products, baskets); IRepositorio <OrdenEnvio> orders = new MockContext <OrdenEnvio>(); ISOrden orderService = new SOrden(orders); customers.Insertar(new Cliente() { Id = "1", CorreoCliente = "*****@*****.**", CodigoPostalCliente = "90210" }); IPrincipal FakeUser = new GenericPrincipal(new GenericIdentity("*****@*****.**", "Forms"), null); var controller = new CestaController(basketService, orderService, customers); var httpContext = new MockHttpContext(); httpContext.User = FakeUser; httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket") { Value = basket.Id }); controller.ControllerContext = new ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); //Act OrdenEnvio order = new OrdenEnvio(); controller.Comprar(order); //assert Assert.AreEqual(2, order.ItemsOrden.Count); Assert.AreEqual(0, basket.ItemsCesta.Count); OrdenEnvio orderInRep = orders.Buscar(order.Id); Assert.AreEqual(2, orderInRep.ItemsOrden.Count); }
public ContaCorrente AbrirConta(string numeroAgencia, string nomeCliente, decimal saldoInicial, decimal limite, Cesta cesta) { ContaCorrente conta = new ContaCorrente(numeroAgencia, contasCorrentes.Count.ToString(), nomeCliente, saldoInicial, limite, cesta);; contasCorrentes.Add(conta); return(conta); }