示例#1
0
        public void EditProductJustDocument()
        {
            var inizio = DateTime.Now;

            IDocumentRepository docRep = new DocumentRepository();
            IProductRepository prodRep = new ProductRepository();

            PapiroService p = new PapiroService();
            p.DocumentRepository = docRep;
            p.CostDetailRepository = new CostDetailRepository();
            p.TaskExecutorRepository = new TaskExecutorRepository();
            p.ArticleRepository = new ArticleRepository();

            Document doc = docRep.GetEstimateEcommerce("000001");
            doc.EstimateNumber = "0";

            DocumentProduct dp = docRep.GetDocumentProductsByCodProduct("").FirstOrDefault();

            //work with product
            Product prod = p.InitProduct("SuppRigidi", new ProductTaskNameRepository(), new FormatsNameRepository(), new TypeOfTaskRepository());

            //------passaggio del prodotto inizializzato all'ecommerce o alla view
            prod.CodProduct = prodRep.GetNewCode(prod);
            prod.ProductParts.FirstOrDefault().Format = "15x21";
            prod.ProductParts.FirstOrDefault().SubjectNumber = 1;

            var art = prod.ProductParts.FirstOrDefault().ProductPartPrintableArticles.FirstOrDefault();

            #region Printable Article

            IArticleRepository artRep = new ArticleRepository();
            var artFormList = artRep.GetAll().OfType<RigidPrintableArticle>().FirstOrDefault();

            art.TypeOfMaterial = artFormList.TypeOfMaterial;
            art.NameOfMaterial = artFormList.NameOfMaterial;
            art.Weight = artFormList.Weight;
            art.Color = artFormList.Color;
            #endregion

            //------ritorno del prodotto modificato!!!!

            //rigenero
            prodRep.Add(prod);
            prodRep.Save();

            #region ViewModel
            ProductViewModel pv = new ProductViewModel();
            pv.Product = prod;
            //            prod.ProductCodeRigen();

            pv.Quantity = 10;
            #endregion

            p.EditOrCreateAllCost(dp.CodDocumentProduct);

            var fine = DateTime.Now.Subtract(inizio).TotalSeconds;

            Assert.IsTrue(fine < 4);
        }
示例#2
0
        public void CloneObject()
        {
            IDocumentRepository docRep = new DocumentRepository();
            IProductRepository prodRep = new ProductRepository();
            ICostDetailRepository cdetRep = new CostDetailRepository();

            PapiroService p = new PapiroService();
            p.DocumentRepository = docRep;
            p.CostDetailRepository = cdetRep;

            p.DocumentRepository.SetDbName("castello");
            p.CostDetailRepository.SetDbName("castello");

            Document doc = docRep.GetSingle("00000J");
            var prod = docRep.GetDocumentProductsByCodProduct(doc.DocumentProducts.First().CodProduct).FirstOrDefault();

            DocumentProduct prod2 = (DocumentProduct)prod.Clone();
            prod2.CodDocumentProduct = "";
            prod2.Document = null;

            doc.DocumentProducts.Add(prod2);
            doc.DocumentProductsCodeRigen(true);

            p.DocumentRepository.Edit(doc);
            p.DocumentRepository.Save();

            p.DocumentRepository.SetDbName("castello");

            //array di sostituzione dei codici
            Dictionary<string, string> trans = new Dictionary<string, string>();
            foreach (var c in prod.Costs)
            {
                var y = p.CostDetailRepository.GetSingleSimple(c.CodCost);

                if (y != null)
                {
                    var x = (CostDetail)y.Clone();
                    x.CodCostDetail = x.CodCostDetail.Replace(prod.CodDocumentProduct, prod2.CodDocumentProduct);
                    x.CodCost = x.CodCostDetail;

                    x.CostDetailCostCodeRigen();

                    if (x.CodComputedBy != null)
                    {
                        x.CodComputedBy = x.CodComputedBy.Replace(prod.CodDocumentProduct, prod2.CodDocumentProduct);
                    }

                    p.CostDetailRepository.Add(x);
                }
            }

            p.CostDetailRepository.Save();


            doc = docRep.GetSingle("00000J");

            Console.WriteLine("");
        }