public async Task <IActionResult> PutDetalle_Pedido(int id, Detalle_Pedido detalle_Pedido) { if (id != detalle_Pedido.ID) { return(BadRequest()); } _context.Entry(detalle_Pedido).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Detalle_PedidoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDetalle_Pedido([FromRoute] int id, [FromBody] Detalle_Pedido detalle_Pedido) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != detalle_Pedido.Codigo_Pedido) { return(BadRequest()); } _context.Entry(detalle_Pedido).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Detalle_PedidoExists(id)) { return(NotFound()); } else { throw; } } return(Ok(detalle_Pedido)); }
public async Task <ActionResult <Detalle_Pedido> > PostDetalle_Pedido(Detalle_Pedido detalle_Pedido) { _context.Detalle_Pedidos.Add(detalle_Pedido); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDetalle_Pedido", new { id = detalle_Pedido.ID }, detalle_Pedido)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,CarritoProductoID,CarritoUsuarioID,CarritoID,PedidoID")] Detalle_Pedido detalle_Pedido) { if (id != detalle_Pedido.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(detalle_Pedido); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Detalle_PedidoExists(detalle_Pedido.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CarritoID"] = new SelectList(_context.Carritos, "ID", "ID", detalle_Pedido.CarritoID); ViewData["PedidoID"] = new SelectList(_context.Pedidos, "ID", "ID", detalle_Pedido.PedidoID); return(View(detalle_Pedido)); }
/// <summary> /// Realiza el proceso de insertar el detalle del pedido a las bases de datos /// una vez que el usuario se encuentre registrado y con sesión activa /// de lo contrario será redireccionado al inicio de sesión /// </summary> /// <param name="id">Identificador del pedido que se está enviando</param> /// <returns></returns> public ActionResult FormalizarCompra(int?id) { //Si el usuario no está logueado no puede continuar con la formalización if (Session["Usuario"] == null) { return(RedirectToAction("InicioClientes", "Usuario")); } else { if (id == null) { TempData["Mensaje"] = "El pedido especificado no está disponible"; return(View("CarritoPrevia")); } //Encontrando el pedido para asociarlo Pedido pedido = Context.Pedido.Find(id); if (pedido == null) { TempData["Mensaje"] = "El pedido no se encuantra reservado"; return(View("CarritoPrevia")); } //Recorriendo el carrito para llenar un detalle por cada producto que se quiere registrar foreach (var item in Session["Carrito"] as List <CarritoItem> ) { Detalle_Pedido detalle_Pedido = new Detalle_Pedido(); detalle_Pedido.idPedido = pedido.idPedido; detalle_Pedido.idProducto = item.Producto.idProducto; detalle_Pedido.cantidad = item.Cantidad; detalle_Pedido.descuento = Convert.ToDecimal(Session["Descuento"]); Context.Detalle_Pedido.Add(detalle_Pedido); } Context.SaveChanges(); //Cambiando el estado del pedido para colocarlo en procesado pedido.estado = true; Context.Entry(pedido).State = System.Data.Entity.EntityState.Modified; Context.SaveChanges(); //Marcando como usado el cupón utilizado en la compra if (Session["Cupones"] != null) { foreach (var item in Session["Cupones"] as List <Cupones> ) { Cupones_Usuario cupones_Usuario = Context.Cupones_Usuarios.Find(item.idCupones, Session["Usuario"]); cupones_Usuario.estado = false; Context.Entry(cupones_Usuario).State = System.Data.Entity.EntityState.Modified; } Context.SaveChanges(); } //Guardando el estado de la compra Session["Compra"] = "Finalizado"; //Eliminando los elementos del carrito Session.Remove("Carrito"); //Mensaje de confirmación TempData["Mensaje"] = "Pedido realizado con éxito, gracias por su compra!"; return(RedirectToAction("MuestraProductos", "Productos")); } }
public async Task <IActionResult> Create([Bind("ID,CarritoProductoID,CarritoUsuarioID,CarritoID,PedidoID")] Detalle_Pedido detalle_Pedido) { if (ModelState.IsValid) { _context.Add(detalle_Pedido); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CarritoID"] = new SelectList(_context.Carritos, "ID", "ID", detalle_Pedido.CarritoID); ViewData["PedidoID"] = new SelectList(_context.Pedidos, "ID", "ID", detalle_Pedido.PedidoID); return(View(detalle_Pedido)); }
public async Task <ActionResult <Detalle_Pedido> > PostDetalle_Pedido(Detalle_Pedido detalle_Pedido) { _context.Detalle_Pedido.Add(detalle_Pedido); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (Detalle_PedidoExists(detalle_Pedido.Codigo_Pedido)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetDetalle_Pedido", new { id = detalle_Pedido.Codigo_Pedido }, detalle_Pedido)); }
public async Task <List <Detalle_Pedido> > GetListaImp(string Accion, int CodPedido, int CodSubLinea, string Estado, string CodigosItem, string NameImpresora = "") { using (SqlConnection sql = new SqlConnection(_ConnectionString)) { using (SqlCommand cmd = new SqlCommand("[dbo].[Sp_Bus_Rest_DetPedido]", sql)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandTimeout = 0; cmd.Parameters.Add(new SqlParameter("@aTipoAccion", Accion)); cmd.Parameters.Add(new SqlParameter("@ePedido", CodPedido)); cmd.Parameters.Add(new SqlParameter("@eSubLinea", CodSubLinea)); cmd.Parameters.Add(new SqlParameter("@aEstado", Estado)); cmd.Parameters.Add(new SqlParameter("@aCodigos", CodigosItem)); cmd.Parameters.Add(new SqlParameter("@aImpresora", NameImpresora)); var response = new List <Detalle_Pedido>(); await sql.OpenAsync(); using (var reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var miDetalle = new Detalle_Pedido(); miDetalle.pedido = reader.IsDBNull(0) ? 0 : reader.GetInt32(0); miDetalle.itemUnidad.CodItem = reader.IsDBNull(1) ? 0 : reader.GetInt32(1); miDetalle.cantidad = reader.IsDBNull(2) ? 0 : Double.Parse(reader.GetDecimal(2).ToString()); miDetalle.precio = reader.IsDBNull(3) ? 0 : Double.Parse(reader.GetDecimal(3).ToString()); miDetalle.estado = reader.IsDBNull(4) ? "" : reader.GetString(4); miDetalle.idFac = reader.IsDBNull(5) ? 0 : reader.GetInt32(5); miDetalle.observacion = reader.IsDBNull(6) ? "" : reader.GetString(6); miDetalle.itemUnidad.ItemNombre = reader.IsDBNull(7) ? "" : reader.GetString(7); miDetalle.itemUnidad.CodBar = reader.IsDBNull(8) ? "" : reader.GetString(8); response.Add(miDetalle); } return(response); } } } }
public async Task <List <Detalle_Pedido> > GetLista(string Accion, int CodPedido, int CodSubLinea = 0) { using (SqlConnection sql = new SqlConnection(_ConnectionString)) { using (SqlCommand cmd = new SqlCommand("[dbo].[Sp_Bus_Rest_DetPedido]", sql)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandTimeout = 0; cmd.Parameters.Add(new SqlParameter("@aTipoAccion", Accion)); cmd.Parameters.Add(new SqlParameter("@ePedido", CodPedido)); cmd.Parameters.Add(new SqlParameter("@eSubLinea", CodSubLinea)); var response = new List <Detalle_Pedido>(); await sql.OpenAsync(); using (var reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var miDetalle = new Detalle_Pedido(); miDetalle.pedido = reader.IsDBNull(0) ? 0 : reader.GetInt32(0); if ((reader.IsDBNull(1) ? 0 : reader.GetInt32(1)) > 0) { miDetalle.itemUnidad = await _reposiItem.BuscarDatos(reader.GetInt32(1).ToString(), "V", 1, 1, 1, 2, false, 1, 1); } miDetalle.cantidad = reader.IsDBNull(2) ? 0 : Double.Parse(reader.GetDecimal(2).ToString()); miDetalle.precio = reader.IsDBNull(3) ? 0 : Double.Parse(reader.GetDecimal(3).ToString()); miDetalle.estado = reader.IsDBNull(4)? "": reader.GetString(4); miDetalle.idFac = reader.IsDBNull(5) ? 0 : reader.GetInt32(5); miDetalle.observacion = reader.IsDBNull(6) ? "" : reader.GetString(6); response.Add(miDetalle); } return(response); } } } }
public ActionResult FinalizarCompra(string direc, string desc) { List <CarritoItem> compras = (List <CarritoItem>)Session["carrito"]; if (compras != null && compras.Count > 0) { for (int i = 0; i < compras.Count; i++) { Detalle_Venta dventa = new Detalle_Venta(); var maxDetalle = (from g in db.Detalle_Venta select g.Codigo_Detalle).Max(); int maxDetallei = Convert.ToInt32(maxDetalle); dventa.Codigo_Detalle = maxDetallei + 1; dventa.Monto_Total = compras.Sum(x => x.Producto.Precio_Unitario * x.Cantidad); dventa.Descripcion = ClaseCompartida.tipoCliente.ToString(); Venta nuevaVenta = new Venta(); //Sacar el maximo de nuestra tabla Venta var maxVenta = (from g in db.Venta select g.Codigo_Venta).Max(); int maxVentai = Convert.ToInt32(maxVenta); nuevaVenta.Codigo_Venta = maxVentai + 1;// Codigo Venta nuevaVenta.Codigo_Cliente = 10; nuevaVenta.Id_Personas = 1; nuevaVenta.Codigo_Producto = ClaseCompartida.tipoCliente; //nuevaVenta.Detalle_Venta = (from detalle in compras // select new Detalle_Venta // { // Codigo_Detalle = maxDetallei + 1, // Monto_Total = Convert.ToDouble(detalle.Cantidad * detalle.Producto.Precio_Unitario), // Descripcion = detalle.Producto.Nombre_Producto // }); nuevaVenta.Codigo_Detalle_Venta = maxDetallei + 1; nuevaVenta.Cantidad = compras.Sum(x => x.Cantidad); nuevaVenta.Fecha_Venta = DateTime.Now; nuevaVenta.Tipo_Venta = "Linea"; Ubicacion_Pedido ubicacion = new Ubicacion_Pedido(); var maxUbicacion = (from g in db.Ubicacion_Pedido select g.Codigo_Ubicacion).Max(); int maxUbicacion1 = Convert.ToInt32(maxUbicacion); ubicacion.Codigo_Ubicacion = maxUbicacion1 + 1; ubicacion.Descripcion = direc + ", " + desc; Detalle_Pedido detalle_Pedido = new Detalle_Pedido(); var max = (from g in db.Detalle_Pedido select g.Codigo_Detalle).Max(); int maxDP1 = Convert.ToInt32(max); detalle_Pedido.Codigo_Detalle = maxDP1 + 1; detalle_Pedido.Estado_Pedido = "Por entregar"; detalle_Pedido.Subtotal = compras.Sum(x => x.Producto.Precio_Unitario * x.Cantidad); Comprobante comprobante = new Comprobante(); var maxComprobante = (from g in db.Comprobante select g.Numero_Comprobante).Max(); int maxComprobante1 = Convert.ToInt32(maxComprobante); comprobante.Numero_Comprobante = maxComprobante1 + 1; comprobante.Fecha_Emision = DateTime.Now; comprobante.Estado = "En camino"; comprobante.Detalle = "Compra satisfactoria"; pedido pedido = new pedido(); var maxPedido = (from g in db.pedido select g.Codigo_Pedido).Max(); int maxPedido1 = Convert.ToInt32(maxPedido); pedido.Codigo_Pedido = maxPedido + 1; pedido.Fecha_Hora_Pedido = DateTime.Now; pedido.Fecha_Hora_Entrega = DateTime.Now; pedido.Codigo_Direccion_Pedido = maxUbicacion1 + 1; pedido.Codigo_Personas = 1; pedido.Codigo_Detalle_Pedido = maxDP1 + 1; pedido.Codigo_Cliente = 4; pedido.Codigo_Venta = maxVentai + 1; pedido.Numero_Comprobante = maxComprobante1 + 1; db.Detalle_Venta.Add(dventa); db.Venta.Add(nuevaVenta); db.Ubicacion_Pedido.Add(ubicacion); db.Detalle_Pedido.Add(detalle_Pedido); db.Comprobante.Add(comprobante); db.pedido.Add(pedido); db.SaveChanges(); Session["carrito"] = new List <CarritoItem>(); } } return(View()); }