public HttpResponseMessage GetEmpty(string id) { try { id = "SuppRigidi"; PapiroService papiro = new PapiroService(); //work with product Product prod = papiro.InitProduct(id, new ProductTaskNameRepository(), new FormatsNameRepository(), new TypeOfTaskRepository()); return Request.CreateResponse<Product>(HttpStatusCode.OK, prod); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.InternalServerError); } }
public ActionResult CloneDocumentProduct(string codDocument, string codDocumentProduct, int newQuantity) { Document doc = documentRepository.GetSingle(codDocument); var codProduct = doc.DocumentProducts.FirstOrDefault(x => x.CodDocumentProduct == codDocumentProduct).CodProduct; var prod = documentRepository.GetDocumentProductsByCodProduct(codProduct).First(); if (newQuantity > 0) { PapiroService p = new PapiroService(); p.DocumentRepository = documentRepository; p.CostDetailRepository = costDetailRepository; //get product document and clone it DocumentProduct newProdDoc = (DocumentProduct)prod.Clone(); //with new quantity newProdDoc.Quantity = newQuantity; newProdDoc.CodDocumentProduct = ""; newProdDoc.Document = null; //the document product cloned is added to Document doc.DocumentProducts.Add(newProdDoc); //and all codes are regenerated doc.DocumentProductsCodeRigen(true); //keep new Code var newCodDocumentProduct = newProdDoc.CodDocumentProduct; p.DocumentRepository.Edit(doc); p.DocumentRepository.Save(); p.DocumentRepository.SetDbName(CurrentDatabase); //array di sostituzione dei codici Dictionary<string, string> trans = new Dictionary<string, string>(); //now we have to clone cost and add it in new DocumentProduct foreach (var c in prod.Costs) { //get cost var cost = p.CostDetailRepository.GetSingleSimple(c.CodCost); //if cost exist if (cost != null) { //clone it var newCost = (CostDetail)cost.Clone(); //get new CostCode by replace code part about CodDocumentProduct newCost.CodCostDetail = newCost.CodCostDetail.Replace(prod.CodDocumentProduct, newProdDoc.CodDocumentProduct); newCost.CodCost = newCost.CodCostDetail; newCost.CostDetailCostCodeRigen(); //if cost is computed by another one we have to fix the link if (newCost.CodComputedBy != null) { newCost.CodComputedBy = newCost.CodComputedBy.Replace(prod.CodDocumentProduct, newProdDoc.CodDocumentProduct); } p.CostDetailRepository.Add(newCost); } } //save all changes p.CostDetailRepository.Save(); //Updating //reset contentx p.CostDetailRepository.SetDbName(CurrentDatabase); foreach (var c in newProdDoc.Costs.OrderBy(x => x.CodCost)) { var cost = p.CostDetailRepository.GetSingle(c.CodCost); if (cost != null) { //TEMPORANEOOOOOOOOO //another important link to fix is the printer link //this for PrePressCost if (cost.TypeOfCostDetail == CostDetail.CostDetailType.ControlTableCostDetail || cost.TypeOfCostDetail == CostDetail.CostDetailType.PrePostPressCostDetail || cost.TypeOfCostDetail == CostDetail.CostDetailType.RepassRollCostDetail ) { //get ST codCost cost.CodPartPrintingCostDetail = p.DocumentRepository.GetCostsByCodDocumentProduct(cost.TaskCost.CodDocumentProduct).Where(y1 => y1.CodItemGraph == "ST").Select(z => z.CodCost); //if there is a ST if (cost.CodPartPrintingCostDetail != null) { //fix all links foreach (var item in cost.CodPartPrintingCostDetail) { var cv2 = p.CostDetailRepository.GetSingle(item); cost.Printers.Add(cv2); cv2.InitCostDetail(taskExecutorRepository.GetAll(), articleRepository.GetAll()); } } } //regen cost initialization cost.InitCostDetail(taskExecutorRepository.GetAll(), articleRepository.GetAll()); //and regen cost //DA RIMUOVERE if (cost.TaskCost.CostDetails.FirstOrDefault(x => x.CodCostDetail == cost.CodCostDetail) == null) { cost.TaskCost.CostDetails.Add(cost); } //******** cost.Update(); cost.TaskCost.Update(); p.CostDetailRepository.Add(cost); p.CostDetailRepository.Save(); } } //save all p.CostDetailRepository.Save(); doc = documentRepository.GetSingle(codDocument); newProdDoc = doc.DocumentProducts.FirstOrDefault(x => x.CodDocumentProduct == newCodDocumentProduct); newProdDoc.UpdateTotal(); p.DocumentRepository.Edit(doc); p.DocumentRepository.Save(); // end regen costs } return Json(new { redirectUrl = Url.Action("EditDocumentProducts", "Document", new { area = "Working", id = prod.CodProduct }) }); }
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); }
public async Task<ActionResult> CreateProduct(string id) { var p = new PapiroService(); p.ProductRepository = productRepository; p.CurrentDatabase = CurrentDatabase; var inizio = DateTime.Now; var c = p.InitProduct(id, prodTskNameRepository, formatsRepository, typeOfTaskRepository); var d = new ProductViewModel(); //controllo i dati di cliente e riferimento //cercando la session if (Session["CodDocument"] != null) { var doc = documentRepository.GetSingle((string)Session["CodDocument"]); d.DocumentName = doc.DocumentName; d.Customer = doc.Customer; } d.Product = c; // d.Quantities.Add(0); //view name is needed for reach right view because to using more than one submit we have to use "Action" in action method name ViewBag.ActionMethod = "CreateProduct"; var tempo = DateTime.Now.Subtract(inizio); Console.WriteLine(tempo); return View("CreateProduct", d); }
public ActionResult NewFromCodProduct(string id) { var p = new PapiroService(); p.ProductRepository = productRepository; p.CurrentDatabase = CurrentDatabase; var inizio = DateTime.Now; var c = p.ProductRepository.GetSingle(id);// p.InitProduct(id, prodTskNameRepository, formatsRepository, typeOfTaskRepository); var d = new ProductViewModel(); //controllo i dati di cliente e riferimento //cercando la session if (Session["CodDocument"] != null) { var doc = documentRepository.GetSingle((string)Session["CodDocument"]); d.DocumentName = doc.DocumentName; d.Customer = doc.Customer; } c.ProductNameGenerator = p.ProductRepository.GetProductNameGenerator(c.CodMenuProduct).Generator; c.ProductName = ""; d.Product = c; Console.WriteLine(d.ProductRefName); var product = c; //Carico i nomi dei formati perchè se la validazione non va a buon fine devo ripresentarli product.FormatsName = formatsRepository.GetAllById(product.CodMenuProduct); product.SystemTaskList = typeOfTaskRepository.GetAll().ToList(); product.InitPageTask(); //reload option object for productTask and productPartTask var taskList = this.typeOfTaskRepository.GetAll(); foreach (var item in product.ProductTasks) { item.OptionTypeOfTask = typeOfTaskRepository.GetSingleOptionTypeOfTask(item.CodOptionTypeOfTask); } foreach (var item in product.ProductParts) { foreach (var item2 in item.ProductPartTasks) { item2.OptionTypeOfTask = typeOfTaskRepository.GetSingleOptionTypeOfTask(item2.CodOptionTypeOfTask); } } //-----end reloding //???? // d.Quantities.Add(0); //view name is needed for reach right view because to using more than one submit we have to use "Action" in action method name ViewBag.ActionMethod = "CreateProduct"; var tempo = DateTime.Now.Subtract(inizio); Console.WriteLine(tempo); return View("CreateProduct", d); }
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(""); }
public ActionResult SaveCostDetail(string optCod = "") { disposable = false; CostDetail cv = (CostDetail)Session["CostDetail" + optCod]; PapiroService p = new PapiroService(); p.DocumentRepository = documentRepository;//new DocumentRepository(); p.CostDetailRepository = costDetailRepository; p.TaskExecutorRepository = taskExecutorRepository; p.ArticleRepository = articleRepository; p.TypeOfTaskRepository = typeOfTaskRepository; p.CurrentDatabase = CurrentDatabase; p.InitCostDocumentProduct(costDetailRepository.GetSingle(cv.CodCost).TaskCost.CodDocumentProduct); var cvRet = p.SaveCostDetailFromController(cv); var idRet = (string)Session["codProduct"]; Session["CostDetail" + optCod] = cvRet; disposable = true; if (idRet != null) { return Json(new { redirectUrl = Url.Action("EditDocumentProducts", new { id = idRet }) }, JsonRequestBehavior.AllowGet); } else { return Json(new { redirectUrl = Url.Action("Index", new { area = "" }) }, JsonRequestBehavior.AllowGet); } }
public ActionResult EditCost(string id) { var cd = costDetailRepository.GetSingle(id); if (cd == null) { var cost = documentRepository.GetCost(id); EditAndCreateAllCost(cost.CodDocumentProduct); cd = costDetailRepository.GetSingle(id); } PapiroService p = new PapiroService(); p.DocumentRepository = documentRepository;//new DocumentRepository(); p.CostDetailRepository = costDetailRepository; p.TaskExecutorRepository = taskExecutorRepository; p.ArticleRepository = articleRepository; p.TypeOfTaskRepository = typeOfTaskRepository; p.CurrentDatabase = CurrentDatabase; p.InitCostDocumentProduct(cd.TaskCost.CodDocumentProduct); var cv = p.EditCostAutomatically(id, new Guid()); //Console.WriteLine(cv.GainForRun); if (cv == null) { return View("NotImplementedCostDetail"); } Session["CostDetail"] = cv; Session["PapiroService"] = p; Console.Write(cv.Error); var viewName = String.Empty; switch (cv.TypeOfCostDetail) { case CostDetail.CostDetailType.PrintingZRollCostDetail: case CostDetail.CostDetailType.PrintingFlatRollCostDetail: ((PrintingZRollCostDetail)cv).DieTollerance = 0.5; ((PrintingZRollCostDetail)cv).Dies = articleRepository.GetAll().OfType<Die>().ToList(); ((PrintingZRollCostDetail)cv).FuzzyAlgo(); viewName = "PrintingCostDetail"; break; case CostDetail.CostDetailType.PrintingRollCostDetail: ((PrintingRollCostDetail)cv).FuzzyAlgo(); viewName = "PrintingCostDetail"; break; case CostDetail.CostDetailType.PrintingSheetCostDetail: viewName = "PrintingCostDetail"; break; case CostDetail.CostDetailType.PrintedSheetArticleCostDetail: viewName = "PrintingCostDetail"; break; case CostDetail.CostDetailType.PrintedRollArticleCostDetail: viewName = "PrintingCostDetail"; break; case CostDetail.CostDetailType.ControlTableCostDetail: viewName = "ControlTableCostDetail"; break; case CostDetail.CostDetailType.PrePostPressCostDetail: case CostDetail.CostDetailType.ImplantMeshCostDetail: case CostDetail.CostDetailType.ImplantHotPrintingCostDetail: case CostDetail.CostDetailType.RepassRollCostDetail: //get ST codCost cv.CodPartPrintingCostDetail = p.DocumentRepository.GetCostsByCodDocumentProduct(cv.TaskCost.CodDocumentProduct).Where(y1 => y1.CodItemGraph == "ST").Select(z => z.CodCost); //if there is a ST if (cv.CodPartPrintingCostDetail != null) { //fix all links foreach (var item in cv.CodPartPrintingCostDetail) { var cv2 = p.CostDetailRepository.GetSingle(item); if (!cv.Printers.Select(x => x.CodCostDetail).Contains(cv2.CodCostDetail)) { cv.Printers.Add(cv2); cv2.InitCostDetail(taskExecutorRepository.GetAll(), articleRepository.GetAll()); } } } viewName = "PrintingCostDetail"; break; default: viewName = "ControlTableCostDetail"; break; } Session["CostDetail"] = cv; Session["PapiroService"] = p; return View(viewName, cv); }
public ActionResult EditAndCreateAllCost(string id) { var idRet = documentRepository.GetCostsByCodDocumentProduct(id).FirstOrDefault().DocumentProduct.CodProduct; PapiroService p = new PapiroService(); p.DocumentRepository = documentRepository;//new DocumentRepository(); p.CostDetailRepository = costDetailRepository; p.TaskExecutorRepository = taskExecutorRepository; p.ArticleRepository = articleRepository; p.TypeOfTaskRepository = typeOfTaskRepository; p.CurrentDatabase = CurrentDatabase; p.EditOrCreateAllCost(id); return RedirectToAction("EditDocumentProducts", "Document", new { id = idRet }); }
public HttpResponseMessage GetMaterialRigid() { try { PapiroService papiro = new PapiroService(); //Initialize new product var x = papiro.GetRigidList(new ArticleRepository()); return Request.CreateResponse<List<PrintableArticleApi>>(HttpStatusCode.OK, x); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.InternalServerError); } }
public HttpResponseMessage GetPriceRigidBind([ModelBinder(typeof(ProductApiModelBinder))]ProductApi prod) { try { PapiroService papiro = new PapiroService(); //Initialize new product PapiroMVC.Models.ProductRigid prodIntero = (ProductRigid)papiro.InitProduct(prod.Id, new ProductTaskNameRepository(), new FormatsNameRepository(), new TypeOfTaskRepository()); Projection.ResolveProjection((ProductRigidApi)prod, prodIntero); //generazione dei prezzi a caso prod.Prices.Clear(); prod.Prices.Add(new Price { Date = DateTime.Today.AddDays(2), UnitPrice = "0.087" }); prod.Prices.Add(new Price { Date = DateTime.Today.AddDays(4), UnitPrice = "0.059" }); prod.Prices.Add(new Price { Date = DateTime.Today.AddDays(9), UnitPrice = "0.024" }); return Request.CreateResponse<ProductRigidApi>(HttpStatusCode.OK, (ProductRigidApi)prod); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.InternalServerError); } }
public HttpResponseMessage GetEmptyRigid(string id) { try { PapiroService papiro = new PapiroService(); //Initialize new product PapiroMVC.Models.ProductRigid prodIntero = (ProductRigid)papiro.InitProduct(id, new ProductTaskNameRepository(), new FormatsNameRepository(), new TypeOfTaskRepository()); var prod = new ProductRigidApi(); prod.Id = id; Projection.MakeProjection(prodIntero, prod); return Request.CreateResponse<ProductRigidApi>(HttpStatusCode.OK, prod); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.InternalServerError); } }