public Response Crear(ProductoCategoriaRequest request) { ProductoCategoria categoria = this._unitOfWork.CategoriaRepository .FindBy(categoria => categoria.Nombre == request.NombreCategoria, includeProperties: "SubCategorias").FirstOrDefault(); if (categoria != null) { return(new Response { Mensaje = "La categoria ya se encuentra registrada" }); } categoria = new ProductoCategoria(); categoria.Nombre = request.NombreCategoria; this._unitOfWork.CategoriaRepository.Add(categoria); this._unitOfWork.Commit(); return(new Response { Mensaje = $"Se ha registrado la categoria {categoria.Nombre} con éxito", Data = new ProductoCategoriaRequest().Map(categoria) }); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ProductoId,CategoriaId")] ProductoCategoria productoCategoria) { if (id != productoCategoria.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _productoCategoriasService.EditProductoCategoriaPost(productoCategoria); } catch (DbUpdateConcurrencyException) { if (!ProductoCategoriaExists(productoCategoria.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoriaId"] = new SelectList(await _categoriasService.GetCategorias(), "Id", "Id", productoCategoria.CategoriaId); ViewData["ProductoId"] = new SelectList(await _productosService.GetProductos(), "Id", "Descripcion", productoCategoria.ProductoId); return(View(productoCategoria)); }
public async Task <IActionResult> Create([Bind("Id,ProductoId,CategoriaId")] ProductoCategoria productoCategoria) { if (ModelState.IsValid) { await _productoCategoriasService.CreateProductoCategoriaPost(productoCategoria); return(RedirectToAction(nameof(Index))); } ViewData["CategoriaId"] = new SelectList(await _categoriasService.GetCategorias(), "Id", "Id", productoCategoria.CategoriaId); ViewData["ProductoId"] = new SelectList(await _productosService.GetProductos(), "Id", "Descripcion", productoCategoria.ProductoId); return(View(productoCategoria)); }
// GET: ProductoCategorias/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } ProductoCategoria productoCategoria = await _productoCategoriasService.GetProductoCategoriaById(id); if (productoCategoria == null) { return(NotFound()); } return(View(productoCategoria)); }
// GET: ProductoCategorias/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } ProductoCategoria productoCategoria = await _productoCategoriasService.EditProductoCategoriaGet(id); if (productoCategoria == null) { return(NotFound()); } ViewData["CategoriaId"] = new SelectList(await _categoriasService.GetCategorias(), "Id", "Id", productoCategoria.CategoriaId); ViewData["ProductoId"] = new SelectList(await _productosService.GetProductos(), "Id", "Descripcion", productoCategoria.ProductoId); return(View(productoCategoria)); }
public Response Agregar(ProductoSubCategoriaRequest request) { ProductoCategoria categoria = this._unitOfWork.CategoriaRepository .FindBy(categoria => categoria.Id == request.IdCategoria, includeProperties: "SubCategorias").FirstOrDefault(); if (categoria == null) { return(new Response { Mensaje = "La categoria no fue encontrada" }); } ProductoSubCategoria subCategoria = categoria.SubCategorias .FirstOrDefault(subCategoria => subCategoria.Nombre == request.NombreSubCategoria); if (subCategoria != null) { return(new Response { Mensaje = $"La subcategoria {request.NombreSubCategoria} ya " + $"se encuentra registrada" }); } subCategoria = new ProductoSubCategoria .ProductoSubCategoriaBuilder(request.NombreSubCategoria).Build(); categoria.SubCategorias.Add(subCategoria); this._unitOfWork.CategoriaRepository.Edit(categoria); this._unitOfWork.Commit(); return(new Response { Mensaje = "Subcategoria registrada con éxito", Data = new ProductoCategoriaRequest().Map(categoria) }); }
public async Task EditProductoCategoriaPost(ProductoCategoria productoCategoria) { _context.Update(productoCategoria); await _context.SaveChangesAsync(); }
public async Task CreateProductoCategoriaPost(ProductoCategoria productoCategoria) { _context.Add(productoCategoria); await _context.SaveChangesAsync(); }
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)); }