/// <summary> /// create fisical new estimate /// </summary> /// <returns></returns> private Estimate NewEstimate() { var c = new Estimate(); c.EstimateNumberSerie = DateTime.Now.Year.ToString(); c.CodDocument = documentRepository.GetNewCode(c); c.EstimateNumber = documentRepository.GetNewEstimateNumber(c); c.DateDocument = DateTime.Now; var allStates = documentRepository.GetAllStates().Where(x => (x.UseInEstimate ?? false)); foreach (var s in allStates) { c.DocumentStates.Add(new DocumentState { CodDocument = c.CodDocument, StateNumber = s.StateNumber, CodState = s.CodState, ResetLinkedStates = s.ResetLinkedStates, Selected = false }); } documentRepository.Add(c); documentRepository.Save(); Session["CodDocument"] = c.CodDocument; return c; }
public ActionResult EditEstimate(Estimate c) { var taskList = this.typeOfTaskRepository.GetAll(); if (ModelState.IsValid) { try { documentRepository.Edit(c); //rigeneration name of article documentRepository.Save(); return Json(new { redirectUrl = Url.Action("ListEstimate") }); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message); } } Session["CodDocument"] = c.CodDocument; //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 = "EditEstimate"; return PartialView("_EditAndCreateDocument", c); }
public ActionResult NewProductCurrentEstimate(Estimate c) { MenuProduct[] menuProd = menu.GetAll().ToArray(); string strings = "~/Views/Shared/Strings"; foreach (var item in menuProd) { var name = (string)HttpContext.GetLocalResourceObject(strings, "CodMenuProduct" + item.CodMenuProduct); item.Name = name; if (name == "") { Console.WriteLine(); } } var filteredItems = menuProd.Where( item => item.Name.IndexOf(c.NewProductCommand.NewProduct, StringComparison.InvariantCultureIgnoreCase) >= 0 ); var sel = filteredItems.FirstOrDefault(); if (sel != null) { var est = Session["CodDocument"] != null ? Session["CodDocument"] : NewEstimate(); return Json(new { redirectUrl = Url.Action("CreateProduct", "Product", new { id = sel.CodMenuProduct }) }); } else { return Json(new { error = true }); } }
public HttpResponseMessage Test( string username, string nCom, string nPrev, string desc, string field1, string field2, string field3, string quantity, string price) { this.Init(); taskCenterRepository.SetDbName(username); productRepository.SetDbName(username); documentRepository.SetDbName(username); //cerco il prodotto ---> se c'è ok //altrimenti lo creo come generico!!! //cerco la commessa ---> se c'è ok //altrimenti la creo var prod = productRepository.GetAll().Where(x => x.PapiroPrev == nPrev).FirstOrDefault(); if (prod == null) { prod = new ProductEmpty(); prod.CodProduct = productRepository.GetNewCode(prod); prod.CodMenuProduct = "Vuoto"; prod.PapiroPrev = nPrev; prod.ProductName = desc; productRepository.Add(prod); productRepository.Save(); } var docProd = documentRepository.GetAllDocumentProducts().Where(x => x.CodProduct == prod.CodProduct).FirstOrDefault(); if (docProd == null) { docProd = new DocumentProduct(); docProd.CodProduct = prod.CodProduct; docProd.UnitPrice = "0";//Convert.ToDouble(price).ToString(); docProd.Quantity = 0; // Convert.ToInt16(quantity); Estimate e = new Estimate(); e.CodDocument = documentRepository.GetNewCode(e); e.EstimateNumberSerie = DateTime.Now.Year.ToString(); e.EstimateNumber = documentRepository.GetNewEstimateNumber(e); //var docProd = documentRepository.GetDocumentProductByCodDocumentProduct(codDocumentProduct); e.DocumentProducts.Add(docProd); documentRepository.Add(e); documentRepository.Save(); docProd.Product = prod; } var c = (Order)documentRepository.GetAll().Where(x => x.PapiroCom == nCom).FirstOrDefault(); if (c == null) { c = new Order(); c.CodDocument = documentRepository.GetNewCode(c); c.OrderNumberSerie = DateTime.Now.Year.ToString(); c.OrderNumber = documentRepository.GetNewOrderNumber(c); c.PapiroCom = nCom; c.OrderProduct = docProd; //c.CodCustomer = docProd.Document.CodCustomer; //c.Customer = docProd.Document.Customer; c.DateDocument = DateTime.Now; var allStates = documentRepository.GetAllStates().Where(x => (x.UseInOrder ?? false)).OrderBy(x => x.StateNumber); foreach (var s in allStates) { c.DocumentStates.Add(new DocumentState { CodDocument = c.CodDocument, StateNumber = s.StateNumber, CodState = s.CodState, // StateName = s.StateName, //derivated!!! ResetLinkedStates = s.ResetLinkedStates, Selected = false }); } documentRepository.Add(c); documentRepository.Save(); //se ci sono dei TaskCenter inizio a buttare i taskcenter nel primo taskcenter (IndexOf==0) var taskCenter = taskCenterRepository.GetAll().Where(y => y.IndexOf == 0).FirstOrDefault(); if (taskCenter != null) { DocumentTaskCenter dtc = new DocumentTaskCenter(); dtc.CodTaskCenter = taskCenter.CodTaskCenter; dtc.CodDocument = c.CodDocument; if (docProd.Product.ProductRefName == null) { dtc.DocumentName = docProd.Product.ProductName; } else { dtc.DocumentName = docProd.Product.ProductRefName; } dtc.FieldA = field1; dtc.FieldB = field2; dtc.FieldC = field3; if (username.ToLower() == "lamarina") { try { dtc.DocumentName = nCom.Substring(0,nCom.IndexOf('/')) + " " + dtc.DocumentName + " " + field1; } catch (Exception) { } dtc.FieldA = ""; } else { dtc.DocumentName = nCom + " " + dtc.DocumentName; } taskCenterRepository.AddNewDocumentTaskCenter(dtc); taskCenterRepository.Save(); } } taskCenterRepository.Dispose(); productRepository.Dispose(); documentRepository.Dispose(); return Request.CreateResponse<string>(HttpStatusCode.OK, username); }