public ActionResult <int> UploadByte() { var imagenProducto = new ImagenProducto(); try { var file = Request.Form.Files[0]; if (file.Length > 0) { using (var memoryStream = new MemoryStream()) { file.CopyTo(memoryStream); imagenProducto.Imagen = memoryStream.ToArray(); } var response = _ImagenProductoServicio.Guardar(imagenProducto); if (response.Error) { return(BadRequest(response.Mensaje)); } return(Ok(response.ID)); } else { return(BadRequest()); } } catch { return(StatusCode(500, "Internal server error")); } }
public List <ImagenProducto> listarImagenesPorProducto(Producto producto) { try { List <ImagenProducto> listaImagenProducto = new List <ImagenProducto>(); ImagenProducto ImagenProducto = null; string consultaSQL = "select img.codigoimagenproducto,img.direccionimagenproducto, img.nombreimagenproducto, img.principalimagenproducto from imagenproducto img where img.codigoproducto = @codigoProducto "; SqlCommand sentencia; SqlDataReader resultado; sentencia = gestorODBC.prepararSentencia(consultaSQL); sentencia.Parameters.Add("@codigoProducto", Int).Value = producto.codigoProducto; resultado = sentencia.ExecuteReader(); while (resultado.Read()) { ImagenProducto = new ImagenProducto(); ImagenProducto.codigoimagen = (int)resultado[0]; ImagenProducto.urlimagen = (string)resultado[1]; ImagenProducto.nombreimagen = (string)resultado[2]; ImagenProducto.principal = (bool)resultado[3]; producto.agregarImagen(ImagenProducto); listaImagenProducto.Add(ImagenProducto); } resultado.Close(); return(listaImagenProducto); } catch (Exception) { throw ExcepcionSQL.crearErrorConsultar();; } }
public async Task <object> UpdImagen(ImagenProducto imagenProducto) { Response response = new Response(); ResponseSql responsesql = new ResponseSql(); try { if (imagenProducto.ACCION == "A" || imagenProducto.ACCION == "M") { string directory = _config.GetSection("AppSettings").GetSection("directory").Value; if (imagenProducto.SArchivo != "" && imagenProducto.BImagen != "") { AuxiliarMethods.Base64ToImage(directory, imagenProducto.BImagen, imagenProducto.SArchivo, "Producto"); } } responsesql = await _unitOfWork.Producto.UpdImagen(imagenProducto); response.Status = responsesql.ID_ERR == 0 ? Constant.Status : responsesql.ID_ERR; response.Message = responsesql.DESCR_ERR; response.Data = responsesql.IDDATO; } catch (Exception e) { response.Status = Constant.Error500; response.Message = e.Message; } return(response); }
public ImagenProducto buscarImagenPrincipalProducto(Producto producto) { try { ImagenProducto ImagenProducto = null; string consultaSQL = "SELECT img.codigoimagenproducto, img.direccionimagenproducto, img.nombreimagenproducto, img.principalimagenproducto FROM imagenproducto img where img.codigoproducto=@codigoproducto and img.principalimagenproducto='TRUE'"; SqlDataReader resultado; SqlCommand sentencia; sentencia = gestorODBC.prepararSentencia(consultaSQL); sentencia.Parameters.Add("@codigoproducto", Int).Value = producto.codigoProducto; resultado = sentencia.ExecuteReader(); if (resultado.Read()) { ImagenProducto = new ImagenProducto(); ImagenProducto.codigoimagen = (int)resultado[0]; ImagenProducto.urlimagen = (string)resultado[1]; ImagenProducto.nombreimagen = (string)resultado[2]; ImagenProducto.principal = (bool)resultado[3]; } resultado.Close(); return(ImagenProducto); } catch (Exception) { throw ExcepcionSQL.crearErrorConsultar(); } }
public static List <ImagenProducto> GetImagenProductoById(int Idprocuto) { ImagenProductoTableAdapter localAdapter = new ImagenProductoTableAdapter(); if (Idprocuto <= 0) { return(null); } List <ImagenProducto> theList = new List <ImagenProducto>(); ImagenProducto theUser = null; ImagenProductoTableAdapter theAdapter = new ImagenProductoTableAdapter(); try { ImagenProductoDS.ImagenProductoDataTable table = theAdapter.GetImagenProductoById(Idprocuto); if (table != null && table.Rows.Count > 0) { foreach (ImagenProductoDS.ImagenProductoRow row in table.Rows) { theUser = FillImagenProductoRecord(row); theList.Add(theUser); } } } catch (Exception q) { log.Error("el error ocurrio mientras obtenia la lista de las Imagenes del producto Id :\"" + Idprocuto + "\" de la base de datos", q); throw q; //return null; } return(theList); }
public void UploadFile() { if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any()) { // Obtener la imagen subida var httpPostedFile = System.Web.HttpContext.Current.Request.Files["UploadedImage"]; String usuarioId = User.Identity.Name; String tienda = Session["Tienda_Nombre"].ToString(); long prodId = Convert.ToInt64(System.Web.HttpContext.Current.Request.Form["ProductoID"]); if (httpPostedFile != null) { byte[] imageBytes = null; using (var binaryReader = new BinaryReader(httpPostedFile.InputStream)) { imageBytes = binaryReader.ReadBytes(httpPostedFile.ContentLength); } ImagenProducto ip = new ImagenProducto { ProductoID = prodId, Imagen = imageBytes }; cS.AgregarImagenProducto(ip, tienda); } } }
public async Task <ActionResult <Response> > UpdImagen([FromBody] ImagenProducto imagenProducto) { Response response = new Response(); object rpta = new object(); try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } imagenProducto = (ImagenProducto)BusinessLogic.Utilities.AuxiliarMethods.ValidateParameters(imagenProducto, imagenProducto.GetType()); rpta = await _productologic.UpdImagen(imagenProducto); if (rpta == null) { return(NotFound()); } } catch (Exception e) { response.Status = Constant.Error500; response.Message = e.Message; return(Ok(response)); } return(Ok(rpta)); }
protected void ImagenRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "addImageArticulo") { try { ImagenProducto data = new ImagenProducto(); bool repetido = false; int imagenId = Convert.ToInt32(e.CommandArgument.ToString()); data.ImagenId = imagenId; data.ProductoId = Convert.ToInt32(ProductoIdHiddenField.Value); List <ImagenProducto> listaImgProducto = ImagenProductoBLL.GetImagenProductoById(Convert.ToInt32(ProductoIdHiddenField.Value)); //List<ImageArticulo> articuloImg = ImageArticuloBLL.GetImagenesArticulo(Convert.ToInt32(CodigoLiteral.Text)); for (int i = 0; i < listaImgProducto.Count; i++) { if (imagenId == listaImgProducto[i].ImagenId) { repetido = true; } } if (repetido == false) { ImagenProductoBLL.InsertImageProducto(data); cargarListaImagenesDelProducto(CodigoLiteral.Text); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorAlert", "alert('La imagen no se puede insertar por que estaria repetida');", true); } } catch (Exception ex) { Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorAlert", "alert('La imagen no pudo ser insertada al articulo');", true); log.Error("La imagen no pudo ser insertada al articulo", ex); return; //throw ex; } } if (e.CommandName == "removeImage") { try { ImagenProducto data = new ImagenProducto(); int imagenId = Convert.ToInt32(e.CommandArgument.ToString()); Imagen objImagen = ImagenBLL.GetImagenById(imagenId); System.IO.FileInfo info = new System.IO.FileInfo(objImagen.Directorio); info.Delete(); ImagenBLL.DeleteImagen(imagenId); cargarImagenesRepeateLista(); } catch (Exception ex) { log.Error("La imagen no pudo ser insertada al articulo", ex); return; } } }
private static ImagenProducto FillImagenRecord(ImagenProductoDS.ImagenProductoRow row) { ImagenProducto theNewRecord = new ImagenProducto( row.imagenProductoId, row.productoId, row.imagenId); return(theNewRecord); }
public ActionResult CreatePromotion(Promocion oPromotion, HttpPostedFileBase files) { var model = oSrvPromotions.GetPromocion(); try { if (ModelState.IsValid) { UploadDirectory = ProyectoTelas.Properties.Settings.Default.DirectorioImagenes; //string servername = Dashboard1._2.Properties.Settings.Default.NombreServidor; HttpPostedFileBase file = Request.Files["files"]; var directorio = UploadDirectory; string pathRandom = Path.GetRandomFileName().Replace(/*'.', '-'*/ "~/", ""); string resultFileName = pathRandom + '_' + file.FileName.Replace("~/", ""); string resultFileUrl = directorio + resultFileName; string resultFilePath = System.Web.HttpContext.Current.Request.MapPath(resultFileUrl); bool hasFile = false; ImagenProducto oImgProduct = null; var validate = db.Promocion.Select(x => x.Nombre == oPromotion.Nombre).First(); if (!validate) { if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { file.SaveAs(resultFilePath); oPromotion.Imagen = /*servername +*/ resultFileUrl.Replace("~/", ""); oImgProduct = new ImagenProducto(); //oImgProduct.Tipo = file.ContentType; oImgProduct.Url = oPromotion.Imagen.Replace("~/", ""); //oImgProduct.Estatus = true; hasFile = true; } db.Promocion.Add(oPromotion); db.SaveChanges(); if (hasFile) { oImgProduct.ProductoID = oPromotion.PromocionID; db.SaveChanges(); } return(RedirectToAction("Index")); } } } catch (Exception ex) { Console.WriteLine("Error : " + ex.Message); } ViewBag.ProductoId = new SelectList(db.Producto, "ProductoID", "Nombre", oPromotion.ProductoID); return(View("Crear", oPromotion)); //return View(oPromotion); }
public ActionResult Create(Producto producto, HttpPostedFileBase files) { try { if (ModelState.IsValid) { UploadDirectory = ProyectoTelas.Properties.Settings.Default.DirectorioImagenes; HttpPostedFileBase file = Request.Files["files"]; var directorio = UploadDirectory; string pathRandom = Path.GetRandomFileName().Replace(/*'.', '-'*/ "~/", ""); string resultFileName = pathRandom + '_' + file.FileName.Replace("~/", ""); string resultFileUrl = directorio + resultFileName; string resultFilePath = System.Web.HttpContext.Current.Request.MapPath(resultFileUrl); bool hasFile = false; ImagenProducto oImgProduct = null; if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { file.SaveAs(resultFilePath); producto.ImagenPortada = /*servername +*/ resultFileUrl.Replace("~/", ""); oImgProduct = new ImagenProducto(); oImgProduct.Url = producto.ImagenPortada.Replace("~/", ""); hasFile = true; } db.Producto.Add(producto); db.SaveChanges(); oImgProduct.ProductoID = producto.ProductoID; db.ImagenProducto.Add(oImgProduct); db.SaveChanges(); if (hasFile) { oImgProduct.ProductoID = producto.ProductoID; db.SaveChanges(); } //} return(RedirectToAction("Index")); } //} } catch (Exception ex) { throw new Exception(SrvMessages.getMessageSQL(ex)); } ViewBag.ProveedorId = new SelectList(db.Proveedor, "ProveedorID", "NombreProveedor", producto.ProveedorID); return(View(producto)); }
protected void SaveImagenButton_Click(object sender, EventArgs e) { ImagenProducto ObjImagenProducto = new ImagenProducto(); ObjImagenProducto.ProductoId = Convert.ToInt32(ProductoIdHiddenField.Value); ObjImagenProducto.ImagenId = Convert.ToInt32(ImagenIdHiddenField.Value); ImagenProductoBLL.InsertImageProducto(ObjImagenProducto); CargarProducto(); cargarImagenesRepeateLista(); }
public static ImagenProductoDTO ToDTO(this ImagenProducto model) { return(new ImagenProductoDTO { IdImagenProducto = model.IdImagenProducto, IdProducto = model.IdProducto, EsPortada = model.EsPortada, Url = model.Url }); }
public ImagenProductoDto createImagenProducto(string nombre) { var entity = new ImagenProducto() { Nombre = nombre + ".jpg" }; repository.Agregarr <ImagenProducto>(entity); return(new ImagenProductoDto { Nombre = nombre + ".jpg" }); }
private void bgwImagen_DoWork(object sender, DoWorkEventArgs e) { if (pcbProducto.InvokeRequired) { try { ImagenProducto i = new ImagenProducto(Imagen); this.Invoke(i, Producto.Imagen01Producto(id)); } catch { } } }
public void crearimagenProducto(ImagenProducto imagenProducto, int codigoproducto) { try { gestorODBC.abrirConexion(); imagenProductoDAO.crearImagenProducto(imagenProducto, codigoproducto); gestorODBC.cerrarConexion(); } catch (Exception e) { gestorODBC.cerrarConexion(); throw e; } }
public void modificarimagenProducto(ImagenProducto imagenProducto) { try { gestorODBC.abrirConexion(); imagenProductoDAO.modificarImagenProducto(imagenProducto); gestorODBC.cerrarConexion(); } catch (Exception e) { gestorODBC.cerrarConexion(); throw e; } }
public void eliminarimagenProducto(ImagenProducto imagenProducto) { try { gestorODBC.abrirConexion(); imagenProducto.validarPrincipal(imagenProducto); imagenProductoDAO.eliminarImagenProducto(imagenProducto); gestorODBC.cerrarConexion(); } catch (Exception e) { gestorODBC.cerrarConexion(); throw e; } }
public void eliminarImagenProducto(ImagenProducto ImagenProducto) { try { string sentenciaSQL = "delete imagenproducto where codigoimagenproducto=@codigoimagenproducto"; SqlCommand sentencia; sentencia = gestorODBC.prepararSentencia(sentenciaSQL); sentencia.Parameters.Add("@codigoimagenproducto", Int).Value = ImagenProducto.codigoimagen; sentencia.ExecuteNonQuery(); } catch (Exception) { throw ExcepcionSQL.crearErrorEliminar(); } }
private List <ImagenProducto> ObtenerImagenesProducto(long ProductoID, string item) { List <ImagenProducto> lista = new List <ImagenProducto>(); var json = ripJson("/items/" + item); foreach (var picture in json.pictures) { var webCli = new WebClient(); byte[] bytes = webCli.DownloadData((string)picture.url); ImagenProducto im = new ImagenProducto { ProductoID = ProductoID, Imagen = bytes }; lista.Add(im); } return(lista); }
public GuardarImagenResponse Guardar(ImagenProducto imagenProducto) { try { _context.ImagenesProductos.Add(imagenProducto); _context.SaveChanges(); var LastRegister = _context.ImagenesProductos .OrderByDescending(x => x.ImagenProductoID) .First().ImagenProductoID; return(new GuardarImagenResponse(LastRegister)); } catch (Exception e) { return(new GuardarImagenResponse($"Error de la Aplicacion: {e.Message}")); } }
public void modificarImagenProducto(ImagenProducto ImagenProducto) { try { string sentenciaSQL = "UPDATE imagenproducto SET direccionimagenproducto=@direccionimagenproducto, nombreimagenproducto=@nombreimagenproducto, principalimagenproducto=@principalimagenproducto WHERE codigoimagenproducto=@codigoimagenproducto"; SqlCommand sentencia; sentencia = gestorODBC.prepararSentencia(sentenciaSQL); sentencia.Parameters.Add("@direccionimagenproducto", VarChar, 100).Value = ImagenProducto.urlimagen; sentencia.Parameters.Add("@nombreimagenproducto", VarChar, 200).Value = ImagenProducto.nombreimagen; sentencia.Parameters.Add("@principalimagenproducto", Bit).Value = ImagenProducto.principal; sentencia.Parameters.Add("@codigoimagenproducto", Int).Value = ImagenProducto.codigoimagen; sentencia.ExecuteNonQuery(); } catch (Exception) { throw ExcepcionSQL.crearErrorModificar(); } }
public void crearImagenProducto(ImagenProducto ImagenProducto, int codigoproducto) { try { string sentenciaSQL = "INSERT INTO imagenproducto(codigoproducto,direccionimagenproducto,nombreimagenproducto,principalimagenproducto) VALUES(@codigoproducto,@direccionimagenproducto,@nombreimagenproducto,@principalimagenproducto)"; SqlCommand sentencia; sentencia = gestorODBC.prepararSentencia(sentenciaSQL); sentencia.Parameters.Add("@codigoproducto", Int).Value = codigoproducto; sentencia.Parameters.Add("@direccionimagenproducto", VarChar, 500).Value = ImagenProducto.urlimagen; sentencia.Parameters.Add("@nombreimagenproducto", VarChar, 100).Value = ImagenProducto.nombreimagen; sentencia.Parameters.Add("@principalimagenproducto", Bit).Value = ImagenProducto.principal; sentencia.ExecuteNonQuery(); } catch (Exception) { throw ExcepcionSQL.crearErrorInsertar(); } }
public async Task <ResponseSql> UpdImagen(ImagenProducto imagenProducto) { var parameters = new DynamicParameters(); parameters.Add("@ACCION", imagenProducto.ACCION); parameters.Add("@IDIMAGEN", imagenProducto.IdImagen); parameters.Add("@IDPRODUCTO", imagenProducto.IdProducto); parameters.Add("@COD_COLOR", imagenProducto.Cod_Color); parameters.Add("@NORDEN", imagenProducto.NOrden); parameters.Add("@SDESCRIPCION", imagenProducto.SDescripcion); parameters.Add("@SARCHIVO", imagenProducto.SArchivo); parameters.Add("@BIMAGEN", imagenProducto.BImagen); parameters.Add("@IDUSUARIO", imagenProducto.IdUsuario); using (var connection = new SqlConnection(_connectionString)) { return(await connection.QueryFirstAsync <ResponseSql>("[dbo].[SPE_UDP_EXT_PRODUCTO_IMAGEN]", parameters, commandType : System.Data.CommandType.StoredProcedure)); } }
public static void InsertImageProducto(ImagenProducto newData) { if (newData == null) { throw new ArgumentException("el articuloImagen no puede ser null"); } try { ImagenProductoTableAdapter localAdapter = new ImagenProductoTableAdapter(); //DateTime? nullDate = null; localAdapter.InsertImagenProducto( newData.ProductoId, newData.ImagenId ); log.Debug("Se insertó la imagen en su Articulo" + newData.ImagenProductoId); } catch (Exception q) { log.Error("Ocurrió un error mientras se insertaba la imagen en el Articulo", q); throw q; } }
public async Task <ActionResult <Response> > UpdImagen([FromBody] ImagenProducto imagenProducto) { object rpta = new object(); try { imagenProducto = (ImagenProducto)ValidateParameters(imagenProducto, imagenProducto.GetType()); rpta = await _productologic.UpdImagen(imagenProducto); if (rpta == null) { return(NotFound()); } } catch (Exception e) { Response response = new Response(); response.Status = Constant.Error500; response.Message = e.Message; return(Ok(response)); } return(Ok(rpta)); }
public async Task <ActionResult> Create(CreateProductosViewModel productos) { if (ModelState.IsValid) { Productos newProduct = null; if (productos.ProductoImagenes.ElementAt(0) == null) { newProduct = new Productos { ProductoTitulo = productos.ProductoTitulo, ProdutoDescripcion = productos.ProdutoDescripcion, ProductoPrecio = productos.ProductoPrecio, ProductStock = productos.ProductStock, CategoryKey = productos.CategoryKey, UnidadesId = productos.UnidadesId, ProductoImagenes = "/img/noimage.jpg" }; db.Productos.Add(newProduct); await db.SaveChangesAsync(); } else { newProduct = new Productos { ProductoTitulo = productos.ProductoTitulo, ProdutoDescripcion = productos.ProdutoDescripcion, ProductoPrecio = productos.ProductoPrecio, ProductStock = productos.ProductStock, CategoryKey = productos.CategoryKey, UnidadesId = productos.UnidadesId, ProductoImagenes = "/img/" + Path.GetFileName(productos.ProductoImagenes.ElementAt(0).FileName) }; db.Productos.Add(newProduct); await db.SaveChangesAsync(); } string uniqueName = null; if (productos.ProductoImagenes.ElementAt(0) != null) { for (int i = 0; i < productos.ProductoImagenes.Count(); i++) { var fileName = Path.GetFileName(productos.ProductoImagenes.ElementAt(i).FileName); string pa = Server.MapPath("/img").ToString(); var Filepath = Path.Combine(Server.MapPath("/img"), fileName); productos.ProductoImagenes.ElementAt(i).SaveAs(Filepath); uniqueName = "/img/" + fileName; var imagen = new ImagenProducto { urlImagen = uniqueName, IdProducto = newProduct.IdProducto }; db.ImagenesProductos.Add(imagen); await db.SaveChangesAsync(); } } else { var imagen = new ImagenProducto { urlImagen = "/img/noimage.jpg", IdProducto = newProduct.IdProducto }; db.ImagenesProductos.Add(imagen); await db.SaveChangesAsync(); } return(RedirectToAction("Index")); } ViewBag.CategoryKey = new SelectList(db.Categories, "CategoryKey", "CotegoryName", productos.CategoryKey); ViewBag.UnidadesId = new SelectList(db.Unidades, "UnidadesId", "UnidadesNombre", productos.UnidadesId); return(View(productos)); }
public async Task <ActionResult> Edit(CreateProductosViewModel productos) { if (ModelState.IsValid) { Productos newProduct = null; if (productos.ProductoImagenes.ElementAt(0) == null) { newProduct = new Productos { IdProducto = productos.IdProducto, ProductoTitulo = productos.ProductoTitulo, ProdutoDescripcion = productos.ProdutoDescripcion, ProductoPrecio = productos.ProductoPrecio, ProductStock = productos.ProductStock, CategoryKey = productos.CategoryKey, UnidadesId = productos.UnidadesId, ProductoImagenes = "/img/noimage.jpg" }; } else { newProduct = new Productos { IdProducto = productos.IdProducto, ProductoTitulo = productos.ProductoTitulo, ProdutoDescripcion = productos.ProdutoDescripcion, ProductoPrecio = productos.ProductoPrecio, ProductStock = productos.ProductStock, CategoryKey = productos.CategoryKey, UnidadesId = productos.UnidadesId, ProductoImagenes = "/img/" + Path.GetFileName(productos.ProductoImagenes.ElementAt(0).FileName) }; } db.Entry(newProduct).State = EntityState.Modified; await db.SaveChangesAsync(); string uniqueName = null; if (productos.ProductoImagenes.ElementAt(0) != null) { //borrar imagenes que ya estaban almacenadas var ima = db.ImagenesProductos.Where(x => x.IdProducto == newProduct.IdProducto); foreach (var item in ima) { if (item.IdProducto == newProduct.IdProducto) { db.ImagenesProductos.Remove(item); //await db.SaveChangesAsync(); } } for (int i = 0; i < productos.ProductoImagenes.Count(); i++) { var fileName = Path.GetFileName(productos.ProductoImagenes.ElementAt(i).FileName); string pa = Server.MapPath("/img").ToString(); var Filepath = Path.Combine(Server.MapPath("/img"), fileName); productos.ProductoImagenes.ElementAt(i).SaveAs(Filepath); uniqueName = "/img/" + fileName; var imagen = new ImagenProducto { urlImagen = uniqueName, IdProducto = newProduct.IdProducto }; db.ImagenesProductos.Add(imagen); await db.SaveChangesAsync(); } } else { var imagen = new ImagenProducto { urlImagen = "/img/noimage.jpg", IdProducto = newProduct.IdProducto }; db.ImagenesProductos.Add(imagen); await db.SaveChangesAsync(); } return(RedirectToAction("Index")); } ViewBag.CategoryKey = new SelectList(db.Categories, "CategoryKey", "CotegoryName", productos.CategoryKey); ViewBag.UnidadesId = new SelectList(db.Unidades, "UnidadesId", "UnidadesNombre", productos.UnidadesId); return(View(productos)); }
public ImagenProductoViewModel(ImagenProducto imagenProducto) { ImagenProductoID = imagenProducto.ImagenProductoID; Imagen = imagenProducto.Imagen; }
public async Task <Producto> InsertarProductoPanel(InsertoProductoPanelDto producto) { var db = new QueryFactory(connection, compiler); ImagenProducto imagen = new ImagenProducto() { Nombre = producto.imagen }; PrecioProducto precio = new PrecioProducto() { Precioreal = producto.precioreal, Precioventa = producto.precioventa, Fecha = DateTime.Now }; Marca marca = new Marca() { Nombre = producto.marca }; repository.Agregar <ImagenProducto>(imagen); repository.Agregar <PrecioProducto>(precio); repository.Agregar <Marca>(marca); var categoriaID = db.Query("categorias"). Select("Id"). Where("Descripcion", "=", producto.categoria).FirstOrDefault <int>(); var imagenID = db.Query("imagenproducto"). Select("Id"). Where("nombre", "=", producto.imagen).FirstOrDefault <int>(); var precioID = db.Query("precioproducto"). Select("Id"). Where("PrecioVenta", "=", producto.precioventa) .Where("PrecioReal", "=", producto.precioreal). FirstOrDefault <int>(); var marcaID = db.Query("marca"). Select("Id"). Where("Nombre", "=", producto.marca). FirstOrDefault <int>(); Producto objeto = new Producto() { Nombre = producto.nombre, Descripcion = producto.descripcion, ImagenID = imagenID, PrecioID = precioID, CategoriaID = categoriaID, MarcaID = marcaID, Stock = producto.stock }; repository.Agregarr <Producto>(objeto); var ProductoID = db.Query("productos"). Select("Id"). Where("Nombre", "=", objeto.Nombre). Where("CategoriaID", "=", objeto.CategoriaID). Where("PrecioID", "=", objeto.PrecioID). Where("MarcaID", "=", objeto.MarcaID). Where("Stock", "=", objeto.Stock). Where("Descripcion", "=", objeto.Descripcion). FirstOrDefault <int>(); InsertarPublicacionDto avg = new InsertarPublicacionDto() { productoID = ProductoID }; string url = "https://localhost:44398/api/Publicacion/InsertarPublicacion"; using (var httpClient = new HttpClient()) { var json = Newtonsoft.Json.JsonConvert.SerializeObject(avg, Formatting.None); var data = new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json"); var result = await httpClient.PostAsync(url, data); string resultado = result.Content.ReadAsStringAsync().Result; //posts = JsonConvert.DeserializeObject<List<ProductoEspecificoDto>>(resultado); } return(objeto); }