예제 #1
0
        public IList <ProductFabric> UpdateProductFabric(List <ProductFabric> tasks)
        {
            var result  = new List <ProductFabric>();
            var command = dbContext.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "sp_ProductFabric_u";
            SqlParameter[] sqlParams = new SqlParameter[3];
            sqlParams[0] = new SqlParameter("@RowId", DbType.Int32);
            sqlParams[1] = new SqlParameter("@FabricName", DbType.String);
            sqlParams[2] = new SqlParameter("@Description", DbType.String);
            using (var transaction = new TransactionScope())
            {
                using (command.Connection)
                {
                    if (command.Connection.State == ConnectionState.Closed)
                    {
                        command.Connection.Open();
                    }
                    foreach (var item in tasks)
                    {
                        var data = new ProductFabric();
                        command.Parameters.Clear();
                        sqlParams[0].Value = (object)item.RowId;
                        sqlParams[1].Value = (object)item.FabricName;
                        sqlParams[2].Value = (object)item.Description;
                        command.Parameters.Add(sqlParams[0]);
                        command.Parameters.Add(sqlParams[1]);
                        command.Parameters.Add(sqlParams[2]);
                        try
                        {
                            command.ExecuteNonQuery();
                            data.RowId   = item.RowId;
                            data.Message = "";
                        }
                        catch (Exception ex)
                        {
                            data.RowId   = item.RowId;
                            data.Message = "Error while updating record.";
                        }
                        finally
                        {
                            result.Add(data);
                        }
                    }
                }
                transaction.Complete();
            }
            return(result);
        }
예제 #2
0
        public IActionResult AddProductFabric([FromBody] ProductFabric request)
        {
            var response = new OperationResponse <bool>();

            try
            {
                response.Data = _specificationService.AddProductFabric(request);
            }
            catch (Exception exception)
            {
                response.State = ResponseState.Error;
                response.Messages.Add(exception.Message);
                _logger.LogError(exception, "Error in AddProductFabric ==>" + exception.StackTrace, request);
            }
            return(new JsonResult(response));
        }
예제 #3
0
        public bool AddProductFabric(ProductFabric request)
        {
            int result;
            var command = dbContext.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "sp_ProductFabric_i";
            command.AddParameter("@FabricName", request.FabricName, DbType.String);
            command.AddParameter("@Description", request.Description, DbType.String);
            try
            {
                command.OpenConnection();
                result = command.ExecuteNonQuery();
            }
            finally
            {
                command.CloseConnection();
            }
            return(result > 0);
        }
예제 #4
0
        public List <ProductFabric> GetProductFabric(string QueryConditionPartParam)
        {
            List <ProductFabric> GridRecords = new List <ProductFabric>();
            var command = dbContext.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "sp_ProductFabric_Get";
            command.OpenConnection();
            var reader = command.OpenReader();

            while (reader.Read())
            {
                ProductFabric GridRecord = new ProductFabric()
                {
                    RowId       = reader.ValidateColumnExistExtractAndCastTo <int>("RowId"),
                    FabricName  = reader.ValidateColumnExistExtractAndCastTo <string>("FabricName"),
                    Description = reader.ValidateColumnExistExtractAndCastTo <string>("Description"),
                };
                GridRecords.Add(GridRecord);
            }
            ;
            command.CloseConnection();
            return(GridRecords);
        }
예제 #5
0
        public List <Product> GrabProducts(int amount)
        {
            List <Product> products = new List <Product>(amount);

            List <string> indexes = GrabIndexes();

            for (int i = 0; i < amount; i++)
            {
                string url  = ProductUrl.Replace("%", indexes[i]);
                var    page = new HtmlWeb().Load(url);

                Product product = new Product();

                //product.ProductId = i + 1;

                var element = page.DocumentNode.SelectSingleNode("//h1[@class='primary product-item-headline']");
                product.Name = element.InnerHtml;

                element       = page.DocumentNode.SelectSingleNode("//span[@class='price-value']");
                product.Price = Int32.Parse(FindNumbers(element.InnerText));

                //var elements = page.DocumentNode.SelectNodes("//div[contains(@class, 'product-colors')]//h3[@class='product-input-label']");
                product.Color = Colors[R.Next(0, 6)];

                product.Country = Countries[R.Next(0, 5)];

                element             = page.DocumentNode.SelectSingleNode("//p[@class='pdp-description-text']");
                product.Description = element.InnerHtml;

                element = page.DocumentNode.SelectSingleNode("//div[@class='product-detail-main-image-container']//img");
                var pictureUrl = element.GetAttributeValue("src", "");
                var request    = HttpWebRequest.Create("https:" + pictureUrl);
                var response   = request.GetResponse();
                var stream     = response.GetResponseStream();
                var reader     = new BinaryReader(stream);
                product.Picture = reader.ReadBytes((int)response.ContentLength);

                product.Sizes = new List <ProductSize>();
                for (int j = 32; j <= 46; j += 2)
                {
                    ProductSize size = new ProductSize();
                    size.ProductId = i + 1;
                    size.Size      = j;
                    size.Quantity  = R.Next(0, 20);

                    product.Sizes.Add(size);
                }

                product.Fabrics = new List <ProductFabric>();
                int number = R.Next(1, 4);
                int f      = R.Next(0, 8);
                for (int j = 1; j <= number; j++)
                {
                    ProductFabric fabric = new ProductFabric();
                    fabric.ProductId = i + 1;
                    fabric.Fabric    = Fabrics[f];
                    f++;

                    if (j != number)
                    {
                        fabric.Procentage = 25;
                    }
                    else
                    {
                        fabric.Procentage = 100 - (number - 1) * 25;
                    }

                    product.Fabrics.Add(fabric);
                }

                products.Add(product);
            }

            return(products);
        }