public void ProductoGrupoOrdenEliminar(int id) { RepositoryGenerico <ProductoGrupoOrden> repository = new RepositoryGenerico <ProductoGrupoOrden>(); ProductoGrupoOrden dato = repository.Obtener(id); if (dato == null) { throw new ApplicationException("No existe"); } dato.Vigente = false; repository.Actualizar(dato); }
public IHttpActionResult ProductoGrupoOrdenGrabar(ProductoGrupoOrden dato) { try { ServiciosCatalogos servicio = new ServiciosCatalogos(); ProductoGrupoOrden resp = servicio.ProductoGrupoOrdenGrabar(dato); return(Ok(resp)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ProductoGrupoOrden ProductoGrupoOrdenGrabar(ProductoGrupoOrden dato) { RepositoryGenerico <ProductoGrupoOrden> repository = new RepositoryGenerico <ProductoGrupoOrden>(); dato.Validar(); if (dato.Id == -1) { if (repository.Obtener("Descripcion", dato.Descripcion) != null) { throw new ApplicationException("Ya existe"); } dato.Vigente = true; } repository.Actualizar(dato); return(dato); }
public IHttpActionResult ProductoGrupoOrden(int id) { try { ServiciosCatalogos servicio = new ServiciosCatalogos(); ProductoGrupoOrden resp = servicio.ObtenerObjeto <ProductoGrupoOrden>(id); if (resp == null) { return(NotFound()); } return(Ok(resp)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public Producto ProductoGrabar(Producto datoGraba, string carpetaFoto) { ServicioGenerico servGenerico = new ServicioGenerico(); ProductoRepository repository = new ProductoRepository(); Producto dato; string pathOrigen = string.Empty; if (datoGraba.Id == -1) { dato = new Producto(); string codigoAutomatico = servGenerico.ParametroObtenerValor("CODIGO_AUTOMATICO"); string primerCodigo = servGenerico.ParametroObtenerValor("PRIMER_CODIGO_AUTOMATICO"); if (codigoAutomatico != null && codigoAutomatico.Equals("SI")) { Producto ultimo = repository.ObtenerUltimoProducto(); if (ultimo == null) { dato.Codigo = primerCodigo.ConvertirInt(); } else { dato.Codigo = ultimo.Codigo + 1; } } } else { dato = repository.Obtener(datoGraba.Id); if (dato == null) { throw new ApplicationException("No existe Producto"); } pathOrigen = dato.Path; } string url_host = servGenerico.ParametroObtenerValor("URL_HOST"); if (!string.IsNullOrEmpty(datoGraba.Foto)) { Producto validar = null; validar = repository.Obtener("Foto", datoGraba.Foto); if (validar != null && validar.Id != datoGraba.Id) { throw new ApplicationException("Ya existe un producto con la misma foto"); } } dato.Vigente = true; dato.Descripcion = datoGraba.Descripcion; dato.Peso = datoGraba.Peso; dato.TipoPrecio = datoGraba.TipoPrecio; if (dato.PrecioPorPeso) { dato.PrecioUnitario = 0; } else { dato.PrecioUnitario = datoGraba.PrecioUnitario; } bool cambioSubcategoria = (dato.Subcategoria != null && dato.Subcategoria.Id != datoGraba.Subcategoria.Id); dato.Subcategoria = this.ObtenerObjeto <Subcategoria>(datoGraba.Subcategoria.Id); dato.Ubicacion = datoGraba.Ubicacion; dato.Foto = datoGraba.Foto; if (string.IsNullOrEmpty(dato.FotoLink) && !string.IsNullOrEmpty(dato.Foto)) { dato.FotoLink = string.Format("{0}{1}{2}{3}", url_host, "assets/fotos", dato.Path, dato.Foto); } dato.ListaPrecio = this.ObtenerObjeto <ListaPrecio>(datoGraba.ListaPrecio.Id); //este gtupo orden no puede quedar null, para esos casos va GRUPOS_ORDEN.DEFAULT_ que es 1 ProductoGrupoOrden gpo = null; if (datoGraba.GrupoOrden.Id > 1) { gpo = this.ObtenerObjeto <ProductoGrupoOrden>(datoGraba.GrupoOrden.Id); } else { gpo = this.ObtenerObjeto <ProductoGrupoOrden>((int)GRUPOS_ORDEN.DEFAULT_); } if (gpo != null) { dato.GrupoOrden = gpo; } dato.Stock = datoGraba.Stock; dato.StockPropio = true; repository.Actualizar(dato); this.ProductoStockGrabar(datoGraba, dato.Id, cambioSubcategoria); //if (!string.IsNullOrEmpty(dato.Foto) && pathOrigen != dato.Path) //{ // string pathRoot = carpetaFoto.Substring(0, carpetaFoto.Length - 1); // string fileOrigen = string.Format("{0}{1}{2}", pathRoot, pathOrigen, dato.Foto); // string fileDestino = string.Format("{0}{1}{2}", pathRoot, dato.Path, dato.Foto); // FileHelper.CopyFile(fileOrigen.Replace(@"/", @"\"), fileDestino.Replace(@"\", @"/"), true); // FileHelper.DeleteFile(fileOrigen); // dato = repository.Obtener(dato.Id); // dato.FotoLink = string.Format("{0}{1}{2}{3}", url_host, "assets/fotos", dato.Path, dato.Foto); // repository.Actualizar(dato); //} CacheManager.RemoveToCache(gobalKeyCache); return(this.ObtenerObjeto <Producto>(dato.Id)); }