public ProductBE SearchIdProduct(int SEARIDPRO)
        {
            ProductMasterEntities BDMP   = new ProductMasterEntities();
            ProductBE             idprod = new ProductBE();

            try
            {
                idprod = (from Product in BDMP.Product
                          where Product.IdProduct == SEARIDPRO
                          select new ProductBE
                {
                    IdProduct = Product.IdProduct,
                    NameProduct = Product.NameProduct,
                    ReleaseDate = Product.ReleaseDate,
                    Email = Product.Email,
                    IdCountry = Product.IdCountry,
                    NameCountry = Product.NameProduct,
                    Cost = Product.Cost,
                    UnitsAvailable = Product.UnitsAvailable,
                    SoldUnits = Product.SoldUnits,
                    StateProduct = Product.StateProduct,
                }).FirstOrDefault();
            }
            catch (Exception EX)
            {
            }
            finally
            {
                BDMP.Dispose();
            }
            return(idprod);
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Proxy productService = new Proxy();

            int     productId    = Convert.ToInt32(this.hfldProductId.Value);
            string  productName  = this.txtProductName.Text.ToString().Trim();
            decimal productPrice = Convert.ToDecimal(this.txtProductPrice.Text);
            int     categoryId   = Convert.ToInt32(this.ddlCategorylist.SelectedValue);


            ProductBE product = new ProductBE();

            product.ProductId    = productId;
            product.ProductName  = productName;
            product.ProductPrice = productPrice;
            product.CategoryId   = categoryId;

            CategoryBE category = new CategoryBE();

            category.CategoryId = categoryId;
            product.Category    = category;

            productService.UpdateProduct(product);

            Response.Redirect("ProductList.aspx");
        }
Esempio n. 3
0
        //Este metodo es de tipo internal que perimte que solo se pueda acceder a el desde el mismo ensamblado, resive
        //un DbDataRecord y crea un objeto ProductBE para asignarle los valores en el DbDataRecord
        internal static ProductBE Get(DbDataRecord row)
        {
            var product = new ProductBE();

            //Para evitar errores de conversión se usan los metodos de DataUtilities para convertir los valores del
            //DbDataRecord y asignarselos a los atributos del ProductBE
            product.ProductID       = DataUtilities.GetInt32(row["ProductID"]).Value;
            product.ProductName     = DataUtilities.GetString(row["ProductName"]);
            product.SupplierID      = DataUtilities.GetInt32(row["SupplierID"]);
            product.CategoryID      = DataUtilities.GetInt32(row["CategoryID"]);
            product.QuantityPerUnit = DataUtilities.GetString(row["QuantityPerUnit"]);
            product.UnitPrice       = DataUtilities.GetDecimal(row["UnitPrice"]);
            product.UnitsInStock    = DataUtilities.GetInt32(row["UnitsInStock"]);
            product.UnitsOnOrder    = DataUtilities.GetInt32(row["UnitsOnOrder"]);
            product.ReorderLevel    = DataUtilities.GetInt32(row["ReorderLevel"]);
            product.Discontinued    = DataUtilities.GetBoolean(row["Discontinued"]);

            //Ahora se buscaran los objetos relacionados con este
            var dbCommand = Provider.GetDbCommand("SELECT * FROM Categories WHERE CategoryID = ?");

            Data.DataUtilities.Utilities.SetValue(dbCommand, product.CategoryID);

            product.Category = CategoryBC.Get(DAC.EjecutarConsulta(dbCommand).FirstOrDefault());

            dbCommand = Provider.GetDbCommand("SELECT * FROM Suppliers WHERE SupplierID = ?");
            Data.DataUtilities.Utilities.SetValue(dbCommand, product.SupplierID);

            product.Supplier = Contacts.SupplierBC.Get(DAC.EjecutarConsulta(dbCommand).FirstOrDefault());

            return(product);
        }
Esempio n. 4
0
        /// <summary>
        /// Assigns this instance.
        /// </summary>
        private void Assign()
        {
            try
            {
                if (Request.QueryString["productid"] != null)
                {
                    ProductId = Convert.ToInt32(Request["productid"]);

                    ProductBE product = this._presenter.GetProductById();
                    if (product == null)
                    {
                        Page.ClientScript.RegisterStartupScript(typeof(string), string.Empty, "alert('we don\\'t have this product!');location='ProductList.aspx';", true);
                    }
                    else
                    {
                        this.hfldProductId.Value  = Request["productid"];
                        this.txtProductName.Text  = product.ProductName;
                        this.txtProductPrice.Text = Convert.ToString(product.ProductPrice);

                        ddlCategorylist.SelectedValue = Convert.ToString(product.CategoryId);
                    }
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(typeof(string), string.Empty, "alert('we don\\'t have this product!');location='ProductList.aspx';", true);
                }
            }
            catch (Exception ex)
            {
                this.ShowErrorMessage(ex);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Assigns this instance.
        /// </summary>
        private void Assign()
        {
            if (Request.QueryString["productid"] != null)
            {
                int productid = Convert.ToInt32(Request["productid"]);

                Proxy     productService = new Proxy();
                ProductBE product        = productService.GetProductById(productid);
                if (product == null)
                {
                    Page.ClientScript.RegisterStartupScript(typeof(string), string.Empty, "alert('we don\\'t have this product!');location='ProductList.aspx';", true);
                }
                else
                {
                    this.hfldProductId.Value  = Request["productid"];
                    this.txtProductName.Text  = product.ProductName;
                    this.txtProductPrice.Text = Convert.ToString(product.ProductPrice);

                    ddlCategorylist.SelectedValue = Convert.ToString(product.CategoryId);
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(typeof(string), string.Empty, "alert('we don\\'t have this product!');location='ProductList.aspx';", true);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// delete product by productid
 /// </summary>
 /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param>
 protected void Delete(RepeaterCommandEventArgs e)
 {
     if (e.CommandArgument != null)
     {
         try
         {
             ProductId = Convert.ToInt32(e.CommandArgument);
             ProductBE product  = this._presenter.GetProductById();
             int       countNum = this._presenter.CountOrderDetailsByProductId();
             if (product == null)
             {
                 Page.ClientScript.RegisterStartupScript(typeof(string), string.Empty, "showErrorMessage('we don\\'t have this product!');location='ProductList.aspx';", true);
             }
             else if (countNum > 0)
             {
                 Page.ClientScript.RegisterStartupScript(typeof(string), string.Empty, "showErrorMessage('The product is being used!')", true);
             }
             else
             {
                 this._presenter.DeleteProduct();
                 Page.ClientScript.RegisterStartupScript(typeof(string), string.Empty, "window.location.href=window.location.href;", true);
             }
         }
         catch (Exception ex)
         {
             this.ShowErrorMessage(ex);
         }
     }
 }
Esempio n. 7
0
        public ProductBE SearchIdProduct(int SEARIDPROCUP)
        {
            MasterProductContext BDMP       = new MasterProductContext();
            ProductBE            idprocupbo = new ProductBE();

            try
            {
                idprocupbo = (from Product in BDMP.Product
                              where Product.IdProduct == SEARIDPROCUP
                              select new ProductBE
                {
                    IdProduct = Product.IdProduct,
                    NameProduct = Product.NameProduct,
                    Properties = Product.Properties,
                    ReleaseDate = Product.ReleaseDate,
                    ManufacturerEmail = Product.ManufacturerEmail,
                    IdCountry = Product.IdCountry,
                    Cost = Product.Cost,
                    UnitsAvailable = Product.UnitsAvailable,
                    SoldUnits = Product.SoldUnits,
                    StateProduct = Product.StateProduct,
                    ImageProduct = Product.ImageProduct
                }).FirstOrDefault();
            }
            catch (Exception EX)
            {
            }
            finally
            {
                BDMP.Dispose();
            }

            return(idprocupbo);
        }
Esempio n. 8
0
        public ProductBE SetProduct(ProductBE objProductBE)
        {
            try
            {
                product dbProduct = new product();
                dbProduct.id            = objProductBE.Id;
                dbProduct.title         = objProductBE.Title;
                dbProduct.description   = objProductBE.Description;
                dbProduct.price         = objProductBE.Price;
                dbProduct.image         = objProductBE.Image;
                dbProduct.active        = true;
                dbProduct.idUserCreated = objProductBE.UserId;
                dbProduct.dateCreated   = DateTime.Now;

                db.products.InsertOnSubmit(dbProduct);
                db.SubmitChanges();

                objProductBE.Id = dbProduct.id;
                return(objProductBE);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// To Translate Product to ProductBE
        /// </summary>
        /// <param name="productDE"></param>
        /// <returns></returns>
        public ProductBE Translate(Product productDE)
        {
            if (productDE != null)
            {
                ProductBE productBE = new ProductBE()
                {
                    ProductId    = productDE.ProductId,
                    ProductName  = productDE.ProductName,
                    ProductPrice = productDE.ProductPrice,
                    CategoryId   = productDE.CategoryId,
                    Category     = new CategoryBE()
                };

                if (productDE.Category != null)
                {
                    CategoryTranslator categoryTranslator = new CategoryTranslator();
                    productBE.Category = categoryTranslator.Translate(productDE.Category);
                }

                return(productBE);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// get a product by productid
        /// </summary>
        /// <param name="productid">The productid.</param>
        /// <returns></returns>
        public ProductBE GetById(int productid)
        {
            ProductManager _productManager = new ProductManager();
            ProductBE      productBE       = _productManager.GetById(productid);

            return(productBE);
        }
Esempio n. 11
0
        public List <ProductBE> ProductViewById(int productId)
        {
            List <ProductBE> res  = new List <ProductBE>();
            string           wsql = "SELECT * FROM Product where productid = " + productId.ToString();

            using (DbConnection connection = database.CreateOpenConnection())
            {
                using (DbCommand command = database.CreateCommand(wsql, connection))
                {
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Console.WriteLine(reader["DES_PERFIL"]);
                            ProductBE pcBe = new ProductBE();
                            pcBe.ProductId   = Convert.ToInt32(reader["PRODUCTID"]);
                            pcBe.ProductName = Convert.ToString(reader["PRODUCT"]);
                            pcBe.Price       = Convert.ToDecimal(reader["PRICE"]);
                            pcBe.Count       = Convert.ToInt32(reader["COUNT"]);
                            pcBe.Description = Convert.ToString(reader["DESCRIPTION"]);
                            res.Add(pcBe);
                        }
                    }
                }
            }
            return(res);
        }
Esempio n. 12
0
        public ProductBE <Product> Get()
        {
            var result = new ProductBE <Product>();

            result.Product = _service.GetAllAsync().Result.ToArray();

            return(result);
        }
        public AnswerResponseBE UpdateCupboard(ProductBE UPPROD)
        {
            AnswerResponseBE AR = new AnswerResponseBE();
            ProductLogic     PL = new ProductLogic();

            AR = PL.UpdateProduct(UPPROD);
            return(AR);
        }
        public AnswerResponseBE InsertProduct(ProductBE IPROD)
        {
            AnswerResponseBE AR = new AnswerResponseBE();
            ProductLogic     PL = new ProductLogic();

            AR = PL.InsertProduct(IPROD);
            return(AR);
        }
Esempio n. 15
0
        /// <summary>
        /// Insert a product
        /// </summary>
        /// <param name="dbEntity">The db entity.</param>
        /// <param name="Product">The product.</param>
        public bool Insert(TTAEntityContainer dbEntity, ProductBE Product)
        {
            ProductTranslator productTranslator = new ProductTranslator();
            Product           productDE         = productTranslator.Translate(Product);

            dbEntity.AddToProducts(productDE);
            dbEntity.SaveChanges();
            return(true);
        }
Esempio n. 16
0
 public ProductBE UpdateProduct(ProductBE objProductBE)
 {
     try
     {
         return(objProductDA.UpdateProduct(objProductBE));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 17
0
        public void TestSetProduct()
        {
            var obj = new ProductBE();

            obj.Description = "Camiseta Real Madrid 19/20";
            obj.Title       = "Camiseta Real Madrid 19/20";
            obj.Price       = 199;
            obj.UserId      = 0;

            obj = objProductDA.SetProduct(obj);
            Assert.Equals(2, obj.Id);
        }
Esempio n. 18
0
        public async Task <IActionResult> Get([FromRoute] int id)
        {
            var result = new ProductBE <Product>();
            var prd    = await _service.GetAsync(id);

            if (prd == null)
            {
                return(NotFound());
            }
            result.Product = new Product[] { prd };

            return(Ok(result));
        }
Esempio n. 19
0
        /// <summary>
        /// Inserts the product.
        /// </summary>
        /// <param name="productBE">The product BE.</param>
        public void InsertProduct()
        {
            ProductBE productBE = new ProductBE();

            productBE.ProductName  = View.ProductName;
            productBE.ProductPrice = View.ProductPrice;
            productBE.CategoryId   = View.CategoryId;
            CategoryBE categoryBE = new CategoryBE();

            categoryBE.CategoryId = View.CategoryId;
            productBE.Category    = categoryBE;
            _controller.InsertProduct(productBE);
        }
Esempio n. 20
0
        /// <summary>
        /// Updates the product. --by Will
        /// </summary>
        /// <param name="productBE">The product BE.</param>
        /// <returns></returns>
        public bool UpdateProduct(ProductBE productBE)
        {
            UpdateProductRequest request = new UpdateProductRequest();

            request.product = productBE;
            UpdateProductResponse response = MyChannelFactory.CreateChannel().UpdateProduct(request);

            if (response.IsFailed)
            {
                throw (new Exception(response.Message));
            }
            return(!response.IsFailed);
        }
Esempio n. 21
0
        /// <summary>
        /// update product
        /// </summary>
        /// <param name="dbEntity">The db entity.</param>
        /// <param name="pro">The pro.</param>
        public bool Update(TTAEntityContainer dbEntity, ProductBE pro)
        {
            ProductTranslator productTranslator = new ProductTranslator();
            Product           productDE         = productTranslator.Translate(pro);

            Product product = (from Product p in dbEntity.Products where p.ProductId == productDE.ProductId select p).SingleOrDefault <Product>();

            product.ProductName  = productDE.ProductName;
            product.ProductPrice = productDE.ProductPrice;
            product.CategoryId   = productDE.CategoryId;

            dbEntity.SaveChanges();
            return(true);
        }
Esempio n. 22
0
        /// <summary>
        /// GetAllProducts
        /// </summary>
        /// <returns></returns>
        public List <ProductBE> GetAllProducts()
        {
            this.DBEntity = new TTAEntityContainer();
            ProductTranslator productTranslator = new ProductTranslator();

            List <Product>   list          = (from Product Product in DBEntity.Products select Product).ToList <Product>();
            List <ProductBE> listProductBE = new List <ProductBE>();

            foreach (Product productDE in list)
            {
                ProductBE productBE = productTranslator.Translate(productDE);
                listProductBE.Add(productBE);
            }
            return(listProductBE);
        }
Esempio n. 23
0
        public void TestUpdateProduct()
        {
            var obj = new ProductBE();

            obj.Id          = 2;
            obj.Description = "Camiseta Real Madrid 20/21";
            obj.Title       = "Camiseta Real Madrid 20/21";
            obj.Price       = 200;
            obj.Image       = "https://drive.google.com/file/d/1bWHAee9tBk3wDK74_KXBgWPXpWwqr0oK/view?usp=sharing";
            obj.Active      = false;
            obj.UserId      = 0;

            obj = objProductDA.UpdateProduct(obj);
            Assert.Equals(2, obj.Id);
        }
Esempio n. 24
0
        /// <summary>
        /// Updates the product. --by Will
        /// </summary>
        /// <param name="productBE">The product BE.</param>
        /// <returns></returns>
        public bool UpdateProduct(ProductBE productBE)
        {
            UpdateProductRequest request = new UpdateProductRequest();

            request.product = productBE;
            UpdateProductResponse response = MyChannelFactory.CreateChannel().UpdateProduct(request);

            if (response.IsFailed)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("error", new Exception(response.Message));
                log.Fatal("fatal", new Exception(response.Message));
                throw (new Exception(response.Message));
            }
            return(!response.IsFailed);
        }
Esempio n. 25
0
        /// <summary>
        /// Updates the product.
        /// </summary>
        /// <param name="productBE">The product BE.</param>
        public void UpdateProduct()
        {
            ProductBE product = new ProductBE();

            product.ProductId    = View.ProductId;
            product.ProductName  = View.ProductName;
            product.ProductPrice = View.ProductPrice;
            product.CategoryId   = View.CategoryId;

            CategoryBE category = new CategoryBE();

            category.CategoryId = View.CategoryId;
            product.Category    = category;

            _controller.UpdateProduct(product);
        }
Esempio n. 26
0
        public AnswerResponseBE InsertProduct(ProductBE IPROD)
        {
            AnswerResponseBE     AR   = new AnswerResponseBE();
            MasterProductContext BDMP = new MasterProductContext();

            try
            {
                int CountProd = 0;
                CountProd = BDMP.Product.Where(x => x.IdProduct == IPROD.IdProduct).ToList().Count();
                if (CountProd == 0)
                {
                    Product PROD = new Product();
                    PROD.IdProduct         = IPROD.IdProduct;
                    PROD.NameProduct       = IPROD.NameProduct;
                    PROD.Properties        = IPROD.Properties;
                    PROD.ReleaseDate       = IPROD.ReleaseDate;
                    PROD.ManufacturerEmail = IPROD.ManufacturerEmail;
                    PROD.IdCountry         = IPROD.IdCountry;
                    PROD.Cost           = IPROD.Cost;
                    PROD.UnitsAvailable = IPROD.UnitsAvailable;
                    PROD.SoldUnits      = IPROD.SoldUnits;
                    PROD.StateProduct   = IPROD.StateProduct;
                    PROD.ImageProduct   = IPROD.ImageProduct;

                    BDMP.Product.Add(PROD);
                    BDMP.SaveChanges();

                    AR.CodeError        = 0;
                    AR.DescriptionError = "Se ha insertado el producto correctamente";
                }
                else
                {
                    AR.CodeError        = 2;
                    AR.DescriptionError = "El producto ya existe, por favor verifique la información";
                }
            }
            catch (Exception EX)
            {
                AR.CodeError        = 1;
                AR.DescriptionError = "Hubo un error";
            }
            finally
            {
                BDMP.Dispose();
            }
            return(AR);
        }
Esempio n. 27
0
        /// <summary>
        /// To Translate ProductBE to Product
        /// </summary>
        /// <param name="productBE"></param>
        /// <returns></returns>
        public Product Translate(ProductBE productBE)
        {
            if (productBE != null)
            {
                Product productDE = new Product();
                productDE.ProductId    = productBE.ProductId;
                productDE.ProductName  = productBE.ProductName;
                productDE.ProductPrice = productBE.ProductPrice;
                productDE.CategoryId   = productBE.Category.CategoryId;

                return(productDE);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 28
0
 /// <summary>
 /// jump to update page by productid
 /// </summary>
 /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param>
 protected void Update(RepeaterCommandEventArgs e)
 {
     if (e.CommandArgument != null)
     {
         int       productid      = Convert.ToInt32(e.CommandArgument);
         Proxy     productService = new Proxy();
         ProductBE product        = productService.GetProductById(productid);
         if (product == null)
         {
             Page.ClientScript.RegisterStartupScript(typeof(string), string.Empty, "alert('we don\\'t have this product!');location='ProductList.aspx';", true);
         }
         else
         {
             Response.Redirect("UpdateProduct.aspx?productid=" + productid);
         }
     }
 }
Esempio n. 29
0
        public AnswerResponseBE UpdateProduct(ProductBE UPROD)
        {
            AnswerResponseBE     AR   = new AnswerResponseBE();
            MasterProductContext BDMP = new MasterProductContext();

            try
            {
                Product product = new Product();
                product = BDMP.Product.Where(x => x.IdProduct == UPROD.IdProduct).FirstOrDefault();
                if (product != null)
                {
                    product.IdProduct         = UPROD.IdProduct;
                    product.NameProduct       = UPROD.NameProduct;
                    product.Properties        = UPROD.Properties;
                    product.ReleaseDate       = UPROD.ReleaseDate;
                    product.ManufacturerEmail = UPROD.ManufacturerEmail;
                    product.IdCountry         = UPROD.IdCountry;
                    product.Cost           = UPROD.Cost;
                    product.UnitsAvailable = UPROD.UnitsAvailable;
                    product.SoldUnits      = UPROD.SoldUnits;
                    product.StateProduct   = UPROD.StateProduct;
                    product.ImageProduct   = UPROD.ImageProduct;

                    BDMP.SaveChanges();

                    AR.CodeError        = 0;
                    AR.DescriptionError = "Se ha actualizado el producto correctamente";
                }
                else
                {
                    AR.CodeError        = 2;
                    AR.DescriptionError = "El registro no existe, por favor verifique la información";
                }
            }
            catch (Exception EX)
            {
                AR.CodeError        = 1;
                AR.DescriptionError = "Hubo un error";
            }
            finally
            {
                BDMP.Dispose();
            }
            return(AR);
        }
Esempio n. 30
0
        public List <ProductBE> GetAllProducts()
        {
            List <ProductBE> products = new List <ProductBE>();
            DataSet          dsResult = new DataSet();

            using (_connection = new SqlConnection(_connectionString))
            {
                var query = "SELECT * FROM Product";
                _command = new SqlCommand(query, _connection);//command object
                try
                {
                    _connection.Open();
                    SqlCommand     command = new SqlCommand(query, _connection);
                    SqlDataAdapter da      = new SqlDataAdapter(_command);
                    da.Fill(dsResult);

                    foreach (DataRow rows in dsResult.Tables[0].Rows)
                    {
                        ProductBE product = new ProductBE();
                        product.ProductId    = Convert.ToInt32(rows["ProductId"]);
                        product.ProductName  = Convert.ToString(rows["ProductName"]);
                        product.CategoryId   = Convert.ToInt32(rows["CategoryId"]);
                        product.UnitPrice    = Convert.ToDecimal(rows["UnitPrice"]);
                        product.UnitsInStock = Convert.ToInt32(rows["UnitsInStock"]);
                        product.UnitsOnOrder = Convert.ToInt32(rows["UnitsOnOrder"]);
                        product.ReorderLevel = Convert.ToInt32(rows["ReorderLevel"]);
                        product.Discontinued = Convert.ToBoolean(rows["Discontinued"]);

                        //Adding object to the list
                        //dsResult.Add(product);
                        products.Add(product);
                    }
                    _connection.Close();
                    return(products);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }