public static ML.Result AddImagen(ML.Producto producto) { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities contex = new DL_EF.EcommerceRubenEntities()) { var Add = contex.ProductoAddImagen (producto.Nombre, producto.Descripcion, producto.PaisOrigen, producto.Precio , producto.SubCategoria.IdSubcategoria, Convert.ToBase64String(producto.LogoTipo), producto.Stock); if (Add > 0) { result.Correct = true; } else { result.Correct = false; } } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result DeleteEF(ML.Producto producto) { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities()) { var query = context.ProductoDelete(producto.IdProducto); if (query >= 1) { result.Correct = true; } else { result.Correct = false; result.ErrorMessage = "No se eliminó el registro"; } result.Correct = true; } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result Alta(int IdProducto, bool Status) { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities()) { var updateResult = context.ProductoAlta(IdProducto, Status); if (updateResult >= 1) { result.Correct = true; result.ErrorMessage = "Se actualizo correctamente el status del producto"; } else { result.Correct = false; result.ErrorMessage = "No se actualizaron los datos del producto"; } } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result UpdateEF(ML.Producto producto) { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities()) { var updateResult = context.ProductoUpdate(producto.IdProducto, producto.Nombre, producto.Descripcion, producto.PaisOrigen, producto.Precio, producto.SubCategoria.IdSubcategoria, Convert.ToBase64String(producto.LogoTipo), producto.Stock); if (updateResult >= 1) { result.Correct = true; } else { result.Correct = false; result.ErrorMessage = "No se actualizó el status de la credencial"; } } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result GetByIdEF(ML.Producto productos) { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities()) { var alumnos = context.ProductoGetById(productos.IdProducto).FirstOrDefault(); if (alumnos != null) { ML.DetalleVenta detalle = new ML.DetalleVenta(); ML.Producto producto = new ML.Producto(); producto.IdProducto = alumnos.IdProducto; producto.Nombre = alumnos.NombreProducto; producto.Descripcion = alumnos.Descripcion; producto.PaisOrigen = alumnos.PaisOrigen; producto.Precio = alumnos.Precio; producto.Stock = Convert.ToInt32(alumnos.Stock); producto.SubCategoria = new ML.SubCategoria(); producto.SubCategoria.IdSubcategoria = alumnos.IdSubCategori; producto.SubCategoria.Categoria = new ML.Categoria(); producto.SubCategoria.Categoria.IdCategoria = alumnos.IdCategoria; producto.LogoTipo = Convert.FromBase64String(alumnos.Imagen); producto.DetalleVenta = new ML.DetalleVenta(); producto.DetalleVenta.Cantidad = 1; producto.DetalleVenta.Venta = new ML.Venta(); producto.DetalleVenta.Venta.Total = Convert.ToInt32(producto.Precio * producto.DetalleVenta.Cantidad); //producto.DetalleVenta.Venta.Total = alumnos.Precio; result.Object = producto; result.Correct = true; } else { result.Correct = false; result.ErrorMessage = "No se encontraron registros."; } } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result Get() { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities()) { var query = context.ProductoGetAllInnerJoin2().ToList(); result.Objects = new List <object>(); if (query != null) { foreach (var obj in query) { ML.Producto producto = new ML.Producto(); producto.IdProducto = obj.IdProducto; producto.Nombre = obj.Nombre; producto.Descripcion = obj.Descripcion; producto.PaisOrigen = obj.PaisOrigen; producto.Precio = obj.Precio; producto.SubCategoria = new ML.SubCategoria(); producto.SubCategoria.Nombre = obj.NombreCategoria; producto.LogoTipo = Convert.FromBase64String(obj.Imagen); producto.Stock = Convert.ToInt32(obj.Stock); result.Objects.Add(producto); } result.Correct = true; } else { result.Correct = false; result.ErrorMessage = "No se encontraron registros."; } } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result GetByIdEF(ML.DetalleVenta detalle) { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities()) { var alumnos = context.DetalleVentaGetAllInner().FirstOrDefault(); if (alumnos != null) { ML.DetalleVenta detalles = new ML.DetalleVenta(); ML.Producto producto = new ML.Producto(); detalles.Producto.IdProducto = alumnos.IdProducto; detalles.Producto.Nombre = alumnos.Nombre; detalles.Producto.Precio = alumnos.Precio; detalles.Producto.LogoTipo = Convert.FromBase64String(alumnos.Imagen); result.Object = producto; /*foreach (var obj in alumnos) * { * * }*/ result.Correct = true; } else { result.Correct = false; result.ErrorMessage = "No se encontraron registros."; } } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result Add(int IdVenta, int IdProducto, int Cantidad) { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities()) { var query = context.DetalleVentaAdd(IdVenta, IdProducto, Cantidad); var query2 = context.ProductoStock(IdProducto, Cantidad); if (query >= 1) { result.Correct = true; } else { result.Correct = false; } } //using (SqlConnection context = new SqlConnection(DL.Conexion.GetConnectionString())) //{ // string Query = "Insert into DetallePedido values (@IdProducto,@IdPedido,@cantidad)"; // SqlCommand cmd = DL.Conexion.CreateCommand(Query, context); // cmd.Parameters.AddWithValue("@IdPedido", IdVenta); // cmd.Parameters.AddWithValue("@IdProducto", IdProducto); // cmd.Parameters.AddWithValue("@Cantidad", Cantidad); // int RowsAffected = DL.Conexion.ExecuteCommand(cmd); // if (RowsAffected >= 1) // { // result.Correct = true; // } // else // { // result.Correct = false; // result.ErrorMessage = "No se inserto correctamente"; // } //} } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result GetByIdCategoria(ML.SubCategoria subCategoria) { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities()) { //var IdResult = new ObjectParameter("IdSubCategoria", typeof(int)); var Query = context.SubCategoriaGetByIdCategoria(subCategoria.Categoria.IdCategoria); result.Objects = new List <object>(); if (Query != null) { foreach (var obj in Query) { ML.SubCategoria alumno = new ML.SubCategoria(); alumno.IdSubcategoria = obj.IdSubCategoria; alumno.Nombre = obj.Nombre; alumno.Categoria = new ML.Categoria(); alumno.Categoria.IdCategoria = obj.IdCategoria; result.Objects.Add(alumno); } result.Correct = true; } else { result.Correct = false; result.ErrorMessage = "No se encontraron registros."; } } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result GetAll() { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities contex = new DL_EF.EcommerceRubenEntities()) { var query = contex.VentasGetAll().ToList(); result.Objects = new List <object>(); if (query != null) { foreach (var obj in query) { ML.DetalleVenta detalle = new ML.DetalleVenta(); detalle.Venta = new ML.Venta(); detalle.Producto = new ML.Producto(); detalle.Venta.Cliente = new ML.Cliente(); detalle.Venta.Cliente.Nombre = obj.NombreCliente; detalle.Producto.IdProducto = obj.IdProducto; detalle.Producto.Nombre = obj.NombreProducto; detalle.Producto.Descripcion = obj.Descripcion; detalle.Producto.Precio = obj.Precio; detalle.Venta.IdVenta = obj.IdVenta; detalle.Venta.Fecha = Convert.ToDateTime(obj.Fecha); detalle.Venta.Total = Convert.ToInt32(obj.Total); detalle.Cantidad = Convert.ToInt32(obj.Cantidad); result.Objects.Add(detalle); } result.Correct = true; } else { result.Correct = false; } } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result GetAllEF() { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities()) { var query = context.SubCategoriaGetAll().ToList(); result.Objects = new List <object>(); if (query != null) { foreach (var obj in query) { ML.SubCategoria alumno = new ML.SubCategoria(); alumno.IdSubcategoria = obj.IdSubCategoria; alumno.Nombre = obj.Nombre; alumno.Categoria = new ML.Categoria(); alumno.Categoria.IdCategoria = obj.IdCategoria; result.Objects.Add(alumno); } result.Correct = true; } else { result.Correct = false; result.ErrorMessage = "No se encontraron registros."; } } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }
public static ML.Result AddEF(ML.Venta venta, List <Object> Objects) { ML.Result result = new ML.Result(); try { using (DL_EF.EcommerceRubenEntities context = new DL_EF.EcommerceRubenEntities()) { //var query = context.VentaAddSP(venta.Total, venta.Cliente.IdCliente); var IdResult = new ObjectParameter("IdVenta", typeof(int)); int ventas = context.VentaAddSP(IdResult, venta.Total, venta.Cliente.IdCliente); venta.IdVenta = (int)IdResult.Value; //int IdUsuario = Convert.ToInt32(venta.Cliente.IdCliente); //double Total = Convert.ToDouble(venta.Total); ////int Ventas = 1; //var IdResult = new ObjectParameter("IdVenta", typeof(int)); //int IdVenta = Convert.ToInt32(context.VentaAddSP(IdResult, venta.Total, venta.Cliente.IdCliente)); Console.WriteLine("El IdVenta es: " + venta.IdVenta); /* foreach (ML.DetalleVenta detalleVenta in Objects) * { * detalleVenta.Venta = venta; * * BL.DetalleVenta.AddEF(detalleVenta); * * }*/ foreach (ML.Producto productoItem in Objects) { BL.DetalleVenta.Add(venta.IdVenta, productoItem.IdProducto, productoItem.DetalleVenta.Cantidad); } result.Object = venta.IdVenta; if (venta.IdVenta >= 1) { result.Correct = true; } else { result.Correct = false; result.ErrorMessage = "No se insertó el registro"; } result.Correct = true; } } catch (Exception ex) { result.Correct = false; result.ErrorMessage = ex.Message; } return(result); }