Ejemplo n.º 1
0
        public void UpdateView(DtoProduct product)
        {
            var dbProduct = ProductRepository.GetProductById(product.Id);

            dbProduct.Views = product.Views;
            ProductRepository.Save(ref dbProduct);
        }
Ejemplo n.º 2
0
        private void btnKiemTra_Click(object sender, EventArgs e)
        {
            if (nguoiLapPhieuComboBox.SelectedValue == null ||
                nguoiLapPhieuComboBox.SelectedValue.ToString().IsEmpty())
            {
                MessageBox.Show("Không được để trống người lập phiếu");
                return;
            }
            for (int i = 0; i < dgvDetailDeliveryBill.Rows.Count - 1; i++)
            {
                if (dgvDetailDeliveryBill.Rows[i].Cells[0].Value == null ||
                    dgvDetailDeliveryBill.Rows[i].Cells[1].Value == null ||
                    dgvDetailDeliveryBill.Rows[i].Cells[3].Value == null)
                {
                    MessageBox.Show("Không được để trống mã chi tiết phiếu nhập kho, sản phẩm, số lượng");
                    return;
                }

                DtoProduct dto = _bllProduct.GetProductByID(dgvDetailDeliveryBill.Rows[i].Cells[1].Value.ToString());
                if (dto.SoLuong < int.Parse(dgvDetailDeliveryBill.Rows[i].Cells[3].Value.ToString()))
                {
                    MessageBox.Show(String.Format("Kho không có đủ sản phẩm {0}, kho con {1} san pham", dto.TenSanPham, dto.SoLuong));
                    return;
                }
            }
            MessageBox.Show("OK!");
            btnThem.Enabled = true;

            txtTotal.Text = SumTotal().ToString();
        }
Ejemplo n.º 3
0
        public void AddNew(Product product)
        {
            IDalProduct DAL = DalFactory.CreateProductDal();
            DtoProduct  DTO = product.ToDTO();

            DAL.Insert(DTO);
        }
Ejemplo n.º 4
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (!CheckTextBox())
            {
                return;
            }
            DtoProduct data = new DtoProduct(
                txtMaSanPham.Text,
                txtTenSanPham.Text,
                txtLoaiSanPham.Text,
                int.Parse(txtThoiGianBaoHanh.Text),
                double.Parse(txtDonGiaNhap.Text),
                double.Parse(txtDonGiaBan.Text),
                int.Parse(txtSoLuong.Text),
                txtDonViTinh.Text,
                txtGhiChu.Text);

            if (_bllProduct.AddProduct(data))
            {
                MessageBox.Show(Constants.MsgNotificationSuccessfuly);
                btnLuu.Enabled = false;
            }
            else
            {
                MessageBox.Show(Constants.MsgAlreadyExist);
            }
            txtMaSanPham.Enabled = false;
            btnLamTuoi.PerformClick();
        }
Ejemplo n.º 5
0
        public DtoProduct GetProductByIDTest([PexAssumeUnderTest] DalProduct target, string id)
        {
            DtoProduct result = target.GetProductByID(id);

            return(result);
            // TODO: add assertions to method DalProductTest.GetProductByIDTest(DalProduct, String)
        }
Ejemplo n.º 6
0
        public DtoProduct GetById(int id)
        {
            DtoProduct product = new DtoProduct();

            try
            {
                using (SqlConnection connection = this.connection.CreateConnection())
                {
                    string Querry = "select * from Products where Id=@id";
                    using (SqlCommand command = new SqlCommand(Querry, connection))
                    {
                        connection.Open();
                        command.Parameters.AddWithValue("@id", id);
                        var reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            DtoProduct newProduct = new DtoProduct
                            {
                                Id           = reader.GetInt32(0),
                                Titel        = reader.GetString(1),
                                Prijs        = reader.GetDecimal(2),
                                Omschrijving = reader.GetString(3)
                            };
                            product = newProduct;
                        }
                    }
                }
            }
            catch (SqlException se)
            {
                Console.Write(se.Message);
            }
            return(product);
        }
Ejemplo n.º 7
0
        public void Update(DtoProduct product)
        {
            try
            {
                using (SqlConnection connection = this.connection.CreateConnection())
                {
                    string Querry = "UPDATE Products SET Titel = @titel, Prijs = @prijs, Omschrijving = @omschrijving Where Id = @id";
                    using (SqlCommand command = new SqlCommand(Querry, connection))
                    {
                        connection.Open();

                        command.Parameters.AddWithValue("@id", product.Id);
                        command.Parameters.AddWithValue("@titel", product.Titel);
                        command.Parameters.AddWithValue("@prijs", product.Prijs);
                        command.Parameters.AddWithValue("@omschrijving", product.Omschrijving);

                        command.CommandType = CommandType.Text;
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException se)
            {
                Console.Write(se.Message);
            }
        }
Ejemplo n.º 8
0
        public List <DtoProduct> GetAll()
        {
            List <DtoProduct> products = new List <DtoProduct>();

            try
            {
                using (SqlConnection connection = this.connection.CreateConnection())
                {
                    string Querry = "select * from Products";
                    using (SqlCommand command = new SqlCommand(Querry, connection))
                    {
                        connection.Open();
                        var reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            DtoProduct newProduct = new DtoProduct
                            {
                                Id           = reader.GetInt32(0),
                                Titel        = reader.GetString(1),
                                Prijs        = reader.GetDecimal(2),
                                Omschrijving = reader.GetString(3)
                            };
                            products.Add(newProduct);
                        }
                    }
                }
            }
            catch (SqlException se)
            {
                Console.Write(se.Message);
            }
            return(products);
        }
        public int AddProduct(DtoProduct data)
        {
            SqlParameter[] para =
            {
                new SqlParameter("@MaSanPham",       data.MaSanPham),
                new SqlParameter("@TenSanPham",      data.TenSanPham),
                new SqlParameter("@LoaiSanPham",     data.LoaiSanPham),
                new SqlParameter("@ThoiGianBaoHanh", data.ThoiGianBaoHanh),
                new SqlParameter("@DonGiaNhap",      data.DonGiaNhap),
                new SqlParameter("@DonGiaBan",       data.DonGiaBan),
                new SqlParameter("@SoLuong",         data.SoLuong),
                new SqlParameter("@DonViTinh",       data.DonViTinh),
                new SqlParameter("@GhiChu",          data.GhiChu)
            };
            try
            {
                return(SqlHelper.ExecuteNonQuery(con, CommandType.StoredProcedure, "AddProduct",
                                                 para));
            }
            catch (SqlException e)
            {
                return(0);

                throw e;
            }
            catch (Exception e)
            {
                return(0);

                throw e;
            }
        }
Ejemplo n.º 10
0
 public Product(DtoProduct product)
 {
     id           = product.Id;
     titel        = product.Titel;
     omschrijving = product.Omschrijving;
     prijs        = product.Prijs;
 }
Ejemplo n.º 11
0
 public void updateProduct(DtoProduct product)
 {
     // Console.WriteLine(product.Name);
     this.dtoProduct = product;
     txtProduct.Text = product.Name;
     txtPrice.Text   = product.Price;
 }
        public int EditProduct(DtoProduct data)
        {
            SqlParameter[] para =
            {
                new SqlParameter("@MaSanPham",       data.MaSanPham),
                new SqlParameter("@TenSanPham",      data.TenSanPham),
                new SqlParameter("@LoaiSanPham",     data.LoaiSanPham),
                new SqlParameter("@ThoiGianBaoHanh", data.ThoiGianBaoHanh),
                new SqlParameter("@DonGiaNhap",      data.DonGiaNhap),
                new SqlParameter("@DonGiaBan",       data.DonGiaBan),
                new SqlParameter("@SoLuong",         data.SoLuong),
                new SqlParameter("@DonViTinh",       data.DonViTinh),
                new SqlParameter("@GhiChu",          data.GhiChu)
            };
            try
            {
                return(SqlHelper.ExecuteNonQuery(con, CommandType.StoredProcedure, "EditProduct",
                                                 para));
            }
            catch (SqlException)
            {
                return(0);

                throw new ArgumentException(Constants.MsgExceptionSql);
            }
            catch (Exception)
            {
                return(0);

                throw new AggregateException(Constants.MsgExceptionError);
            }
        }
Ejemplo n.º 13
0
        public Product GetByID(int id)
        {
            IDalProduct DAL        = DalFactory.CreateProductDal();
            DtoProduct  DtoProduct = DAL.GetById(id);
            Product     product    = new Product(DtoProduct);

            return(product);
        }
Ejemplo n.º 14
0
        public void Save(ref DtoProduct product)
        {
            var repo = product.ToRepository();

            if (product.Producer != null)
            {
                product.Producer = Save(product.Producer);
                repo.Producer_Id = product.Producer.Id;
            }

            if (repo.Id == 0)
            {
                repo.Id = Insert(repo, "Product");
            }
            else
            {
                Update(repo, "Product");
            }


            if (product.Categories != null && product.Categories?.Count > 0)
            {
                product.Categories = Save(product.Categories);
                if (product.Categories != null)
                {
                    foreach (var item in product.Categories)
                    {
                        InsertFk("Product_id", product.Id, "Category_id", item.Id, "CategoryToProduct");
                    }
                }
            }

            if (product.Skus != null && product.Skus?.Count > 0)
            {
                foreach (var sku in product.Skus)
                {
                    sku.ProductReference = product;
                }
                product.Skus = Save(product.Skus);
            }

            if (product.Principles != null && product.Principles?.Count > 0)
            {
                product.Principles = Save(product.Principles);
                if (product.Principles != null)
                {
                    foreach (var item in product.Principles)
                    {
                        InsertFk("Product_id", product.Id, "Principle_id", item.Id, "PrincipleToProduct");
                    }
                }
            }



            product = FillProduct(repo);
        }
Ejemplo n.º 15
0
 public bool EditProduct(DtoProduct data)
 {
     try
     {
         return(_dalProduct.EditProduct(data) == 1 ? true : false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 16
0
        public async Task <IActionResult> PutAsync([FromBody] DtoUpdateProduct model)
        {
            try
            {
                DtoProduct product = await service.UpdateAsync(model);

                return(Ok(product));
            }
            catch
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 17
0
 private void dgvDetailDeliveryBill_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         var s = dgvDetailDeliveryBill.CurrentRow.Cells[1].Value.ToString();
         if (!s.IsEmpty() || s != null)
         {
             DtoProduct dto = _bllProduct.GetProductByID(s);
             dgvDetailDeliveryBill.CurrentRow.Cells[2].Value = dto.DonGiaNhap;
         }
     }
     catch (Exception)
     {
     }
 }
        public ActionResult UpdateView(DtoProduct product)
        {
            ProductDomain.UpdateView(product);
            List <DtoProduct> model = null;

            if (ViewBag.Query != null)
            {
                model = ProductDomain.GetProductLike(ViewBag.Query, ViewBag.Page, ViewBag.Size);
            }
            else
            {
                model = ProductDomain.GetProductOrderByRank(ViewBag.Page ?? 0, ViewBag.Size ?? 50);
            }
            return(View("Ranking", model));
        }
Ejemplo n.º 19
0
        public IActionResult PaginateSorting([FromBody] DtoPaginationAndSorting dto)
        {
            bool isSortingListValid = true;

            if (dto.SortingList != null)
            {
                isSortingListValid = SortingListValidator <DtoProduct> .Validate(dto.SortingList);
            }

            if (isSortingListValid)
            {
                return(new OkObjectResult(_useCasePagSort
                                          .PaginateSorting(dto.PageNumber, dto.TotalPageNumber, dto.SortingList)
                                          .Select(domainEntity => DtoProduct.DomainEntityToDto(domainEntity))));
            }
            return(new BadRequestResult());
        }
        public IActionResult Filter([FromBody] DtoFilter dtoFilter)
        {
            List <string> list = new List <string>();

            if (dtoFilter.FilterList != null)
            {
                list = dtoFilter.FilterList.Where(data => (data.Contains("=") &&
                                                           FilterListValidator <DtoProduct> .Validate(data))).ToList();
            }

            if (list.Count > 0)
            {
                return(new OkObjectResult(_useCaseFilter.Filter(list)
                                          .Select(domainEntity =>
                                                  DtoProduct.DomainEntityToDto(domainEntity))));
            }
            return(new BadRequestResult());
        }
        public static DtoProduct ToDTO(this Repository.Model.Products.Product model)
        {
            if (model == null)
            {
                return(null);
            }
            var dto = new DtoProduct()
            {
                Id         = model.Id,
                Name       = model.Name,
                NeedRecipe = model.NeedRecipe,
                Serving    = model.Serving,
                Type       = model.Type,
                Views      = model.Views
            };

            return(dto);
        }
Ejemplo n.º 22
0
        public DtoProduct GetProductByID(string id)
        {
            DataTable dt = SqlHelper.ExecuteDataset(Constants.ConnectionString, CommandType.Text,
                                                    "select * from SANPHAM where MaSanPham = @MaSanPham", new SqlParameter("@MaSanPham", id)).Tables[0];
            DtoProduct dto = new DtoProduct(
                dt.Rows[0].ItemArray[0].ToString(),
                dt.Rows[0].ItemArray[1].ToString(),
                dt.Rows[0].ItemArray[2].ToString(),
                int.Parse(dt.Rows[0].ItemArray[3].ToString()),
                double.Parse(dt.Rows[0].ItemArray[4].ToString()),
                double.Parse(dt.Rows[0].ItemArray[5].ToString()),
                int.Parse(dt.Rows[0].ItemArray[6].ToString()),
                dt.Rows[0].ItemArray[7].ToString(),
                dt.Rows[0].ItemArray[8].ToString()
                );

            return(dto);
        }
        public static Products.Product ToRepository(this DtoProduct dto)
        {
            if (dto == null)
            {
                return(null);
            }
            var model = new Products.Product()
            {
                Id          = dto.Id,
                Name        = dto.Name,
                NeedRecipe  = dto.NeedRecipe,
                Serving     = dto.Serving,
                Views       = dto.Views,
                Type        = dto.Type,
                Producer_Id = dto.Producer?.Id
            };

            return(model);
        }
Ejemplo n.º 24
0
        public IActionResult Filter([FromBody] DtoFilterPaginationSorting dto)
        {
            bool isValid = false;

            if (dto.SortingList != null && dto.FilterList != null)
            {
                isValid = dto.FilterList.All(data => data.Contains("=") &&
                                             FilterListValidator <DtoProduct> .Validate(data) &&
                                             SortingListValidator <DtoProduct> .Validate(dto.SortingList));
            }

            if (isValid)
            {
                var list = _useCaseFilterLike.FilterSorting(dto.PageNumber, dto.TotalPageNumber,
                                                            dto.FilterList, dto.SortingList);

                return(new OkObjectResult(list.Select(domainEntity =>
                                                      DtoProduct.DomainEntityToDto(domainEntity))));
            }
            return(new BadRequestResult());
        }
Ejemplo n.º 25
0
        private void dgvProduct_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            String id          = (dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[0].Value.ToString() == null)?"": dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[0].Value.ToString();
            String gender      = (dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[1].Value.ToString() == null)?"": dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[1].Value.ToString();
            String editorial   = (dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[2].Value.ToString() == null)?"": dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[2].Value.ToString();
            String precio      = (dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[3].Value.ToString() == null)?"": dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[3].Value.ToString();
            String name        = (dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[4].Value.ToString() == null)?"": dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[4].Value.ToString();
            String description = (dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[5].Value.ToString() == null)?"": dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[5].Value.ToString();
            String stock       = (dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[6].Value.ToString() == null)?"": dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[6].Value.ToString();

            DtoProduct dtoProduct = new DtoProduct(id, gender, editorial, precio, name, description, stock);

            if (observer != null)
            {
                observer.updateProduct(dtoProduct);
                Dispose();
            }
            if (observerMod != null)
            {
                observerMod.updateProduct(dtoProduct);
                Dispose();
            }
        }
Ejemplo n.º 26
0
        public void Insert(DtoProduct product)
        {
            try
            {
                using (SqlConnection connection = this.connection.CreateConnection())
                {
                    string Querry = "insert into Products ( Titel, Prijs, Omschrijving) values(@titel,@prijs,@omschrijving)";
                    using (SqlCommand command = new SqlCommand(Querry, connection))
                    {
                        connection.Open();

                        command.Parameters.AddWithValue("@titel", product.Titel);
                        command.Parameters.AddWithValue("@prijs", product.Prijs);
                        command.Parameters.AddWithValue("@omschrijving", product.Omschrijving);
                        command.CommandType = CommandType.Text;
                        int rowsAdded = command.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException se)
            {
                Console.Write(se.Message);
            }
        }
Ejemplo n.º 27
0
        public List <DtoProduct> GetProductsInCategorie(int categorieId)
        {
            List <DtoProduct> productDTOs = new List <DtoProduct>();

            try
            {
                using (SqlConnection connection = this.connection.CreateConnection())
                {
                    string Querry = "SELECT Products.Id,Products.Titel,Products.Prijs,Products.Omschrijving FROM Products LEFT JOIN Categorie_Product ON Categorie_Product.ProductId = Products.Id AND Categorie_Product.CategorieId = @id WHERE CategorieId IS NOT NULL ORDER BY Id";
                    using (SqlCommand command = new SqlCommand(Querry, connection))
                    {
                        connection.Open();

                        command.Parameters.AddWithValue("@id", categorieId);

                        var reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            DtoProduct newProduct = new DtoProduct
                            {
                                Id           = reader.GetInt32(0),
                                Titel        = reader.GetString(1),
                                Prijs        = reader.GetDecimal(2),
                                Omschrijving = reader.GetString(3)
                            };
                            productDTOs.Add(newProduct);
                        }
                    }
                }
            }
            catch (SqlException se)
            {
                Console.Write(se.Message);
            }
            return(productDTOs);
        }
Ejemplo n.º 28
0
 public string Put(int id, [FromBody] DtoProduct dtoProduct)
 {
     _useCaseProduct.Update(id, dtoProduct.DtoToDomainEntity());
     return("Updated");
 }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Init DB Session");
            Console.ForegroundColor = ConsoleColor.Gray;
            new IhChegou.Repository.Query.ProductQueries();

            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine("Searching...");
            Console.ForegroundColor = ConsoleColor.White;

            const string URL_BASE = "https://consultaremedios.com.br";
            const string URL_LISTA_MEDICAMENTOS = URL_BASE + "/medicamentos";

            var errorUrl = new ConcurrentBag <string>();


            var client = new WebClient();

            client.Encoding = Encoding.UTF8;

            var response = client.DownloadString(URL_LISTA_MEDICAMENTOS);

            var document = new HtmlDocument();

            document.LoadHtml(response);

            var letters = document.DocumentNode.SelectNodes("//*[@id=\"letras\"]/div/div/div/div/div[2]/*").Select(i => i.GetAttributeValue("href", ""));

            var prodUrls = new List <string>();

            foreach (var item in letters)
            {
                var prodUrl = new List <string>();
                int page    = 1;
                do
                {
                    response = client.DownloadString(URL_BASE + item + "?pagina=" + page);
                    document = new HtmlDocument();
                    document.LoadHtml(response);
                    prodUrl = document.DocumentNode.SelectNodes("//*[@class=\"product-block__title\"]/a")?.Select(i => i.GetAttributeValue("href", ""))?.ToList();
                    if (prodUrl != null)
                    {
                        prodUrls.AddRange(prodUrl);
                    }
                    page++;
                } while (prodUrl != null && prodUrl?.Count() != 0);
            }

            //  var nodes = documents[0].DocumentNode.SelectNodes("//div[@class='item col-xs-12 col-sm-4 col-md-3']");


            // Parallel.ForEach(nodes, new ParallelOptions { MaxDegreeOfParallelism = 1 }, (nod) =>
            foreach (var prodUrl in prodUrls)
            {
                var ProdResponse    = client.DownloadString(URL_BASE + prodUrl);
                var productDocument = new HtmlDocument();
                productDocument.LoadHtml(ProdResponse);


                var query = new IhChegou.Repository.Query.ProductQueries();

                var product = new DtoProduct();
                product.Name = HttpUtility.HtmlDecode(productDocument.DocumentNode.SelectSingleNode("//*[@class=\"product-header__title\"]").InnerText);

                try
                {
                    product.Serving = HttpUtility.HtmlDecode(productDocument.DocumentNode.SelectSingleNode("//*[@id=\"indication-collapse\"]").InnerText);



                    var producerName = productDocument.DocumentNode.SelectSingleNode("//*[@class=\"cr-icon-factory product-block__meta-icon\"]/..").InnerText;

                    var producer = query.GetAllProducers().Where(i => i.Name == producerName).SingleOrDefault();
                    if (producer == null)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkMagenta;
                        Console.WriteLine("New Producer - " + producerName);
                        producer = new DtoProducer()
                        {
                            Name = producerName
                        };
                        query.Save(ref producer);
                    }
                    product.Producer = producer;

                    var dbProduct = query.GetProductByNameAndProducer(product.Name, product.Producer);
                    if (dbProduct != null)
                    {
                        product = dbProduct;
                    }
                    else
                    {
                        Console.WriteLine("New Product - " + product.Name);
                    }

                    var skuUrls = productDocument.DocumentNode.SelectNodes("//*[@class=\"presentation-offer-info__description\"]/a")?.Select(i => i.GetAttributeValue("href", ""))?.ToList();

                    foreach (var skuUrl in skuUrls)
                    {
                        var skuResponse  = client.DownloadString(URL_BASE + skuUrl);
                        var skutDocument = new HtmlDocument();
                        skutDocument.LoadHtml(skuResponse);

                        var infoNodes = skutDocument.DocumentNode.SelectNodes("//*[@class=\"extra-infos-block\"]");

                        if (skuUrls.IndexOf(skuUrl) == 0)
                        {
                            foreach (var infoNode in infoNodes)
                            {
                                switch (infoNode.FirstChild.InnerText)
                                {
                                case "Tipo do Medicamento":
                                    if (infoNode.LastChild.InnerText == "Referência")
                                    {
                                        product.Type = Global.Enumerators.ProductType.Reference;
                                    }
                                    if (infoNode.LastChild.InnerText == "Similar")
                                    {
                                        product.Type = Global.Enumerators.ProductType.Similar;
                                    }
                                    if (infoNode.LastChild.InnerText == "Genérico")
                                    {
                                        product.Type = Global.Enumerators.ProductType.Generic;
                                    }
                                    break;

                                case "Necessita de Receita":
                                    if (infoNode.SelectSingleNode("//*/b").InnerText == "Sim")
                                    {
                                        product.NeedRecipe = true;
                                    }
                                    break;

                                case "Princípio Ativo":
                                {
                                    var prodPrinciples = new List <DtoPrinciple>();

                                    var princepleText = infoNode.LastChild.InnerText.Split('+');

                                    if (princepleText.Length > 0)
                                    {
                                        foreach (var item in princepleText)
                                        {
                                            var principle = query.GetAllPrnciples().Where(i => i.Name == item).SingleOrDefault();

                                            if (principle == null)
                                            {
                                                Console.ForegroundColor = ConsoleColor.DarkYellow;
                                                Console.WriteLine("New Principle - " + item);
                                                principle = new DtoPrinciple()
                                                {
                                                    Name = item
                                                };
                                                query.Save(ref principle);
                                            }
                                            prodPrinciples.Add(principle);
                                        }
                                        foreach (var principle in prodPrinciples)
                                        {
                                            product.Principles = product.Principles ?? new List <DtoPrinciple>();
                                            if (product.Principles.FirstOrDefault(i => i.Id == principle.Id) == null)
                                            {
                                                product.Principles.Add(principle);
                                            }
                                        }
                                    }
                                }
                                break;
                                }
                            }
                            var categorias = productDocument.DocumentNode.SelectNodes("//*[@id='product-page']/div[1]/div/div[1]/div/div/nav/ul/li").Select(i => i.InnerText.Replace("\n", "")).ToList();

                            categorias.RemoveAt(categorias.IndexOf(categorias.FirstOrDefault()));
                            categorias.RemoveAt(categorias.IndexOf(categorias.LastOrDefault()));

                            var ProdCategories = new List <DtoCategory>();
                            foreach (var item in categorias)
                            {
                                var category = query.GetCategory(item);

                                if (category == null)
                                {
                                    Console.ForegroundColor = ConsoleColor.Cyan;
                                    Console.WriteLine("New Category - " + item);

                                    var position = categorias.IndexOf(item);
                                    category = new DtoCategory()
                                    {
                                        Name = item
                                    };
                                    if (position > 0)
                                    {
                                        var father = query.GetCategory(categorias[position - 1]);
                                        father.SubCategories = father.SubCategories ?? new List <DtoCategory>();
                                        father.SubCategories.Add(category);
                                        category = father;
                                    }
                                    query.Save(ref category);
                                }
                                category = query.GetCategory(item);
                                ProdCategories.Add(category);
                            }
                            foreach (var category in ProdCategories)
                            {
                                product.Categories = new List <DtoCategory>();
                                product.Categories.Add(query.GetCategory(category.Name));
                            }
                        }

                        var newSku = new DtoSku
                        {
                            Image = skutDocument.DocumentNode.SelectSingleNode("//*[@class=\"product-header__beauty-image\"]/img")?.GetAttributeValue("src", ""),
                            Name  = skutDocument.DocumentNode.SelectSingleNode("//*[@id=\"product-page\"]/div[1]/div/div[2]/div[2]/h1").InnerText,
                        };
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        var dbsku = product.Skus?.FirstOrDefault(i => i.Name == newSku.Name);
                        if (dbsku == null)
                        {
                            Console.WriteLine("New Sku - " + newSku.Name);
                        }
                        else
                        {
                            newSku.Id = dbsku.Id;
                        }
                        product.Skus = product.Skus ?? new List <DtoSku>();
                        if (product.Skus.Where(i => i.Id == newSku.Id).Count() > 0)
                        {
                            product.Skus.Remove(product.Skus.Where(i => i.Id == newSku.Id).SingleOrDefault());
                        }
                        product.Skus.Add(newSku);
                    }
                    Console.ForegroundColor = ConsoleColor.Green;

                    query.Save(ref product);
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"- {ex.Message} -{ ex.InnerException?.Message}");
                    Console.ResetColor();
                }
            }
            //});

            var writer = new StreamWriter("errorList.json");

            writer.WriteLine(JsonConvert.SerializeObject(errorUrl));

            writer.Close();
        }
Ejemplo n.º 30
0
        public IEnumerable <DtoProduct> Paginate([FromBody] DtoPagination dto)
        {
            var list = _useCasePag.Paginate(dto.PageNumber, dto.TotalPageNumber);

            return(list.Select(domainEntity => DtoProduct.DomainEntityToDto(domainEntity)));
        }