public IHttpActionResult Postpedido_detalle(pedido_detalle pedido_detalle) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.pedido_detalle.Add(pedido_detalle); try { db.SaveChanges(); } catch (DbUpdateException) { if (pedido_detalleExists(pedido_detalle.uid_pedido_d)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = pedido_detalle.uid_pedido_d }, pedido_detalle)); }
public IHttpActionResult Putpedido_detalle(int id, pedido_detalle pedido_detalle) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pedido_detalle.uid_pedido_d) { return(BadRequest()); } db.Entry(pedido_detalle).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!pedido_detalleExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult GuardarDetalle(PedidoViewModel pedidoViewModel) { var plato = _context.plato.SingleOrDefault(p => p.plato_id == pedidoViewModel .PedidoDetalle.plato_id_fk); var pedidoDetalle = new pedido_detalle { plato_id_fk = pedidoViewModel.PedidoDetalle.plato_id_fk, cantidad = pedidoViewModel.PedidoDetalle.cantidad, precio = plato?.precio * pedidoViewModel.PedidoDetalle.cantidad ?? 0, pedido_cabecera_id_fk = pedidoViewModel.PedidoCabecera.pedido_cabecera_id }; _context.pedido_detalle.Add(pedidoDetalle); _context.SaveChanges(); var pedidoCabecera = _context.pedido_cabecera.Find(pedidoDetalle.pedido_cabecera_id_fk); if (pedidoCabecera != null) { pedidoCabecera.precio_final += pedidoDetalle.precio; } _context.SaveChanges(); pedidoViewModel.PedidoCabecera = pedidoCabecera; pedidoViewModel.PedidoDetalle = pedidoDetalle; pedidoViewModel.PedidoDetalleList = _context.pedido_detalle .Where(p => p.pedido_cabecera_id_fk == pedidoViewModel.PedidoCabecera.pedido_cabecera_id).ToList(); return(View("PedidoDetalle", pedidoViewModel)); }
public JsonResult EnviarPedido(List <string> platoIds, List <string> cantidad, int mesaId) { var userId = System.Web.HttpContext.Current.User.Identity.GetUserId(); var pedidoCabecera = new pedido_cabecera { mesa_id_fk = mesaId, estado = EstadoPedidoCabecera.Enviado, fecha = DateTime.Now, precio_final = 0 }; _context.pedido_cabecera.Add(pedidoCabecera); _context.SaveChanges(); for (var i = 0; i < platoIds.Count; i++) { var platoId = Convert.ToInt32(platoIds[i]); var plato = _context.plato.SingleOrDefault(p => p.plato_id == platoId); var pedidoDetalle = new pedido_detalle { plato_id_fk = Convert.ToInt32(platoIds[i]), cantidad = Convert.ToInt32(cantidad[i]), precio = plato.precio * Convert.ToInt32(cantidad[i]), pedido_cabecera_id_fk = pedidoCabecera.pedido_cabecera_id }; _context.pedido_detalle.Add(pedidoDetalle); _context.SaveChanges(); } return(Json(platoIds, JsonRequestBehavior.AllowGet)); }
public PedidoViewModel() { PedidoCabecera = new pedido_cabecera(); PedidoDetalleList = new List <pedido_detalle>(); PedidoDetalle = new pedido_detalle(); Restaurante = new restaurante(); }
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e) { if (!HttpContext.Current.User.Identity.IsAuthenticated) { FormsAuthentication.RedirectToLoginPage(); e.Cancel = true; } else if ((dtpCalendario.SelectedDate < DateTime.Now.AddDays(1)) || (txtDirEntrega.Text.Trim() == "") || (txtDirFactura.Text.Trim() == "")) { lblValidar.Visible = true; e.Cancel = true; } else //Guardando Pedido { using (dbLQDataContext db = new dbLQDataContext()) { pedido nuevo_pedido = new pedido { idusuario = HttpContext.Current.User.Identity.Name, fecha = DateTime.Now, fecha_entrega = dtpCalendario.SelectedDate, dir_entrega = txtDirEntrega.Text.Trim(), dir_factura = txtDirFactura.Text.Trim(), subtotal = precioTotal, iva = precioTotal * decimal.Parse("0.13"), total = precioTotal * decimal.Parse("0.13") + precioTotal }; List <ListaCompras> listado = (List <ListaCompras>)Session["ListaCompras"]; foreach (ListaCompras item in listado) { pedido_detalle cupcake = new pedido_detalle { iddiseno = item.iddiseno, cantidad = item.cantidad, precio = item.precio, }; nuevo_pedido.pedido_detalles.Add(cupcake); } db.pedidos.InsertOnSubmit(nuevo_pedido); try { db.SubmitChanges(); } catch (ChangeConflictException) { db.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues); db.SubmitChanges(); } //Response.Redirect("~/Clientes/Pedidos.aspx"); } } }
public IHttpActionResult Getpedido_detalle(int id) { pedido_detalle pedido_detalle = db.pedido_detalle.Find(id); if (pedido_detalle == null) { return(NotFound()); } return(Ok(pedido_detalle)); }
public ActionResult Guardar(pedido_detalle empresa) { if (ModelState.IsValid) { empresa.guardar(); return(Redirect("~/pedido_detalle")); } else { return(View("~/Views/pedido_detalle/Agregar.cshtml", empresa)); } }
public IHttpActionResult Deletepedido_detalle(int id) { pedido_detalle pedido_detalle = db.pedido_detalle.Find(id); if (pedido_detalle == null) { return(NotFound()); } db.pedido_detalle.Remove(pedido_detalle); db.SaveChanges(); return(Ok(pedido_detalle)); }
public static void guardarFactura(TextBox tbClien, DateTimePicker dtFecha, ComboBox cbTipo, TextBox tbDirec, TextBox tbTel, TextBox tbDni, DataGridView dgvFact, Label idnum, decimal total, int idclien, int idUser) { int idTipo = Convert.ToInt32(cbTipo.SelectedIndex); DateTime datt = dtFecha.Value; string s = Convert.ToString(datt); using (GestionVentasEntities db_c = new GestionVentasEntities()) { factura_cabecera oFac = new factura_cabecera(); oFac.idcliente = idclien; oFac.idusuario = idUser; oFac.idtipoventa = idTipo; oFac.fecha = dtFecha.Value; oFac.total = total; oFac.estado = 1; db_c.factura_cabecera.Add(oFac); db_c.SaveChanges(); foreach (DataGridViewRow row in dgvFact.Rows) { using (GestionVentasEntities db_d = new GestionVentasEntities()) { pedido_detalle oPed = new pedido_detalle(); oPed.idproducto = Convert.ToInt32(row.Cells[0].Value.ToString()); oPed.peso = Convert.ToDecimal(row.Cells[2].Value.ToString()); oPed.cantidad = Convert.ToDecimal(row.Cells[3].Value.ToString()); using (GestionVentasEntities db_p = new GestionVentasEntities()) { int id = Convert.ToInt32(row.Cells[0].Value.ToString()); producto oProd = db_p.producto.FirstOrDefault(x => x.idproducto == id); oProd.stock = oProd.stock - oPed.cantidad; db_p.SaveChanges(); } oPed.descuento = Convert.ToDecimal(row.Cells[6].Value.ToString()); oPed.subtotal = Convert.ToDecimal(row.Cells[7].Value.ToString()); oPed.idfactura = oFac.idfactura; db_d.pedido_detalle.Add(oPed); db_d.SaveChanges(); } } } MessageBox.Show("Factura guardada", "Aceptar", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public void GuardarPedido(int xiPedido, DateTime xdFechaEntrega, string xsEstado, int xiCliente, string xsUsuario, decimal xdTotal, decimal xdFacturado, List <Pedido> xoProductos, string xsAplicaDesc, decimal xdDescuento, int?xiVuelta, out string xsError) { xsError = ""; int xiIdPedido = 0; using (BD_Entities xoDB = new BD_Entities()) { try { var xoPedido = xoDB.pedido.Find(xiPedido); if (xoPedido != null) { if (xoPedido.ped_estado.Trim().Equals("E") && DateTime.Today > xdFechaEntrega && xsEstado.Equals("C")) { xsError = "Si el pedido pasa a estado CARGADO, la fecha de entrega no puede ser menor a " + DateTime.Today.ToString("dd/MM/yyy"); } else { //Actualizamos el pedido xoPedido.ped_cliente = xiCliente; xoPedido.ped_monto = Math.Round(xdTotal); xoPedido.ped_factu = Math.Round(xdFacturado); xoPedido.ped_estado = xsEstado; xoPedido.ped_repartidor = xsUsuario; xoPedido.ped_fecha = xdFechaEntrega; xoPedido.ped_apdes = xsAplicaDesc; xoPedido.ped_descu = xdDescuento; xoPedido.ped_vuelta = (byte?)xiVuelta; //Borramos todos los items del pedido var items = xoDB.pedido_detalle.Where(x => x.det_pedido == xiPedido).ToList(); xoDB.pedido_detalle.RemoveRange(items); xoDB.SaveChanges(); } } else { //Primero guardamos la cabecera del pedido var xoCabeceraPedido = new pedido() { ped_cliente = xiCliente, ped_fecha = xdFechaEntrega, ped_fechaCarga = DateTime.Now, ped_monto = Math.Round(xdTotal), ped_factu = Math.Round(xdFacturado), ped_estado = "C", ped_repartidor = xsUsuario, ped_apdes = xsAplicaDesc, ped_descu = xdDescuento, ped_vuelta = (byte?)xiVuelta }; xoDB.pedido.Add(xoCabeceraPedido); xoDB.SaveChanges(); //Obtenemos el identity de la cabecera xiIdPedido = xoCabeceraPedido.ped_id; } if (xsError == "") { //Para cada producto guardamos el detalle foreach (var item in xoProductos) { var xoPedidoDetalle = new pedido_detalle() { det_pedido = xoPedido != null ? xiPedido : xiIdPedido, det_producto = item.IdProducto, det_cantidad = item.Cantidad, det_precio = Math.Round(item.Precio, 0), det_monto = Math.Round(item.Monto, 0) }; xoDB.pedido_detalle.Add(xoPedidoDetalle); } xoDB.SaveChanges(); } } catch (Exception ex) { xsError = ex.Message; } } }