public IActionResult GenPURItem([FromBody] JArray values) { try { GenHelper.WriteLog("[Log]", "[" + securityProvider.GetUserName() + "]" + controllername + "-GenPURItem:[" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]"); GenHelper.WriteLog("[Json]", "[" + securityProvider.GetUserName() + "]" + controllername + "-GenPURItem:[" + Environment.NewLine + values.ToString() + Environment.NewLine + "][" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]"); PurchaseReturnDetail dtl; string temp = ""; JToken token; foreach (JObject Jdtl in values.Children()) { dtl = objectSpace.CreateObject <PurchaseReturnDetail>(); temp = Jdtl["Baseline"].ToString(); dtl.Baseline = int.Parse(temp); if (Jdtl.ContainsKey("BaseDocNo")) { temp = Jdtl["BaseDocNo"].ToString(); dtl.BaseDocNo = temp; } temp = DocTypeCodes.PurchaseDelivery; dtl.BaseType = objectSpace.FindObject <DocType>(CriteriaOperator.Parse("BoCode=?", temp)); temp = Jdtl["Quantity"].ToString(); dtl.Quantity = double.Parse(temp); if (Jdtl.ContainsKey("BatchNumber")) { if (Jdtl["BatchNumber"] != null) { temp = Jdtl["BatchNumber"].ToString(); } if (!string.IsNullOrEmpty(temp)) { dtl.BatchNumber = temp; } } token = Jdtl["BinCode"]; temp = token["BoKey"].ToString(); dtl.BinCode = objectSpace.FindObject <vwWarehouseBins>(CriteriaOperator.Parse("BoKey=?", temp)); token = Jdtl["LineVendor"]; temp = token["BoKey"].ToString(); dtl.LineVendor = objectSpace.FindObject <vwBusinessPartners>(CriteriaOperator.Parse("BoKey=?", temp)); } objectSpace.CommitChanges(); return(Ok()); } catch (Exception ex) { GenHelper.WriteLog("[Error]", "[" + securityProvider.GetUserName() + "]" + controllername + "-GenPURItem:[" + ex.Message + "][" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]"); throw new Exception(ex.Message); } }
private void deleteDetails(JObject value, PurchaseOrder obj) { try { #region delete details string detalclassname = "PurchaseOrderDetail"; bool isnew = false; int intkeyvalue = -1; JArray jarray = (JArray)value[detalclassname]; foreach (JObject Jdtl in jarray.Children()) { isnew = false; if (Jdtl.ContainsKey("Oid")) { if (Jdtl["Oid"] == null) { isnew = true; } else { if (int.TryParse(Jdtl["Oid"].ToString(), out intkeyvalue)) { if (intkeyvalue == -1) { isnew = true; } } } } else { isnew = true; } if (!isnew) { if (Jdtl.ContainsKey("IsBeingDelete")) { if (Jdtl["IsBeingDelete"].ToString() == "1" || Jdtl["IsBeingDelete"].ToString().ToUpper() == "TRUE") { PurchaseOrderDetail dtl = obj.PurchaseOrderDetail.Where(pp => pp.Oid == intkeyvalue).FirstOrDefault(); if (dtl != null) { dtl.Delete(); } //obj.PurchaseOrderDetail.Remove(dtl); } } } } #endregion } catch (Exception ex) { throw new Exception(ex.Message); } }
static void PopulateCollectionProperty(JObject jObject, object obj, XPMemberInfo memberInfo, Session session) { XPClassInfo classInfo = session.Dictionary.GetClassInfo(GenHelper.xafAssembly, GenHelper.xafAssembly + "." + memberInfo.Name); JArray jarray = (JArray)jObject[memberInfo.Name]; foreach (JObject Jdtl in jarray.Children()) { try { //string keyPropertyName = memberInfo.ReferenceType.KeyProperty.Name; //JToken keyToken = jObject[memberInfo.Name][keyPropertyName]; int intkeyvalue = -1; object keyValue = null; if (Jdtl.ContainsKey("Oid")) { if (Jdtl["Oid"] != null) { if (int.TryParse(Jdtl["Oid"].ToString(), out intkeyvalue)) { keyValue = intkeyvalue; } else { Guid guidkeyvalue = new Guid(Jdtl["Oid"].ToString()); keyValue = guidkeyvalue; } //object dtlobj = session.GetObjectByKey(memberInfo.MemberType, keyValue); object dtlobj = session.GetObjectByKey(classInfo, keyValue); if (dtlobj != null) { PopulateObject(Jdtl, session, classInfo, dtlobj); } } } } catch (Exception ex) { } } }
//[HttpGet] //public List<DocTypeSeries> Get() //{ // List<DocTypeSeries> result = null; // XPQuery<DocTypeSeries> query = (XPQuery<DocTypeSeries>)_uow.Query<DocTypeSeries>(); // result = query.ToList<DocTypeSeries>(); // return result; //} private void addNewDetailsOnly(JObject value, PurchaseOrder obj, bool IsNewHeader) { try { #region add details string detalclassname = "PurchaseOrderDetail"; bool isnew = false; int intkeyvalue = -1; JArray jarray = (JArray)value[detalclassname]; foreach (JObject Jdtl in jarray.Children()) { isnew = false; if (IsNewHeader) { isnew = true; } else { if (Jdtl.ContainsKey("Oid")) { if (Jdtl["Oid"] == null) { isnew = true; } else { if (int.TryParse(Jdtl["Oid"].ToString(), out intkeyvalue)) { if (intkeyvalue == -1) { isnew = true; } } } } else { isnew = true; } } if (isnew) { if (Jdtl.ContainsKey("IsBeingDelete")) { if (Jdtl["IsBeingDelete"].ToString() == "1" || Jdtl["IsBeingDelete"].ToString().ToUpper() == "TRUE") { isnew = false; } } if (isnew) { PurchaseOrderDetail dtl = JsonPopulateObjectHelper.PopulateObject <PurchaseOrderDetail>(Jdtl.ToString(), _uow); obj.PurchaseOrderDetail.Add(dtl); } } } #endregion } catch (Exception ex) { throw new Exception(ex.Message); } }
public IActionResult GenGRN([FromBody] JObject values) { try { GenHelper.WriteLog("[Log]", "[" + securityProvider.GetUserName() + "]" + controllername + "-GenGRN:[" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]"); GenHelper.WriteLog("[Json]", "[" + securityProvider.GetUserName() + "]" + controllername + "-GenGRN:[" + Environment.NewLine + values.ToString() + Environment.NewLine + "][" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]"); // //JsonParser.ParseJObjectXPO<PurchaseDelivery>(values, employee, objectSpace); string temp = ""; JToken token; PurchaseDelivery employee = objectSpace.CreateObject <PurchaseDelivery>(); token = values["CardCode"]; temp = token["BoKey"].ToString(); employee.CardCode = objectSpace.FindObject <vwBusinessPartners>(CriteriaOperator.Parse("BoKey=?", temp)); employee.NumAtCard = values["NumAtCard"].ToString(); //JsonPopulateObjectHelper.PopulateObjectWODetail(values.ToString(), employee.Session, employee); string detalclassname = "PurchaseDeliveryDetail"; int intkeyvalue = -1; JArray jarray = (JArray)values[detalclassname]; int cnt = 0; foreach (JObject Jdtl in jarray.Children()) { if (Jdtl.ContainsKey("Oid")) { if (int.TryParse(Jdtl["Oid"].ToString(), out intkeyvalue)) { PurchaseDeliveryDetail dtl = objectSpace.GetObjectByKey <PurchaseDeliveryDetail>(intkeyvalue); cnt++; dtl.VisOrder = cnt; dtl.VerNo = 1; employee.PurchaseDeliveryDetail.Add(dtl); } else { GenHelper.WriteLog("[Error]", "[" + securityProvider.GetUserName() + "]" + controllername + "-GenGRN:[Details Key value is invalid][" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]"); throw new Exception("Details Key value is invalid"); } } else { GenHelper.WriteLog("[Error]", "[" + securityProvider.GetUserName() + "]" + controllername + "-GenGRN:[Details Key Column Not found][" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]"); throw new Exception("Details Key Column Not found"); } } if (employee.DocTypeSeries == null) { GenHelper.WriteLog("[Error]", "[" + securityProvider.GetUserName() + "]" + controllername + "-GenGRN:[Document series is not found][" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]"); throw new Exception("Document series is not found"); } employee.DocStatus.AddDocStatus(DocStatus.Accepted, "WebApi Generated"); employee.DocStatus.CurrDocStatus = DocStatus.Accepted; employee.VerNo = 1; employee.AssignDocNumber(); objectSpace.CommitChanges(); return(Ok(employee.DocNum)); } catch (Exception ex) { GenHelper.WriteLog("[Error]", "[" + securityProvider.GetUserName() + "]" + controllername + "-GenGRN:[" + ex.Message + "][" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]"); throw new Exception(ex.Message); } }