public async Task <ActionResult> AddOrden(AddOrdenViewModel aovm) { Empleado e = db.Empleado.Where(x => x.IdEmpleado == 1).FirstOrDefault(); Pedido p = new Pedido(); p.Cantidad = aovm.numpersonas; p.Cliente = aovm.cliente; p.Empleado = e; p.Estado = 1; p.IdMesa = aovm.mesa; db.Pedido.Add(p); await db.SaveChangesAsync(); var lastPedido = db.Pedido.OrderByDescending(x => x.IdPedido).First(); for (var i = 0; i < aovm.id.Count; i++) { DetallePedido dp = new DetallePedido(); dp.IdMenu = aovm.id[i]; dp.cantidad = aovm.cantidad[i]; dp.IdPedido = lastPedido.IdPedido; db.DetallePedido.Add(dp); await db.SaveChangesAsync(); //Encontrar el menu var menu = db.Menus.Find(dp.IdMenu); //Buscar los menus en la receta var recmenu = (from u in db.Receta where u.IdMenu == menu.IdMenu select u).ToList(); //Recorrer foreach (var io in recmenu) { //Encontrar los productos que se utilizan Productos de = db.Productos.Find(io.IdProducto); //Resta de la cantidad que se pide menos la cantidad utilizada var Descuento = io.CantidadUtilizada * dp.cantidad; de.Cantidad = de.Cantidad - Descuento; db.Entry(de).State = EntityState.Modified; db.SaveChanges(); } } //Encontrar las mesas Mesa d = db.Mesa.Find(aovm.mesa); //Cambia el estado de la mesa d.Estado = false; db.Entry(d).State = EntityState.Modified; db.SaveChanges(); return(Redirect("Index")); }
public async Task <ActionResult> AddOrden(AddOrdenViewModel aovm, int?idPedido) { int user = Convert.ToInt32(Session["Id"]); var buscarPedido = db.Pedido.Find(idPedido); if (buscarPedido != null) { buscarPedido.Estado = 1; db.Entry(buscarPedido).State = EntityState.Modified; await db.SaveChangesAsync(); } if (buscarPedido == null) { Pedido p = new Pedido(); p.Cantidad = aovm.numpersonas; p.Cliente = aovm.cliente; p.IdUser = user; p.Estado = 1; p.IdMesa = aovm.mesa; p.FechaInicial = Convert.ToString(DateTime.Now); db.Pedido.Add(p); await db.SaveChangesAsync(); } var lastPedido = db.Pedido.OrderByDescending(x => x.IdPedido).FirstOrDefault(); for (var i = 0; i < aovm.id.Count; i++) { DetallePedido dp = new DetallePedido(); dp.IdMenu = aovm.id[i]; dp.cantidad = aovm.cantidad[i]; dp.IdPedido = lastPedido.IdPedido; dp.Comentarios = aovm.comentarios[i]; dp.Estado = 1; dp.Termino = ((aovm.termino[i] == null || aovm.termino[i] == "undefined") ?"NaN":aovm.termino[i]); db.DetallePedido.Add(dp); await db.SaveChangesAsync(); //Encontrar el menu var menu = db.Menus.Find(dp.IdMenu); //Buscar los menus en la receta var recmenu = (from u in db.Receta where u.IdMenu == menu.IdMenu select u).ToList(); //Recorrer foreach (var io in recmenu) { //Encontrar los productos que se utilizan Productos de = db.Productos.Find(io.IdProducto); //Resta de la cantidad que se pide menos la cantidad utilizada var Descuento = io.CantidadUtilizada * dp.cantidad; de.Cantidad = de.Cantidad - Descuento; db.Entry(de).State = EntityState.Modified; db.SaveChanges(); } } //Encontrar las mesas Mesa d = db.Mesa.Find(aovm.mesa); //Cambia el estado de la mesa d.Estado = false; db.Entry(d).State = EntityState.Modified; db.SaveChanges(); return(Redirect("Index")); }
public ActionResult RealizarPago(double txttotal, double Total, int idPedido, int idDetalle, double Descuento, string Descripcion, double propina, AddOrdenViewModel cvm) { Factura p = new Factura(); //p.NumFactura =1; p.IdPedido = idPedido; p.TotalNeto = txttotal; p.Total = Total; p.Descuento = Descuento; p.Descripcion = Descripcion; p.Propina = propina; p.FechaFactura = DateTime.Now.Date; db.Factura.Add(p); db.SaveChanges(); var det = (from x in db.DetallePedido where x.IdPedido == idPedido select x).ToList(); foreach (var i in det) { DetallePedido de = db.DetallePedido.Find(i.IdDetalle); de.Estado = 3; db.Entry(de).State = EntityState.Modified; db.SaveChanges(); } //Buscar cada Pedido var pedido = (from u in db.Pedido where u.IdPedido == idPedido select u).ToList(); //Recorrer foreach (var io in pedido) { Pedido pe = db.Pedido.Find(io.IdPedido); pe.Estado = 3; db.Entry(pe).State = EntityState.Modified; db.SaveChanges(); } //var mesa = db.Mesa.Where(x => x.IdMesa == pedido[0].IdMesa).FirstOrDefault(); Mesa d = db.Mesa.Find(pedido[0].IdMesa); d.Estado = true; db.Entry(d).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Factura", "Facturas", new { idPedido = pedido[0].IdPedido, idDetalle = det[0].IdDetalle })); }
public ActionResult RealizarPago(double txttotal, int idPedido, int idDetalle, double Descuento, string Descripcion, double propina, AddOrdenViewModel cvm) { //Session["pedido"] = 0; //Session["mesa"] = 0; //Session["pedidoid"]= 0; Session.Remove("pedidoid"); Session.Clear(); Session["pedidoid"] = 0; Session.Remove("pedido"); Session.Clear(); Session["pedido"] = 0; Session.Remove("mesa"); Session.Clear(); Session["mesa"] = 0; Factura p = new Factura(); //p.NumFactura =1; p.IdDetalle = idDetalle; p.Precio = txttotal; p.Descuento = Descuento; p.Descripcion = Descripcion; p.Propina = propina; p.FechaFactura = Convert.ToString(DateTime.Now.Date); db.Factura.Add(p); db.SaveChanges(); //var detalle = db.DetallePedido.Find(p.IdDetalle); //var det = (from x in db.DetallePedido where x.IdDetalle == detalle.IdDetalle select x).ToList(); var det = (from x in db.DetallePedido where x.IdPedido == idPedido select x).ToList(); foreach (var i in det) { DetallePedido de = db.DetallePedido.Find(i.IdDetalle); de.Estado = 3; db.Entry(de).State = EntityState.Modified; db.SaveChanges(); } //Buscar cada Pedido var pedido = (from u in db.Pedido where u.IdPedido == idPedido select u).ToList(); //Recorrer foreach (var io in pedido) { Pedido pe = db.Pedido.Find(io.IdPedido); pe.Estado = 3; db.Entry(pe).State = EntityState.Modified; db.SaveChanges(); } //var dm = db.Mesa.Find(idDetalle); //var mesa = (from x in db.Mesa where x.IdMesa == dm.IdMesa select x); //foreach (var i in mesa) //{ // Mesa d = db.Mesa.Find(i.IdMesa); // d.Estado = true; // db.Entry(d).State = EntityState.Modified; // db.SaveChanges(); // return Redirect("Index"); //} return(Redirect("Index")); }