public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } Producto producto = await _productosService.GetProductoById(id); if (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); } //Modifico el producto actual agregando una unidad a la columa "CantidadVisitas" de la tabla await _productosService.AddCantidadVisitasProductoById(id); return(View(producto)); }
public async Task DeleteProductoVendedorPost(int id) { ProductoVendedor productoVendedor = await _context.ProductoVendedor.FindAsync(id); _context.ProductoVendedor.Remove(productoVendedor); await _context.SaveChangesAsync(); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ProductoId,VendedorId")] ProductoVendedor productoVendedor) { if (id != productoVendedor.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _productosVendedoresService.EditProductoVendedorPost(productoVendedor); } catch (DbUpdateConcurrencyException) { if (!ProductoVendedorExists(productoVendedor.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } //ViewData["ProductoId"] = new SelectList(_context.Producto, "Id", "Descripcion", productoVendedor.ProductoId); //ViewData["VendedorId"] = new SelectList(_context.Set<Vendedor>(), "Id", "NombreDeEmpresa", productoVendedor.VendedorId); return(View(productoVendedor)); }
// Devuelve el objeto vendedor pasándole el Id del producto public async Task <Vendedor> ObtenerVendedorDesdeProducto(int?Id) { ProductoVendedor productoVendedor = await _context.ProductoVendedor .Include(v => v.Vendedor) .FirstOrDefaultAsync(x => x.ProductoId == Id); return(productoVendedor.Vendedor); }
public async Task <IActionResult> Create([Bind("Id,ProductoId,VendedorId")] ProductoVendedor productoVendedor) { if (ModelState.IsValid) { await _productosVendedoresService.CreateProductoVendedor(productoVendedor); return(RedirectToAction(nameof(Index))); } //ViewData["ProductoId"] = new SelectList(_context.Producto, "Id", "Descripcion", productoVendedor.ProductoId); //ViewData["VendedorId"] = new SelectList(_context.Set<Vendedor>(), "Id", "NombreDeEmpresa", productoVendedor.VendedorId); return(View(productoVendedor)); }
// GET: ProductoVendedores/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } ProductoVendedor productoVendedor = await _productosVendedoresService.GetProductoVendedorById(id); if (productoVendedor == null) { return(NotFound()); } return(View(productoVendedor)); }
// GET: ProductoVendedores/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } ProductoVendedor productoVendedor = await _productosVendedoresService.EditProductoVendedorGet(id); if (productoVendedor == null) { return(NotFound()); } //ViewData["ProductoId"] = new SelectList(_context.Producto, "Id", "Descripcion", productoVendedor.ProductoId); //ViewData["VendedorId"] = new SelectList(_context.Set<Vendedor>(), "Id", "NombreDeEmpresa", productoVendedor.VendedorId); return(View(productoVendedor)); }
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)); }
public async Task EditProductoVendedorPost(ProductoVendedor productoVendedor) { _context.Update(productoVendedor); await _context.SaveChangesAsync(); }
public async Task CreateProductoVendedor(ProductoVendedor productoVendedor) { _context.Add(productoVendedor); await _context.SaveChangesAsync(); }
public async Task CreateVisitaWithUsuarioAndProductoVendedor(Usuario usuario, ProductoVendedor productoVendedor) { Visita Visita = new Visita() { UsuarioId = usuario.Id, ProductoId = productoVendedor.ProductoId, VendedorId = productoVendedor.VendedorId, Unidades = 0, FechaVisita = DateTime.Today, }; await CreateVisita(Visita); }
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)); }
public async Task <IActionResult> Create(ProductoCategoriaVM productoCategoriaVM, int?idVendedor, List <IFormFile> Imagen1, List <IFormFile> Imagen2, List <IFormFile> Imagen3) { Producto producto = new Producto() { Titulo = productoCategoriaVM.Producto.Titulo, Descripcion = productoCategoriaVM.Producto.Descripcion, Condiciones = productoCategoriaVM.Producto.Condiciones, FechaValidez = productoCategoriaVM.Producto.FechaValidez }; await _productosService.CreateProductoPost(producto); var img1 = await _imagenesProductosService.AgregarImagenesBlob(Imagen1); var img2 = await _imagenesProductosService.AgregarImagenesBlob(Imagen2); var img3 = await _imagenesProductosService.AgregarImagenesBlob(Imagen3); ImagenesProducto imagenes = new ImagenesProducto() { Imagen1 = img1, Imagen2 = img2, Imagen3 = img3, ProductoId = producto.Id }; ProductoCategoria newProdCat = new ProductoCategoria() { CategoriaId = productoCategoriaVM.Categoria.Id, ProductoId = producto.Id }; ProductoVendedor productoVendedor = new ProductoVendedor(); productoVendedor.ProductoId = producto.Id; int aux = -1; if (idVendedor == null) { string idUsuario = _userManager.GetUserId(User); Vendedor vendedor = await _vendedoresService.GetVendedorByIdentityUserId(idUsuario); aux = vendedor.Id; } else if (idVendedor != null) { string aux2 = idVendedor.ToString(); aux = int.Parse(aux2); } productoVendedor.VendedorId = aux; if (ModelState.IsValid) { await _imagenesProductosService.CreateImagenesProducto(imagenes); await _productosVendedoresService.CreateProductoVendedor(productoVendedor); await _productoCategoriasService.CreateProductoCategoriaPost(newProdCat); return(RedirectToAction("Create", "OpcionesProductos", new { productoId = producto.Id })); } _memoryCache.Remove("ProductosForIndex2"); return(View(producto)); }