public ActionResult DeleteConfirmed(int id) { ProductosPedidos productosPedidos = db.ProductosPedidos.Find(id); db.ProductosPedidos.Remove(productosPedidos); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id_productosPedido,FIdPedido,FIdProducto,Cantidad")] ProductosPedidos productosPedidos) { if (ModelState.IsValid) { db.Entry(productosPedidos).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FIdProducto = new SelectList(db.Productos, "Id_prod", "Nombre_prod", productosPedidos.FIdProducto); return(View(productosPedidos)); }
// GET: ProductosPedidos/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductosPedidos productosPedidos = db.ProductosPedidos.Find(id); if (productosPedidos == null) { return(HttpNotFound()); } return(View(productosPedidos)); }
public JsonResult GuardarPedido(string HasDate) { if (Session["ListadoPlatillos"] == null) { return(Json("", JsonRequestBehavior.AllowGet)); } List <ProductosPedidos> ListadoPlatillos; ProductosPedidos NewProducto = new ProductosPedidos(); Guid id; if (User.Identity != null) { id = Guid.Parse(User.Identity.GetUserId().ToString()); } else { id = new Guid(); } if (HasDate != null) { DateTime xDate; } ListadoPlatillos = Session["ListadoPlatillos"] as List <ProductosPedidos>; string idOrden = ""; string IDMesa = ""; if (Session["IDOrden"] != null) { idOrden = Session["IDOrden"].ToString(); } if (Session["MesasSeleccionadas"] != null) { List <string> xMesas = Session["MesasSeleccionadas"] as List <string>; IDMesa = xMesas[0].Substring(2); } string xResult = ARService.GuardaPedido(ListadoPlatillos, id, Convert.ToInt32(Session["IDEmpleado"]), Convert.ToDouble(Session["SubTotal"]), HasDate, idOrden, IDMesa); if (xResult.Contains("GUID:")) { Guid xID = Guid.Parse(xResult.Substring(5)); Session["Order-GUID"] = xID; Session["ListadoPlatillos"] = null; } if (Session["IDOrden"] != null) { xResult = "StayOnPage"; } return(Json(xResult, JsonRequestBehavior.AllowGet)); }
public JsonResult PersonalizarPlatillos(string RidProdCustom, string Comentarios, string Accion, List <string> chkValues) { int id; double SubTotal = 0; if (RidProdCustom != null) { id = Convert.ToInt32(RidProdCustom); List <ProductosPedidos> ListadoPlatillos; ProductosPedidos NewProducto = new ProductosPedidos(); if (Session["ListadoPlatillos"] == null) { ListadoPlatillos = new List <ProductosPedidos>(); } else { ListadoPlatillos = Session["ListadoPlatillos"] as List <ProductosPedidos>; } if (id > 0) { if (Accion.Equals("Agregar")) { ListadoPlatillos.Find(x => x.ID == id).Observaciones = Comentarios; } else { ListadoPlatillos.Find(x => x.ID == id).Observaciones = ""; } if (chkValues.Count > 0) { for (int i = 1; i < chkValues.Count; i++) { ListadoPlatillos.Find(x => x.ID == id).ComplementodeProducto[i - 1].Seleccionado = Convert.ToBoolean(Convert.ToInt32(chkValues[i])); } } Session["ListadoPlatillos"] = ListadoPlatillos; } if (Session["ListadoPlatillos"] != null) { for (int i = 0; i < ListadoPlatillos.Count(); i++) { SubTotal += ListadoPlatillos[i].Precio * ListadoPlatillos[i].Cantidad; } Session["SubTotal"] = SubTotal.ToString("###,##0.00"); return(Json("", JsonRequestBehavior.AllowGet)); } } return(Json("", JsonRequestBehavior.AllowGet)); }
// GET: ProductosPedidos/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductosPedidos productosPedidos = db.ProductosPedidos.Find(id); if (productosPedidos == null) { return(HttpNotFound()); } ViewBag.FIdProducto = new SelectList(db.Productos, "Id_prod", "Nombre_prod", productosPedidos.FIdProducto); return(View(productosPedidos)); }
public ActionResult Pedido(CarritoCompra cc) { Pedido pedido = new Pedido(); pedido.IdUsuario = User.Identity.Name; List <Producto> productos = ProductList(cc); foreach (Producto producto in productos) { ProductosPedidos pp = new ProductosPedidos(); pp.Producto = db.Productos.Find(producto.Id); pp.Cantidad_Productos = producto.Cantidad; pp.Pedidoes.Add(pedido); db.ProductosPedidos.Add(pp); } Factura factura = new Factura(); factura.ImporteTotal = 0; foreach (Producto producto in productos) { Producto productodb = db.Productos.Find(producto.Id); productodb.Cantidad -= producto.Cantidad; factura.ImporteTotal += producto.Precio * producto.Cantidad; if (productodb.Cantidad <= 2) { Stock stock = new Stock(); stock.Productoes = productodb; stock.Reabastecido = false; db.Stocks.Add(stock); } } factura.Pedido = pedido; db.Facturas.Add(factura); db.Pedidoes.Add(pedido); db.SaveChanges(); cc.Clear(); return(RedirectToAction("Index")); }
public int CreateOrder(PedidosCliente customerOrder) { decimal orderTotal = 0; var cartItems = GetCartItems(); ////Mercado Pago //SDK.ClientId = "1782351866703164"; //SDK.ClientSecret = "6nNax7XMsv6y4qiKxDhEJ4zmZZlCmlCN"; //// Create a preference object //Preference preference = new Preference(); foreach (var item in cartItems) { var stockProductos = db.Productos.FirstOrDefault(p => p.ProductoId == item.Producto.ProductoId); stockProductos.Stock = stockProductos.Stock - item.Cantidad; var orderedProduct = new ProductosPedidos { ProductoId = item.ProductoId, PedidoClienteId = customerOrder.Id, Cantidad = item.Cantidad }; orderTotal += (item.Cantidad * item.Producto.Precio); db.ProductosPedidos.Add(orderedProduct); // //# Adding an item object // preference.Items.Add( // new Item() // { // Id = item.ProductoId.ToString(), // Title = "Nombre: " + customerOrder.NombreCompleto, // Quantity = item.Cantidad, // CurrencyId = 0, // UnitPrice = item.Producto.Precio // } // ); } //// Setting a payer object as value for Payer property //preference.Payer = new Payer() //{ // Email = customerOrder.Email, // Name = customerOrder.Nombres, // Surname = customerOrder.Apellido, // Phone = new Phone // { // Number = customerOrder.Telefono // }, // Date_created = customerOrder.FechaCreacion, // Identification = new Identification // { // Type = "DNI", // Number = customerOrder.DNI, // } } ; //// Save and posti ng preference //preference.Save(); customerOrder.Cantidad = orderTotal; //customerOrder.UrlMercadoPago = preference.InitPoint; db.SaveChanges(); EmptyCart(); return(customerOrder.Id); }
public ActionResult MostrarPlatillos(int?id) { if (Session["IsMesero"] != null) { ViewBag.IsMesero = true; } if (id != null) { List <ProductosPedidos> ListadoPlatillos; ProductosPedidos NewProducto = new ProductosPedidos(); double SubTotal = 0; if (Session["ListadoPlatillos"] == null) { ListadoPlatillos = new List <ProductosPedidos>(); } else { ListadoPlatillos = Session["ListadoPlatillos"] as List <ProductosPedidos>; } if (id != null) { if (id > 0) { if (ListadoPlatillos.Exists(x => x.ID == id.Value)) { ListadoPlatillos.Find(x => x.ID == id.Value).Cantidad += 1; } else { NewProducto.ID = id.Value; NewProducto.Cantidad = 1; ListadoPlatillos.Add(NewProducto); } Session["ListadoPlatillos"] = ListadoPlatillos; } if (id < 0) { ListadoPlatillos.Find(x => x.ID == (id.Value * -1)).Cantidad += -1; if (ListadoPlatillos.Find(x => x.ID == (id.Value * -1)).Cantidad < 1) { ListadoPlatillos.Remove(ListadoPlatillos.Find(x => x.ID == (id.Value * -1))); } if (ListadoPlatillos == null || ListadoPlatillos.Count == 0) { Session["ListadoPlatillos"] = null; } else { Session["ListadoPlatillos"] = ListadoPlatillos; } } } if (Session["ListadoPlatillos"] != null) { int i = 0; List <int> AddProd = new List <int>(); foreach (var item in ListadoPlatillos) { AddProd.Add(item.ID); } List <Productos> productos = this.ARService.BuscarProductos(AddProd); for (i = 0; i < productos.Count(); i++) { ListadoPlatillos.Find(x => x.ID == productos[i].ID).Producto = productos[i].Producto; ListadoPlatillos.Find(x => x.ID == productos[i].ID).Descripcion = productos[i].Descripcion; ListadoPlatillos.Find(x => x.ID == productos[i].ID).Precio = productos[i].Precio; ListadoPlatillos.Find(x => x.ID == productos[i].ID).UnidadMedida = productos[i].UnidadMedida; SubTotal += ListadoPlatillos.Find(x => x.ID == productos[i].ID).Precio *ListadoPlatillos.Find(x => x.ID == productos[i].ID).Cantidad; } List <ComplementoProductos> complementos = this.ARService.BuscarProductosComplementarios(AddProd); if (complementos != null) { if (complementos.Count() > 0) { for (i = 0; i < AddProd.Count(); i++) { if (ListadoPlatillos.Find(x => x.ID == AddProd[i]).ComplementodeProducto == null) { IEnumerable <ComplementoProductos> xComplementos = complementos.Where(x => x.idProducto == AddProd[i]); List <ComplementoProductos> xComplemento = new List <ComplementoProductos>(); for (int e = 0; e < xComplementos.Count(); e++) { xComplemento.Add(xComplementos.ElementAt(e) as ComplementoProductos); } ListadoPlatillos.Find(x => x.ID == AddProd[i]).ComplementodeProducto = xComplemento; } } } } ViewBag.SubTotal = SubTotal.ToString("###,##0.00"); Session["SubTotal"] = SubTotal.ToString("###,##0.00"); return(PartialView("_MostrarPlatillos", ListadoPlatillos)); } //return View(this.ARService.GetProductos(id.Value)); } ViewBag.ListadoPlatillos = Session["ListadoPlatillos"]; return(PartialView("_MostrarPlatillos")); }
public ActionResult ARGuardar(string Mesa, string Fecha, string Items) { if (Mesa != null && Fecha != null && Items != null) { List <string> PlatillosPedidos = new List <string>(); string[] xProductosSeleccionados = Items.Split(','); List <int> AddProd = new List <int>(); foreach (var item in xProductosSeleccionados) { AddProd.Add(Convert.ToInt32(item)); } List <Productos> productos = this.ARService.BuscarProductos(AddProd); int i = 0; List <ProductosPedidos> ListadoPlatillos = new List <ProductosPedidos>(); foreach (var item in productos) { ProductosPedidos xProd = new ProductosPedidos(); xProd.ID = item.ID; xProd.Producto = item.Producto; xProd.Descripcion = item.Descripcion; xProd.Precio = item.Precio; xProd.UnidadMedida = item.UnidadMedida; xProd.Cantidad = 1; ListadoPlatillos.Add(xProd); } List <ComplementoProductos> complementos = this.ARService.BuscarProductosComplementarios(AddProd); if (complementos != null) { if (complementos.Count() > 0) { for (i = 0; i < AddProd.Count(); i++) { if (ListadoPlatillos.Find(x => x.ID == AddProd[i]).ComplementodeProducto == null) { IEnumerable <ComplementoProductos> xComplementos = complementos.Where(x => x.idProducto == AddProd[i]); List <ComplementoProductos> xComplemento = new List <ComplementoProductos>(); for (int e = 0; e < xComplementos.Count(); e++) { xComplemento.Add(xComplementos.ElementAt(e) as ComplementoProductos); } ListadoPlatillos.Find(x => x.ID == AddProd[i]).ComplementodeProducto = xComplemento; } } } } //0List<ProductosPedidos> ListadoPlatillos; ProductosPedidos NewProducto = new ProductosPedidos(); Guid id = new Guid(); Fecha = Fecha.Replace("_", " "); DateTime xDate = DateTime.ParseExact(Fecha, "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture);; string idOrden = ""; string IDMesa = Mesa.Substring(1); string xResult = ARService.GuardaPedido(ListadoPlatillos, id, Convert.ToInt32(Session["IDEmpleado"]), Convert.ToDouble(Session["SubTotal"]), Fecha, idOrden, IDMesa); Guid xID = Guid.Parse(xResult.Substring(5)); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(xID.ToString(), QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); //System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); //imgBarCode.Height = 150; //imgBarCode.Width = 150; using (Bitmap bitMap = qrCode.GetGraphic(20)) { Fecha = Fecha.Replace(@"\", ""); Fecha = Fecha.Replace(@":", ""); Fecha = Fecha.Replace(@" ", ""); var folder = Server.MapPath("~/QROrders/" + Mesa + "_" + Fecha); bitMap.Save(folder, System.Drawing.Imaging.ImageFormat.Jpeg); //using (MemoryStream ms = new MemoryStream()) //{ // bitMap.Save( ms , System.Drawing.Imaging.ImageFormat.Png); // ViewBag.imageBytes = ms.ToArray(); // //imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage); //} } } return(View()); }
public JsonResult LlenaSessionInfo(string idOrden, string IDMesaApartada) { if (idOrden != null) { if (idOrden.Length > 0) { Session["ListadoPlatillos"] = null; Session["IsMesero"] = true; Session["IDOrden"] = idOrden; Session["IDMesaApartada"] = IDMesaApartada; vmPedidos xpedidos = new vmPedidos(); List <Guid> xID = new List <Guid>(); xID.Add(Guid.Parse(idOrden)); List <Documentos> ListadoDocumentos = ARService.getDocumentos(xID); List <DocPartidas> ListadoDocPartidas = ARService.getDocumentosPartidas(xID); List <DocPartidasPersonalizar> ListadoDocPartidasPersonalizar = ARService.getDocumentosPartidasPersonalizar(xID); List <int> AddProd = new List <int>(); int i = 0; List <ProductosPedidos> ListadoPlatillos = new List <ProductosPedidos>(); for (i = 0; i < ListadoDocPartidas.Count; i++) { AddProd.Add(ListadoDocPartidas[i].IDProd); ProductosPedidos xProd = new ProductosPedidos(); xProd.ID = ListadoDocPartidas[i].IDProd; xProd.Cantidad = Convert.ToInt32(ListadoDocPartidas[i].Cantidad); xProd.Surtido = Convert.ToInt32(ListadoDocPartidas[i].Surtido); xProd.Descripcion = ListadoDocPartidas[i].Descripcion; xProd.Precio = ListadoDocPartidas[i].Precio; xProd.UnidadMedida = ListadoDocPartidas[i].UnidadMedida; ListadoPlatillos.Add(xProd); } if (ListadoDocPartidasPersonalizar.Count > 0) { List <ComplementoProductos> complementos = this.ARService.BuscarProductosComplementarios(AddProd); if (complementos != null) { if (complementos.Count() > 0) { for (i = 0; i < AddProd.Count(); i++) { if (ListadoPlatillos.Find(x => x.ID == AddProd[i]).ComplementodeProducto == null) { IEnumerable <ComplementoProductos> xComplementos = complementos.Where(x => x.idProducto == AddProd[i]); List <ComplementoProductos> xComplemento = new List <ComplementoProductos>(); for (int e = 0; e < xComplementos.Count(); e++) { xComplemento.Add(xComplementos.ElementAt(e) as ComplementoProductos); if (ListadoDocPartidasPersonalizar.Find(x => x.IDProdAgregado == xComplemento[xComplemento.Count - 1].idComplemento && x.IDProdPersonalizado == xComplemento[xComplemento.Count - 1].idProducto) != null) { xComplemento[xComplemento.Count - 1].Seleccionado = true; } } ListadoPlatillos.Find(x => x.ID == AddProd[i]).ComplementodeProducto = xComplemento; } } } } } Session["ListadoPlatillos"] = ListadoPlatillos; } } return(Json("", JsonRequestBehavior.AllowGet)); }