Пример #1
0
        /// <summary>
        /// Regresa un registro de
        /// </summary>
        /// <param name="productLegend">Objeto con los filtros</param>
        /// <returns>Product legend</returns>
        /// <history>
        /// [emoguel] created 23/05/2016
        /// </history>
        public async static Task <ProductLegend> GetProductLegend(ProductLegend productLegend)
        {
            ProductLegend productL = null;
            await Task.Run(() =>
            {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    var query = from px in dbContext.ProductsLegends
                                where px.pxla == productLegend.pxla && px.pxpr == productLegend.pxpr
                                select px;
                    productL = query.FirstOrDefault();
                }
            });

            return(productL);

            #endregion
        }
Пример #2
0
        /// <summary>
        /// Carga el legend del product dependiendo del lenguage seleccionado
        /// </summary>
        /// <history>
        /// [emoguel] created 24/05/2016
        /// </history>
        private async void LoadLegends()
        {
            try
            {
                if (cmbLanguages.SelectedIndex > -1)
                {
                    _productLegend.pxla = cmbLanguages.SelectedValue.ToString();
                    _productLegend.pxpr = product.prID;
                    ProductLegend prodLeg = await BRProductsLegends.GetProductLegend(_productLegend);

                    if (prodLeg != null)
                    {
                        UIRichTextBoxHelper.LoadRTF(ref richTextBox, prodLeg.pxText);
                    }
                    _productLegend.pxText = UIRichTextBoxHelper.getRTFFromRichTextBox(ref richTextBox);
                }
            }
            catch (Exception ex)
            {
                UIHelper.ShowMessage(ex);
            }
        }
Пример #3
0
        /// <summary>
        /// Agrega|Actualiza un product
        /// Asigna|desasigna gifts
        /// Actualiza|Agrega un productLegend
        /// </summary>
        /// <param name="product">OBjeto a guardar en product</param>
        /// <param name="blnUpdate">True. Actualiza | False. Agrega</param>
        /// <param name="productLegend">Product legend a guardar</param>
        /// <param name="lstAdd">Gifts a asignar</param>
        /// <param name="lstDel">gift a desasignar</param>
        /// <returns>-1. Existe un product con el mismo ID | 0. No se guardó | >0. Se guardó correctamente</returns>
        /// <history>
        /// [emoguel] created 24/05/2016
        /// </history>
        public async static Task <int> SaveProduct(Product product, bool blnUpdate, ProductLegend productLegend, List <Gift> lstAdd, List <Gift> lstDel)
        {
            int nRes = 0;
            await Task.Run(() =>
            {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    using (var transacction = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
                    {
                        try
                        {
                            #region Update
                            if (blnUpdate)
                            {
                                dbContext.Entry(product).State = EntityState.Modified;
                            }
                            #endregion
                            #region Add
                            else
                            {
                                if (dbContext.Products.Where(pr => pr.prID == product.prID).FirstOrDefault() != null)
                                {
                                    return(-1);
                                }
                                else
                                {
                                    dbContext.Products.Add(product);
                                }
                            }
                            #endregion
                            #region ProductLegend
                            if (!string.IsNullOrWhiteSpace(productLegend.pxText))
                            {
                                ProductLegend prodLegenVal = dbContext.ProductsLegends.Where(px => px.pxla == productLegend.pxla && px.pxpr == productLegend.pxpr).FirstOrDefault();
                                if (prodLegenVal != null)
                                {
                                    prodLegenVal.pxText = productLegend.pxText;
                                }
                                else
                                {
                                    productLegend.pxpr = product.prID;
                                    dbContext.ProductsLegends.Add(productLegend);
                                }
                            }
                            #endregion
                            #region Gifts
                            dbContext.Gifts.AsEnumerable().Where(gi => lstAdd.Any(gii => gii.giID == gi.giID)).ToList().ForEach(gi =>//Add
                            {
                                gi.gipr = product.prID;
                            });

                            dbContext.Gifts.AsEnumerable().Where(gi => lstDel.Any(gii => gii.giID == gi.giID)).ToList().ForEach(gi =>//Del
                            {
                                gi.gipr = null;
                            });
                            #endregion
                            nRes = dbContext.SaveChanges();
                            transacction.Commit();
                            return(nRes);
                        }
                        catch
                        {
                            transacction.Rollback();
                            throw;
                        }
                    }
                }
            });

            return(nRes);
        }