public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var opcionProducto = await _opcionesProductosService.GetOpcionProductoById(id);

            if (opcionProducto == null)
            {
                return(NotFound());
            }

            return(View(opcionProducto));
        }
예제 #2
0
        public async Task <ActionResult> GetProductoDetallesById(int id)
        {
            ProductoDetallesVM productoDetalles = new ProductoDetallesVM();

            productoDetalles.producto = await _productosService.GetProductoById(id);

            if (productoDetalles.producto == null)
            {
                return(NotFound(new string[] { "No hay producto", "Consultar la documentación" }));
            }

            productoDetalles.vendedor = await _vendedoresService.ObtenerVendedorDesdeProducto(id);

            productoDetalles.opcionesProducto = await _opcionesProductosService.GetOpcionProductoById(id);

            productoDetalles.reviews = await _reviewsService.ObtenerReviewsByProductoId(id);

            productoDetalles.valoracionMedia = await _reviewsService.ObtenerValoracionMediaByProductoId(id);

            productoDetalles.totalComentarios = _reviewsService.CantidadComentariosByReviewList(productoDetalles.reviews);
            var categoria = await _categoriaService.GetCategoriaByProductoId(id);

            //var productoDetallesVMReadDTO = _mapper.Map<ProductoDetallesVMReadDTO>(productoDetalles);

            var productoDTO = new {
                id                = productoDetalles.producto.Id,
                titulo            = productoDetalles.producto.Titulo,
                descripcion       = productoDetalles.producto.Descripcion,
                fechaValidez      = productoDetalles.producto.FechaValidez,
                fechaAltaProducto = productoDetalles.producto.FechaAltaProducto,
                estado            = productoDetalles.producto.Estado,
                cantidadVisitas   = productoDetalles.producto.CantidadVisitas,
                condiciones       = productoDetalles.producto.Condiciones,
                categoria         = new { id = categoria.Id, nombre = categoria.Nombre },
                opcionProducto    = _mapper.Map <IEnumerable <OpcionProductoReadDTO> >(productoDetalles.opcionesProducto),
                vendedor          = new {
                    id                 = productoDetalles.vendedor.Id,
                    nombreEmpresa      = productoDetalles.vendedor.NombreDeEmpresa,
                    telefono           = productoDetalles.vendedor.Telefono,
                    paginaWeb          = productoDetalles.vendedor.Paginaweb,
                    cif                = productoDetalles.vendedor.CIF,
                    descripcionEmpresa = productoDetalles.vendedor.DescripcionEmpresa
                }
            };

            return(Ok(productoDTO));
        }
예제 #3
0
        public async Task <IActionResult> Detalles(int?id)
        {
            ProductoDetallesVM productoDetalles = new ProductoDetallesVM();

            if (id == null)
            {
                return(NotFound());
            }

            productoDetalles.producto = await _productosService.GetProductoById(id);

            if (productoDetalles.producto == null)
            {
                return(NotFound());
            }

            if (User.IsInRole("cliente"))
            {
                //Genero una nueva transacción con los datos del usuario, el producto y el vendedor
                Usuario usuario = await _usuariosService.GetUsuarioByActiveIdentityUser(_userManager.GetUserId(User));

                ProductoVendedor productoVendedor = await _productosVendedoresService.ProductoVendedorByProductoId(id);

                await _VisitasService.CreateVisitaWithUsuarioAndProductoVendedor(usuario, productoVendedor);

                ViewData["Usuario"] = usuario;
            }

            //Modifico el producto actual agregando una unidad a la columa "CantidadVisitas" de la tabla
            await _productosService.AddCantidadVisitasProductoById(id);

            //ViewModel a pasar a la vista
            productoDetalles.vendedor = await _vendedoresService.ObtenerVendedorDesdeProducto(id);

            productoDetalles.opcionesProducto = await _opcionesProductosService.GetOpcionProductoById(id);

            productoDetalles.reviews = await _reviewsService.ObtenerReviewsByProductoId(id);

            productoDetalles.valoracionMedia = await _reviewsService.ObtenerValoracionMediaByProductoId(id);

            productoDetalles.totalComentarios = _reviewsService.CantidadComentariosByReviewList(productoDetalles.reviews);

            return(View(productoDetalles));
        }
예제 #4
0
        public async Task <IActionResult> Confirmar(int?id, int opcionElegida)
        {
            Usuario usuario = await _usuariosService.GetUsuarioByActiveIdentityUser(_userManager.GetUserId(User));

            Producto producto = await _productosService.GetProductoById(id);

            List <OpcionProducto> opciones = await _opcionesProductosService.GetOpcionProductoById(id);

            OpcionProducto   opcion           = opciones[opcionElegida - 1];
            ProductoVendedor productoVendedor = producto.ProductoVendedor[0];
            Vendedor         vendedor         = await _vendedoresService.GetVendedorById(productoVendedor.VendedorId);

            UsuarioProductoVM modelo = new UsuarioProductoVM
            {
                producto = producto,
                usuario  = usuario,
                opcion   = opcion
            };
            int   precioFinal = Convert.ToInt32(opcion.PrecioFinal * 100);
            float fee         = vendedor.Fee;
            int   helduFee    = Convert.ToInt32(precioFinal * (fee / 100));

            StripeConfiguration.ApiKey = "sk_test_51GvJEQL9UURBAADxXJtmn6ZmPepnp0Bkt4Hwl3y53I7rjWCQKa4wj3FSfkm2V4ZOIV67I6LQDmfvPmZ16eMh9LcE0057FViwnl";

            var service       = new PaymentIntentService();
            var createOptions = new PaymentIntentCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                Amount               = precioFinal,
                Currency             = "eur",
                ApplicationFeeAmount = helduFee,
                ReceiptEmail         = "*****@*****.**",

                Metadata = new Dictionary <string, string>
                {
                    { "ProductoId", Convert.ToString(producto.Id) },
                    { "Producto", producto.Titulo },
                    { "OpcionId", opcion.Id.ToString() },
                    { "Opcion", opcion.Descripcion },
                    { "PrecioOriginal", opcion.PrecioInicial.ToString() },
                    { "UsuarioId", Convert.ToString(usuario.Id) },
                    { "Usuario", usuario.NombreUsuario },
                    { "VendedorId", vendedor.Id.ToString() },
                    { "Vendedor", vendedor.NombreDeEmpresa }
                },
                TransferData = new PaymentIntentTransferDataOptions()
                {
                    Destination = "acct_1H08zjLhTBm3kv5q"
                },
                //TransferData = new PaymentIntentTransferDataOptions
                //{
                //     Destination = "acct_1H08zjLhTBm3kv5q",
                //},
            };
            var intent = service.Create(createOptions);

            ViewData["ClientSecret"] = intent.ClientSecret;

            return(View(modelo));
        }