private void MethodAddDetails(ESGR_CartaDiaDetalle ESGR_CartaDiaDetalle) { if (ESGR_CartaDiaDetalle == null) { return; } if (ESGR_CartaDiaDetalle.ESGR_Producto == null) { return; } if (ESGR_CartaDiaDetalle.ESGR_Producto.ESGR_ProductoSubCategoria == null) { return; } if (ESGR_CartaDiaDetalle.ESGR_Producto.ESGR_ProductoSubCategoria.ESGR_ProductoCategoria == null) { return; } var NameCategoria = ESGR_CartaDiaDetalle.ESGR_Producto.ESGR_ProductoSubCategoria.ESGR_ProductoCategoria.Categoria; var NameSubCategoria = ESGR_CartaDiaDetalle.ESGR_Producto.ESGR_ProductoSubCategoria.SubCategoria; //===================NO EXISTE CATEGORÍA============================// var IsExistCategoria = CollectionVMSGR_CartaDiaDetalleCategoria.ToList().Exists(x => x.Categoria == NameCategoria); if (!IsExistCategoria) { CollectionVMSGR_CartaDiaDetalleCategoria.Add(new VMSGR_CartaDiaDetalleCategoria() { Categoria = NameCategoria, CollectionVMSGR_CartaDiaDetalleSubCategoria = new ObservableCollection <VMSGR_CartaDiaDetalleSubCategoria>() { new VMSGR_CartaDiaDetalleSubCategoria() { SubCategoria = NameSubCategoria, CollectionESGR_CartaDiaDetalle = new ObservableCollection <ESGR_CartaDiaDetalle>() { ESGR_CartaDiaDetalle } } } }); } else { //===================SI CATEGORÍA============================// var FirstCategoria = CollectionVMSGR_CartaDiaDetalleCategoria.First(x => x.Categoria == NameCategoria); //===================NO EXISTE SUB-CATEGORÍA============================// var IsExistSubCategoria = FirstCategoria.CollectionVMSGR_CartaDiaDetalleSubCategoria.ToList().Exists(x => x.SubCategoria == NameSubCategoria); if (!IsExistSubCategoria) { FirstCategoria.CollectionVMSGR_CartaDiaDetalleSubCategoria.Add(new VMSGR_CartaDiaDetalleSubCategoria() { SubCategoria = NameSubCategoria, CollectionESGR_CartaDiaDetalle = new ObservableCollection <ESGR_CartaDiaDetalle>() { ESGR_CartaDiaDetalle } }); } else { //===================SI SUB-CATEGORÍA============================// var FirstSubCategoria = FirstCategoria.CollectionVMSGR_CartaDiaDetalleSubCategoria.First(x => x.SubCategoria == NameSubCategoria); //===================NO EXISTE ESGR_CartaDiaDetalle============================// var IsExistProducto = FirstSubCategoria.CollectionESGR_CartaDiaDetalle.ToList().Exists(x => x.ESGR_Producto.IdProducto == ESGR_CartaDiaDetalle.ESGR_Producto.IdProducto); if (!IsExistProducto) { FirstSubCategoria.CollectionESGR_CartaDiaDetalle.Add(ESGR_CartaDiaDetalle); } } } }
private void MethodAddDetails(ESGR_CartaDiaDetalle ESGR_CartaDiaDetalle) { try { if (ESGR_CartaDiaDetalle == null) { return; } if (ESGR_CartaDiaDetalle.ESGR_Producto == null) { return; } if (ESGR_CartaDiaDetalle.ESGR_Producto.ESGR_ProductoSubCategoria == null) { return; } if (ESGR_CartaDiaDetalle.ESGR_Producto.ESGR_ProductoSubCategoria.ESGR_ProductoCategoria == null) { return; } var NameCategoria = ESGR_CartaDiaDetalle.ESGR_Producto.ESGR_ProductoSubCategoria.ESGR_ProductoCategoria.Categoria; var NameSubCategoria = ESGR_CartaDiaDetalle.ESGR_Producto.ESGR_ProductoSubCategoria.SubCategoria; //===================NO EXISTE CATEGORÍA============================// var IsExistCategoria = CollectionVMSGR_CartaDiaDetalleCategoria.ToList().Exists(x => x.Categoria == NameCategoria); if (!IsExistCategoria) { Application.Current.Dispatcher.Invoke(() => CollectionVMSGR_CartaDiaDetalleCategoria.Add(new VMSGR_CartaDiaDetalleCategoria() { Categoria = NameCategoria, CollectionVMSGR_CartaDiaDetalleSubCategoria = new ObservableCollection <VMSGR_CartaDiaDetalleSubCategoria>() { new VMSGR_CartaDiaDetalleSubCategoria() { SubCategoria = NameSubCategoria, CollectionESGR_CartaDiaDetalle = new ObservableCollection <ESGR_CartaDiaDetalle>() { ESGR_CartaDiaDetalle } } } }) ); } else { //===================SI CATEGORÍA============================// var FirstCategoria = CollectionVMSGR_CartaDiaDetalleCategoria.First(x => x.Categoria == NameCategoria); //===================NO EXISTE SUB-CATEGORÍA============================// var IsExistSubCategoria = FirstCategoria.CollectionVMSGR_CartaDiaDetalleSubCategoria.ToList().Exists(x => x.SubCategoria == NameSubCategoria); if (!IsExistSubCategoria) { Application.Current.Dispatcher.Invoke(() => FirstCategoria.CollectionVMSGR_CartaDiaDetalleSubCategoria.Add(new VMSGR_CartaDiaDetalleSubCategoria() { SubCategoria = NameSubCategoria, CollectionESGR_CartaDiaDetalle = new ObservableCollection <ESGR_CartaDiaDetalle>() { ESGR_CartaDiaDetalle } }) ); } else { //===================SI SUB-CATEGORÍA============================// var FirstSubCategoria = FirstCategoria.CollectionVMSGR_CartaDiaDetalleSubCategoria.First(x => x.SubCategoria == NameSubCategoria); //===================NO EXISTE ESGR_CartaDiaDetalle============================// var IsExistProducto = FirstSubCategoria.CollectionESGR_CartaDiaDetalle.ToList().Exists(x => x.ESGR_Producto.IdProducto == ESGR_CartaDiaDetalle.ESGR_Producto.IdProducto); if (!IsExistProducto) { Application.Current.Dispatcher.Invoke(() => FirstSubCategoria.CollectionESGR_CartaDiaDetalle.Add(ESGR_CartaDiaDetalle)); } } } } catch (Exception ex) { CmpMessageBox.Show(SGRMessage.AdministratorCartaDia, ex.Message, CmpButton.Aceptar); } }