public static List <Product> QueryProductsByInspection(HttpClient httpClient, Guid inspectionId) { var products = new List <Product>(); var today = DateTime.Today; var fetchXml = string.Empty; fetchXml += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>"; fetchXml += " <entity name='product'>"; fetchXml += " <attribute name='name' />"; fetchXml += " <attribute name='productid' />"; fetchXml += " <attribute name='parentproductid' />"; fetchXml += " <attribute name='price' />"; fetchXml += " <attribute name='defaultuomid' />"; fetchXml += " <attribute name='blu_buyerpays' />"; fetchXml += " <attribute name='statecode' />"; fetchXml += " <attribute name='blu_appointmentduration' />"; fetchXml += " <attribute name='blu_requiredinspectorskills' />"; fetchXml += " <link-entity name='blu_inspectiondetail' from='blu_productid' to='productid' link-type='inner' alias='ae'>"; fetchXml += " <filter type='and'>"; fetchXml += " <condition attribute='blu_reportvalidfrom' operator='on-or-before' value='" + today + "' />"; fetchXml += " <condition attribute='blu_reportvalidto' operator='on-or-after' value='" + today + "' />"; fetchXml += " </filter>"; fetchXml += " <link-entity name='blu_inspection' from='blu_inspectionid' to='blu_inspectionid' link-type='inner' alias='af'>"; fetchXml += " <filter type='and'>"; fetchXml += " <condition attribute='statecode' operator='eq' value='0' />"; fetchXml += " <condition attribute='blu_inspectionid' operator='eq' value='" + inspectionId + "' />"; fetchXml += " </filter>"; fetchXml += " </link-entity>"; fetchXml += " </link-entity>"; fetchXml += " </entity>"; fetchXml += "</fetch>"; var encodedQuery = SharedService.UrlEncode(fetchXml); var odataQuery = webApiQueryUrl + "products?fetchXml=" + encodedQuery; var retrieveResponse = httpClient.GetAsync(odataQuery); var jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); if (systemUserObject == null || systemUserObject.value == null) { return(null); } if (systemUserObject.value.Count == 0) { return(null); } foreach (var data in systemUserObject.value) { var parentProduct = new Product() { Id = data["_parentproductid_value"] == null ? Guid.Empty : Guid.Parse(data["_parentproductid_value"].ToString()), Name = data["*****@*****.**"] == null ? "" : data["*****@*****.**"].ToString(), IsParentProduct = true }; var product = new Product() { Id = data["productid"] == null ? Guid.Empty : Guid.Parse(data["productid"].ToString()), Name = data["name"] == null ? "" : data["name"].ToString(), BuyerPays = data["blu_buyerpays"] == null ? 0 : (decimal)data["blu_buyerpays"], BuyerPaysDisplayName = data["*****@*****.**"] == null ? "" : data["*****@*****.**"].ToString(), UomId = data["_defaultuomid_value"] == null ? Guid.Empty : Guid.Parse(data["_defaultuomid_value"].ToString()), Status = data["statecode"] == null ? 0 : (int)data["statecode"], InspectorSkills = data["blu_requiredinspectorskills"] == null ? new List <string>() : data["blu_requiredinspectorskills"].ToString().Split(','), AppointmentDuration = data["blu_appointmentduration"] == null? 0 : (int)data["blu_appointmentduration"], ParentProductId = parentProduct.Id, ParentProduct = parentProduct, }; products.Add(product); } return(products); }
public static List <Appointment> QueryAppointmentsByInspector(HttpClient httpClient, Guid inspectorId) { var appointments = new List <Appointment>(); try { var fetchXML = string.Empty; fetchXML += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"; fetchXML += " <entity name='appointment'>"; fetchXML += " <attribute name='statecode' />"; fetchXML += " <attribute name='scheduledstart' />"; fetchXML += " <attribute name='scheduledend' />"; fetchXML += " <attribute name='ownerid' />"; fetchXML += " <attribute name='activityid' />"; fetchXML += " <filter type='and'>"; fetchXML += " <condition attribute='statecode' operator='in'>"; fetchXML += " <value>0</value>"; fetchXML += " <value>3</value>"; fetchXML += " </condition>"; fetchXML += " <condition attribute='blu_approvalstatus' operator='eq' value='" + (int)ApprovalStatus.New + "' />"; fetchXML += " <condition attribute='ownerid' operator='eq' value='" + inspectorId + "' />"; fetchXML += " <condition attribute='scheduledstart' operator='on-or-after' value='" + DateTime.Today.ToShortDateString() + "' />"; fetchXML += " </filter>"; fetchXML += " </entity>"; fetchXML += "</fetch>"; var encodedQuery = SharedService.UrlEncode(fetchXML); var odataQuery = webApiQueryUrl + "appointments?fetchXml=" + encodedQuery; var retrieveResponse = httpClient.GetAsync(odataQuery); var jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); foreach (var data in systemUserObject.value) { var appointment = new Appointment() { Id = data["activityid"] == null ? Guid.Empty : Guid.Parse(data["activityid"].ToString()), StartTime = DateTime.Parse(data["scheduledstart"].ToString()), StartTimeDisplayName = data["*****@*****.**"], EndTime = DateTime.Parse(data["scheduledend"].ToString()), EndTimeDisplayName = data["*****@*****.**"], OwnerId = Guid.Parse(data["_ownerid_value"].ToString()), Owner = new SystemUser() { Id = Guid.Parse(data["_ownerid_value"].ToString()), Fullname = data["*****@*****.**"] } }; appointments.Add(appointment); } return(appointments); } catch (Exception ex) { LogService.LogMessage(httpClient, new Log() { Level = (int)LogType.Error, Name = ex.Message, FunctionName = ClassName + " | " + MethodBase.GetCurrentMethod().Name, Message = ex.InnerException != null ? ex.InnerException.Message : ex.Message }); return(null); } }
public static List <Product> QueryProductsByPriceLists(HttpClient httpClient, List <PriceList> priceLists) { var products = new List <Product>(); var fetchXml = string.Empty; fetchXml += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"; fetchXml += " <entity name='product'>"; fetchXml += " <attribute name='name' />"; fetchXml += " <attribute name='productid' />"; fetchXml += " <attribute name='productnumber' />"; fetchXml += " <attribute name='description' />"; fetchXml += " <attribute name='statecode' />"; fetchXml += " <attribute name='productstructure' />"; fetchXml += " <attribute name='parentproductid' />"; fetchXml += " <attribute name='pricelevelid' />"; fetchXml += " <attribute name='blu_stratareport' />"; fetchXml += " <filter type='and'>"; if (priceLists != null && priceLists.Count > 0) { fetchXml += " <condition attribute='pricelevelid' operator='in'>"; foreach (var priceList in priceLists) { fetchXml += " <value>" + priceList.Id + "</value>"; } fetchXml += " </condition>"; } fetchXml += " <condition attribute='statecode' operator='eq' value='0' />"; fetchXml += " <condition attribute='statuscode' operator='eq' value='1' />"; fetchXml += " </filter>"; fetchXml += " </entity>"; fetchXml += "</fetch>"; var encodedQuery = SharedService.UrlEncode(fetchXml); var odataQuery = webApiQueryUrl + "products?fetchXml=" + encodedQuery; var retrieveResponse = httpClient.GetAsync(odataQuery); var jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); if (systemUserObject == null || systemUserObject.value == null) { return(null); } if (systemUserObject.value.Count == 0) { return(null); } foreach (var data in systemUserObject.value) { var priceList = new PriceList() { Id = data["_pricelevelid_value"] == null ? Guid.Empty : Guid.Parse(data["_pricelevelid_value"].ToString()), Name = data["*****@*****.**"] == null ? "" : data["*****@*****.**"].ToString() }; var parentProduct = new Product() { Id = data["_parentproductid_value"] == null ? Guid.Empty : Guid.Parse(data["_parentproductid_value"].ToString()), Name = data["*****@*****.**"] == null ? "" : data["*****@*****.**"].ToString(), IsParentProduct = true }; var product = new Product() { Id = data["productid"] == null ? Guid.Empty : Guid.Parse(data["productid"].ToString()), Name = data["name"] == null ? "" : data["name"].ToString(), StrataReport = data["blu_stratareport"] != null && (bool)data["blu_stratareport"], ParentProductId = parentProduct.Id, ParentProduct = parentProduct, DefaultPriceListId = priceList.Id, DefaultPriceList = priceList }; products.Add(product); } return(products); }
public static List <Opportunity> QueryOpportunitiesByPriceListsByCustomerIdByInspectionId(HttpClient httpClient, List <PriceList> priceLists, Guid customerId, Guid inspectionId) { try { var priceListIds = string.Empty; foreach (var priceList in priceLists) { priceListIds += "<value>" + priceList.Id + "</value>"; } var xmlQuery = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='opportunity'> <attribute name='opportunityid' /> <attribute name='pricelevelid' /> <attribute name='customerid' /> <attribute name='totalamount' /> <attribute name='blu_opportunitytype' /> <filter type='and'> <condition attribute='statuscode' operator='eq' value='" + (int)OpportunityStatusCode.IncompleteChart + @"' /> <condition attribute='customerid' operator='eq' value='" + customerId + @"' /> <condition attribute='pricelevelid' operator='in'> " + priceListIds + @" </condition> </filter> <link-entity name='product' from='productid' to='productid' link-type='inner' alias='ah'> <link-entity name='blu_inspectiondetail' from='blu_productid' to='productid' link-type='outer' alias='ai'> <filter type='and'> <condition attribute='blu_inspectionid' operator='eq' value='" + inspectionId + @"' /> </filter> </link-entity> </link-entity> </entity> </fetch>"; var encodedQuery = SharedService.UrlEncode(xmlQuery); var odataQuery = webApiQueryUrl + "productpricelevels?fetchXml=" + encodedQuery; var retrieveResponse = httpClient.GetAsync(odataQuery); var jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); if (systemUserObject == null || systemUserObject.value == null) { return(null); } var opportunities = new List <Opportunity>(); foreach (var data in systemUserObject.value) { var opportunity = new Opportunity() { Id = Guid.Parse(data["opportunityid"].ToString()), Name = data["name"], CustomerId = Guid.Parse(data["_customerid_value"].ToString()), TotalAmount = (decimal)data["totalamount"], TotalAmountDisplayName = data["*****@*****.**"], PriceListId = Guid.Parse(data["_pricelevelid_value"].ToString()), OpportunityType = (int)data["blu_opportunitytype"] }; opportunities.Add(opportunity); } return(opportunities); } catch (Exception ex) { LogService.LogMessage(httpClient, new Log() { Level = (int)LogType.Error, Name = ex.Message, FunctionName = ClassName + " | " + MethodBase.GetCurrentMethod().Name, Message = ex.InnerException != null ? ex.InnerException.Message : ex.Message }); return(null); } }
public static List <Appointment> QueryInspectorsAppointments(HttpClient httpClient, int numberOfInspectors) { var bookedAppointments = new List <Appointment>(); var appointments = new List <Appointment>(); var appointmentDates = new List <DateTime>(); try { var fetchXML = string.Empty; fetchXML += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"; fetchXML += " <entity name='appointment'>"; fetchXML += " <attribute name='statecode' />"; fetchXML += " <attribute name='scheduledstart' />"; fetchXML += " <attribute name='scheduledend' />"; fetchXML += " <attribute name='ownerid' />"; fetchXML += " <attribute name='activityid' />"; fetchXML += " <filter type='and'>"; fetchXML += " <condition attribute='statecode' operator='in'>"; fetchXML += " <value>0</value>"; fetchXML += " <value>3</value>"; fetchXML += " </condition>"; fetchXML += " <condition attribute='blu_approvalstatus' operator='eq' value='" + (int)ApprovalStatus.New + "' />"; fetchXML += " <condition attribute='scheduledstart' operator='on-or-after' value='" + "2018-05-12" + "' />"; fetchXML += " </filter>"; fetchXML += " </entity>"; fetchXML += "</fetch>"; var encodedQuery = SharedService.UrlEncode(fetchXML); var odataQuery = webApiQueryUrl + "appointments?fetchXml=" + encodedQuery; var retrieveResponse = httpClient.GetAsync(odataQuery); var jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); foreach (var data in systemUserObject.value) { DateTime startTime = DateTime.Parse(data["scheduledstart"].ToString()); DateTime endTime = DateTime.Parse(data["scheduledend"].ToString()); var doesDateAlreadyExist = appointmentDates.Any(x => x.Date == startTime.Date); if (!doesDateAlreadyExist) { appointmentDates.Add(startTime); } var appointment = new Appointment() { Id = data["activityid"] == null ? Guid.Empty : Guid.Parse(data["activityid"].ToString()), StartTime = DateTime.Parse(data["scheduledstart"].ToString()), StartTimeDisplayName = data["*****@*****.**"], EndTime = DateTime.Parse(data["scheduledend"].ToString()), EndTimeDisplayName = data["*****@*****.**"], OwnerId = Guid.Parse(data["_ownerid_value"].ToString()), Owner = new SystemUser() { Id = Guid.Parse(data["_ownerid_value"].ToString()), Fullname = data["*****@*****.**"] } }; appointments.Add(appointment); } var endDate = appointments.Max(r => r.EndTime); var startDate = DateTime.Today; foreach (var date in appointmentDates) { Console.WriteLine(date); for (var min = 0; min < 1440; min += 30) { var apptCount = appointments.Count(x => x.StartTime.Date == date.Date && x.StartTime.TimeOfDay.TotalMinutes <= min && x.EndTime.TimeOfDay.TotalMinutes >= (min + 30)); if (apptCount >= numberOfInspectors) { bookedAppointments.Add(new Appointment() { Subject = "Booked", StartTime = new DateTime(date.Year, date.Month, date.Day, (int)(min / 60), ((min / 30) % 2 * 30), 0), EndTime = new DateTime(date.Year, date.Month, date.Day, (int)((min + 30) / 60), (((min + 30) / 30) % 2 * 30), 0) }); } } } return(bookedAppointments); } catch (Exception ex) { return(null); } }
public static List <CartItem> QueryOpportunityProductsByOpportunityId(HttpClient httpClient, Guid opportunityId) { try { var cartItems = new List <CartItem>(); var fetchXml = string.Empty; fetchXml += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"; fetchXml += " <entity name='opportunityproduct'>"; fetchXml += " <attribute name='productid' />"; fetchXml += " <attribute name='blu_productcategory' />"; fetchXml += " <attribute name='opportunityproductid' />"; fetchXml += " <attribute name='opportunityid' />"; fetchXml += " <attribute name='baseamount' />"; fetchXml += " <attribute name='blu_reportpriority' />"; fetchXml += " <attribute name='blu_freereport' />"; fetchXml += " <attribute name='blu_onbackorder' />"; fetchXml += " <attribute name='blu_reportisreleasedto' />"; fetchXml += " <attribute name='blu_reportisresellable' />"; fetchXml += " <attribute name='blu_sellableto' />"; fetchXml += " <attribute name='blu_stratareport' />"; fetchXml += " <filter type='and'>"; fetchXml += " <condition attribute='opportunityid' operator='eq' value='" + opportunityId + "' />"; fetchXml += " <condition attribute='producttypecode' operator='in'>"; fetchXml += " <value>2</value>"; fetchXml += " <value>1</value>"; fetchXml += " </condition>"; fetchXml += " </filter>"; fetchXml += " <link-entity name='product' from='productid' to='productid' visible='false' link-type='outer' alias='product'>"; fetchXml += " <attribute name='blu_requiredinspectorskills' />"; fetchXml += " <attribute name='blu_appointmentduration' />"; fetchXml += " </link-entity>"; fetchXml += " </entity>"; fetchXml += "</fetch>"; var encodedQuery = SharedService.UrlEncode(fetchXml); var odataQuery = webApiQueryUrl + "opportunityproducts?fetchXml=" + encodedQuery; var retrieveResponse = httpClient.GetAsync(odataQuery); var jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); if (systemUserObject == null || systemUserObject.value == null) { return(null); } var opportunityProducts = new List <OpportunityProduct>(); foreach (var data in systemUserObject.value) { var cartItem = new CartItem() { OpportunityId = data["_opportunityid_value"] == null ? Guid.Empty : Guid.Parse(data["_opportunityid_value"].ToString()), ProductId = data["_productid_value"] == null ? Guid.Empty : Guid.Parse(data["_productid_value"].ToString()), ProductName = data["*****@*****.**"] == null ? "" : data["*****@*****.**"], AmountText = data["*****@*****.**"] == null ? "" : data["*****@*****.**"], ProductSkills = data["product_x002e_blu_requiredinspectorskills"] == null ? new string[0] : data["product_x002e_blu_requiredinspectorskills"].ToString().Split(','), ProductCategory = data["blu_productcategory"] == null ? null : data["blu_productcategory"], AppointmentDuration = data["product_x002e_blu_appointmentduration"] == null ? 0 : (int)data["product_x002e_blu_appointmentduration"], ReportPriority = data["blu_reportpriority"] == null ? 0 : (int)data["blu_reportpriority"], FreeReport = data["blu_freereport"] == null ? false : (bool)data["blu_freereport"], OnBackOrder = data["blu_onbackorder"] == null ? false : (bool)data["blu_onbackorder"], ReportIsReleasedTo = data["blu_reportisreleasedto"] == null ? 0 : (int)data["blu_reportisreleasedto"], ReportIsSellableTo = data["blu_reportisresellable"] == null ? 0 : (int)data["blu_reportisresellable"], SellableTo = data["blu_sellableto"] == null ? 0 : (int)data["blu_sellableto"], IsStrataReport = data["blu_stratareport"] == null ? false : (bool)data["blu_stratareport"], }; cartItems.Add(cartItem); } return(cartItems); } catch (Exception ex) { LogService.LogMessage(httpClient, new Log() { Level = (int)LogType.Error, Name = ex.Message, FunctionName = ClassName + " | " + MethodBase.GetCurrentMethod().Name, Message = ex.InnerException != null ? ex.InnerException.Message : ex.Message }); return(null); } }
public static List <InspectionPortalQA> QueryTermsAndConditionsByQuestionSetup(HttpClient httpClient, Guid questionSetupId) { var questionSetups = new List <InspectionPortalQA>(); var fetchXml = string.Empty; fetchXml += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"; fetchXml += " <entity name='blu_parentcategorysetup_questionsetup' >"; fetchXml += " <attribute name='blu_questionsetupidone' />"; fetchXml += " <attribute name='blu_questionsetupidtwo' />"; fetchXml += " <link-entity name='blu_questionsetup' from='blu_questionsetupid' to='blu_questionsetupidone' link-type='inner' >"; fetchXml += " <filter>"; fetchXml += " <condition attribute='blu_questionsetupid' operator='eq' value='" + questionSetupId + "' />"; fetchXml += " <condition attribute='blu_requiredfor' operator='eq' value='" + (int)InspectionPortalQA_RequiredFor.Portal + "' />"; fetchXml += " </filter>"; fetchXml += " </link-entity>"; fetchXml += " <link-entity name='blu_questionsetup' from='blu_questionsetupid' to='blu_questionsetupidtwo' >"; fetchXml += " <attribute name='blu_questionsetupid' />"; fetchXml += " <attribute name='blu_name' />"; fetchXml += " <attribute name='blu_number' />"; fetchXml += " <attribute name='blu_type' />"; fetchXml += " <attribute name='blu_answerdatatype' />"; fetchXml += " <attribute name='blu_optionvalues' />"; fetchXml += " <attribute name='blu_uniquename' />"; fetchXml += " <filter>"; fetchXml += " <condition attribute='blu_requiredfor' operator='eq' value='" + (int)InspectionPortalQA_RequiredFor.Portal + "' />"; fetchXml += " <condition attribute='blu_type' operator='eq' value='858890002' />"; fetchXml += " </filter>"; fetchXml += " </link-entity>"; fetchXml += " </entity>"; fetchXml += "</fetch>"; var encodedQuery = SharedService.UrlEncode(fetchXml); var odataQuery = webApiQueryUrl + "blu_parentcategorysetup_questionsetupset?fetchXml=" + encodedQuery; var retrieveResponse = httpClient.GetAsync(odataQuery); var jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); if (systemUserObject == null || systemUserObject.value == null) { return(null); } if (systemUserObject.value.Count == 0) { return(null); } foreach (var data in systemUserObject.value) { var questionSetup = new InspectionPortalQA() { Id = data["blu_questionsetup2_x002e_blu_questionsetupid"] == null ? Guid.Empty : Guid.Parse(data["blu_questionsetup2_x002e_blu_questionsetupid"].ToString()), AnswerDataType = data["blu_questionsetup2_x002e_blu_answerdatatype"] == null ? 0 : (int)data["blu_questionsetup2_x002e_blu_answerdatatype"], AnswerDataTypeText = data["*****@*****.**"] == null ? "" : data["*****@*****.**"].ToString(), Name = data["blu_questionsetup2_x002e_blu_name"] == null ? "" : data["blu_questionsetup2_x002e_blu_name"].ToString(), UniqueQuestionName = data["blu_questionsetup2_x002e_blu_uniquename"] == null ? "" : data["blu_questionsetup2_x002e_blu_uniquename"].ToString(), Number = data["blu_questionsetup2_x002e_blu_number"] == null ? -99 : (int)data["blu_questionsetup2_x002e_blu_number"], OptionSetValues = data["blu_questionsetup2_x002e_blu_optionvalues"] == null ? new string[0] : data["blu_questionsetup2_x002e_blu_optionvalues"].ToString().Split(','), Type = data["blu_questionsetup2_x002e_blu_type"] == null ? 0 : (int)data["blu_questionsetup2_x002e_blu_type"], IsMandatory = data["blu_questionsetup1_x002e_blu_answerismandatory"] == null ? false : (bool)data["blu_questionsetup1_x002e_blu_answerismandatory"], }; questionSetup.UniqueName = Guid.NewGuid().ToString().Replace("-", ""); questionSetups.Add(questionSetup); } return(questionSetups); }
public static List <InspectionPortalQA> QueryQuestionSetupByQuestionSetup(HttpClient httpClient, Guid productId) { var questionSetups = new List <InspectionPortalQA>(); var fetchXml = string.Empty; fetchXml += "<fetch>"; fetchXml += " <entity name='blu_blu_questionsetup_product' >"; fetchXml += " <attribute name='blu_questionsetupid' />"; fetchXml += " <attribute name='productid' />"; fetchXml += " <link-entity name='product' from='productid' to='productid' linke-type='inner' >"; fetchXml += " <attribute name='name' />"; fetchXml += " <attribute name='parentproductid' />"; fetchXml += " <filter>"; fetchXml += " <condition attribute='blu_requiredfor' operator='eq' value='" + productId + "' />"; fetchXml += " <filter>"; fetchXml += " </link-entity>"; fetchXml += " <link-entity name='blu_questionsetup' from='blu_questionsetupid' to='blu_questionsetupid' linke-type='inner' >"; fetchXml += " <attribute name='blu_questionsetupid' />"; fetchXml += " <attribute name='blu_name' />"; fetchXml += " <attribute name='blu_number' />"; fetchXml += " <attribute name='blu_type' />"; fetchXml += " <attribute name='blu_answerdatatype' />"; fetchXml += " <attribute name='blu_optionvalues' />"; fetchXml += " <attribute name='blu_uniquename' />"; fetchXml += " </link-entity>"; fetchXml += " </entity>"; fetchXml += "</fetch>"; var encodedQuery = SharedService.UrlEncode(fetchXml); var odataQuery = webApiQueryUrl + "blu_blu_questionsetup_productset?fetchXml=" + encodedQuery; var retrieveResponse = httpClient.GetAsync(odataQuery); var jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); if (systemUserObject == null || systemUserObject.value == null) { return(null); } if (systemUserObject.value.Count == 0) { return(null); } foreach (var data in systemUserObject.value) { var questionSetup = new InspectionPortalQA() { Id = data["blu_questionsetupid"] == null ? Guid.Empty : Guid.Parse(data["blu_questionsetupid"].ToString()), AnswerDataType = data["blu_questionsetup2_x002e_blu_answerdatatype"] == null ? 0 : (int)data["blu_questionsetup2_x002e_blu_answerdatatype"], AnswerDataTypeText = data["*****@*****.**"] == null ? "" : data["*****@*****.**"].ToString(), Name = data["blu_questionsetup2_x002e_blu_name"] == null ? "" : data["blu_questionsetup2_x002e_blu_name"].ToString(), UniqueQuestionName = data["blu_questionsetup2_x002e_blu_uniquename"] == null ? "" : data["blu_questionsetup2_x002e_blu_uniquename"].ToString(), Number = data["blu_questionsetup2_x002e_blu_number"] == null ? -99 : (int)data["blu_questionsetup2_x002e_blu_number"], OptionSetValues = data["blu_questionsetup2_x002e_blu_optionvalues"] == null ? new string[0] : data["blu_questionsetup2_x002e_blu_optionvalues"].ToString().Split(','), Type = data["blu_questionsetup2_x002e_blu_type"] == null ? 0 : (int)data["blu_questionsetup2_x002e_blu_type"], //Id = data["blu_questionsetup2_x002e_blu_questionsetupid"] == null ? Guid.Empty : Guid.Parse(data["blu_questionsetup2_x002e_blu_questionsetupid"].ToString()), //AnswerDataType = data["blu_questionsetup2_x002e_blu_answerdatatype"] == null ? // 0 : (int)data["blu_questionsetup2_x002e_blu_answerdatatype"], //AnswerDataTypeText = data["*****@*****.**"] == null ? //"" : data["*****@*****.**"].ToString(), //Name = data["blu_questionsetup2_x002e_blu_name"] == null ? "" : data["blu_questionsetup2_x002e_blu_name"].ToString(), //UniqueQuestionName = data["blu_questionsetup2_x002e_blu_uniquename"] == null ? "" : data["blu_questionsetup2_x002e_blu_uniquename"].ToString(), //Number = data["blu_questionsetup2_x002e_blu_number"] == null ? // -99 : (int)data["blu_questionsetup2_x002e_blu_number"], //OptionSetValues = data["blu_questionsetup2_x002e_blu_optionvalues"] == null // ? new string[0] // : data["blu_questionsetup2_x002e_blu_optionvalues"].ToString().Split(','), //Type = data["blu_questionsetup2_x002e_blu_type"] == null ? // 0 : (int)data["blu_questionsetup2_x002e_blu_type"], }; questionSetup.UniqueName = Guid.NewGuid().ToString().Replace("-", ""); questionSetups.Add(questionSetup); } return(questionSetups); }
public static List <InspectionPortalQA> QueryQuestionSetupByQuestionSetup(HttpClient httpClient, List <Guid> productIds, Guid priceListId) { var stockingProductIds = new List <Guid>(); foreach (var productId in productIds) { var product = ProductService.QueryProduct(httpClient, productId); if (product.StockingProductId != Guid.Empty && !stockingProductIds.Contains(product.StockingProductId)) { stockingProductIds.Add(product.StockingProductId); } } var questionSetups = new List <InspectionPortalQA>(); var fetchXml = string.Empty; fetchXml += "<fetch>"; fetchXml += " <entity name='blu_blu_questionsetup_product' >"; fetchXml += " <attribute name='blu_questionsetupid' />"; fetchXml += " <attribute name='productid' />"; fetchXml += " <link-entity name='product' from='productid' to='productid' linke-type='inner' >"; fetchXml += " <attribute name='name' />"; fetchXml += " <attribute name='parentproductid' />"; fetchXml += " <filter>"; if (stockingProductIds != null && stockingProductIds.Count > 0) { fetchXml += " <condition attribute='productid' operator='in'>"; foreach (var stockingProductId in stockingProductIds) { fetchXml += " <value>" + stockingProductId + "</value>"; } fetchXml += " </condition>"; } fetchXml += " </filter>"; fetchXml += " </link-entity>"; fetchXml += " <link-entity name='blu_questionsetup' from='blu_questionsetupid' to='blu_questionsetupid' linke-type='inner' >"; fetchXml += " <attribute name='blu_questionsetupid' />"; fetchXml += " <attribute name='blu_name' />"; fetchXml += " <attribute name='blu_number' />"; fetchXml += " <attribute name='blu_type' />"; fetchXml += " <attribute name='blu_answerdatatype' />"; fetchXml += " <attribute name='blu_optionvalues' />"; fetchXml += " <attribute name='blu_uniquename' />"; fetchXml += " <attribute name='blu_answerismandatory' />"; fetchXml += " <attribute name='blu_additionalproduct' />"; fetchXml += " </link-entity>"; fetchXml += " </entity>"; fetchXml += "</fetch>"; var encodedQuery = SharedService.UrlEncode(fetchXml); var odataQuery = webApiQueryUrl + "blu_blu_questionsetup_productset?fetchXml=" + encodedQuery; var retrieveResponse = httpClient.GetAsync(odataQuery); var jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); if (systemUserObject != null && systemUserObject.value != null) { if (systemUserObject.value.Count != 0) { foreach (var data in systemUserObject.value) { var questionSetup = new InspectionPortalQA() { Id = data["blu_questionsetupid"] == null ? Guid.Empty : Guid.Parse(data["blu_questionsetupid"].ToString()), AnswerDataType = data["blu_questionsetup2_x002e_blu_answerdatatype"] == null ? 0 : (int)data["blu_questionsetup2_x002e_blu_answerdatatype"], AnswerDataTypeText = data["*****@*****.**"] == null ? "" : data["*****@*****.**"].ToString(), Name = data["blu_questionsetup2_x002e_blu_name"] == null ? "" : data["blu_questionsetup2_x002e_blu_name"].ToString(), UniqueQuestionName = data["blu_questionsetup2_x002e_blu_uniquename"] == null ? "" : data["blu_questionsetup2_x002e_blu_uniquename"].ToString(), Number = data["blu_questionsetup2_x002e_blu_number"] == null ? -99 : (int)data["blu_questionsetup2_x002e_blu_number"], OptionSetValues = data["blu_questionsetup2_x002e_blu_optionvalues"] == null ? new string[0] : data["blu_questionsetup2_x002e_blu_optionvalues"].ToString().Split(','), Type = data["blu_questionsetup2_x002e_blu_type"] == null ? 0 : (int)data["blu_questionsetup2_x002e_blu_type"], IsMandatory = data["blu_questionsetup2_x002e_blu_answerismandatory"] == null ? false : (bool)data["blu_questionsetup2_x002e_blu_answerismandatory"], AdditionalProductId = data["blu_questionsetup2_x002e_blu_additionalproduct"] == null ? Guid.Empty : Guid.Parse(data["blu_questionsetup2_x002e_blu_additionalproduct"].ToString()), }; questionSetup.UniqueName = Guid.NewGuid().ToString().Replace("-", ""); questionSetups.Add(questionSetup); } } } fetchXml = string.Empty; fetchXml += "<fetch>"; fetchXml += " <entity name='blu_blu_questionsetup_pricelevel' >"; fetchXml += " <filter type='and' >"; fetchXml += " <condition attribute='pricelevelid' operator='eq' value='" + priceListId + "' />"; fetchXml += " </filter>"; fetchXml += " <link-entity name='blu_questionsetup' from='blu_questionsetupid' to='blu_questionsetupid' link-type='inner' >"; fetchXml += " <attribute name='blu_questionsetupid' />"; fetchXml += " <attribute name='blu_name' />"; fetchXml += " <attribute name='blu_number' />"; fetchXml += " <attribute name='blu_type' />"; fetchXml += " <attribute name='blu_answerdatatype' />"; fetchXml += " <attribute name='blu_optionvalues' />"; fetchXml += " <attribute name='blu_uniquename' />"; fetchXml += " <attribute name='blu_answerismandatory' />"; fetchXml += " <attribute name='blu_additionalproduct' />"; fetchXml += " </link-entity>"; fetchXml += " </entity>"; fetchXml += "</fetch>"; encodedQuery = SharedService.UrlEncode(fetchXml); odataQuery = webApiQueryUrl + "blu_blu_questionsetup_pricelevelset?fetchXml=" + encodedQuery; retrieveResponse = httpClient.GetAsync(odataQuery); jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); if (systemUserObject == null || systemUserObject.value == null) { return(questionSetups); } if (systemUserObject.value.Count == 0) { return(questionSetups); } foreach (var data in systemUserObject.value) { var questionSetup = new InspectionPortalQA() { Id = data["blu_questionsetupid"] == null ? Guid.Empty : Guid.Parse(data["blu_questionsetupid"].ToString()), AnswerDataType = data["blu_questionsetup1_x002e_blu_answerdatatype"] == null ? 0 : (int)data["blu_questionsetup1_x002e_blu_answerdatatype"], AnswerDataTypeText = data["*****@*****.**"] == null ? "" : data["*****@*****.**"].ToString(), Name = data["blu_questionsetup1_x002e_blu_name"] == null ? "" : data["blu_questionsetup1_x002e_blu_name"].ToString(), UniqueQuestionName = data["blu_questionsetup1_x002e_blu_uniquename"] == null ? "" : data["blu_questionsetup1_x002e_blu_uniquename"].ToString(), Number = data["blu_questionsetup1_x002e_blu_number"] == null ? -99 : (int)data["blu_questionsetup1_x002e_blu_number"], OptionSetValues = data["blu_questionsetup1_x002e_blu_optionvalues"] == null ? new string[0] : data["blu_questionsetup1_x002e_blu_optionvalues"].ToString().Split(','), Type = data["blu_questionsetup1_x002e_blu_type"] == null ? 0 : (int)data["blu_questionsetup1_x002e_blu_type"], IsMandatory = data["blu_questionsetup1_x002e_blu_answerismandatory"] == null ? false : (bool)data["blu_questionsetup1_x002e_blu_answerismandatory"], AdditionalProductId = data["blu_questionsetup1_x002e_blu_additionalproduct"] == null ? Guid.Empty : Guid.Parse(data["blu_questionsetup1_x002e_blu_additionalproduct"].ToString()), }; questionSetup.UniqueName = Guid.NewGuid().ToString().Replace("-", ""); questionSetup.Answer = questionSetup.Type == (int)InspectionPortalQA_Type.TC ? "true" : ""; questionSetups.Add(questionSetup); } return(questionSetups); }
public static PortalUser QueryPortalUserByUsernameByPassword(HttpClient httpClient, string username, string password) { var fetchXml = string.Empty; fetchXml += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"; fetchXml += " <entity name='blu_portaluser'>"; fetchXml += " <attribute name='blu_portaluserid' />"; fetchXml += " <attribute name='blu_name' />"; fetchXml += " <attribute name='blu_username' />"; fetchXml += " <attribute name='blu_portaluserrole' />"; fetchXml += " <attribute name='blu_customer' />"; fetchXml += " <order attribute='blu_name' descending='false' />"; fetchXml += " <filter type='and'>"; fetchXml += " <condition attribute='blu_username' operator='eq' value='" + username + "' />"; fetchXml += " <condition attribute='blu_password' operator='eq' value='" + password + "' />"; fetchXml += " </filter>"; fetchXml += " <link-entity name='account' from='accountid' to='blu_customer' visible='false' link-type='outer' alias='account'>"; fetchXml += " <attribute name='blu_hasanaccount' />"; fetchXml += " </link-entity>"; fetchXml += " <link-entity name='contact' from='contactid' to='blu_customer' visible='false' link-type='outer' alias='contact'>"; fetchXml += " <attribute name='blu_hasanaccount' />"; fetchXml += " </link-entity>"; fetchXml += " </entity>"; fetchXml += "</fetch>"; var encodedQuery = SharedService.UrlEncode(fetchXml); var odataQuery = WebApiQueryUrl + "blu_portalusers?fetchXml=" + encodedQuery; var retrieveResponse = httpClient.GetAsync(odataQuery); var jRetrieveResponse = JObject.Parse(retrieveResponse.Result.Content.ReadAsStringAsync().Result); dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString()); if (systemUserObject == null || systemUserObject.value == null) { return(null); } if (systemUserObject.value.Count == 0) { return(null); } foreach (var data in systemUserObject.value) { var customer = new Customer() { Id = data["_blu_customer_value"] == null ? Guid.Empty : Guid.Parse(data["_blu_customer_value"].ToString()), Name = data["*****@*****.**"] == null ? "" : data["*****@*****.**"].ToString(), HasAccount = data["account_x002e_blu_hasanaccount"] == null ? (data["contact_x002e_blu_hasanaccount"] == null ? false : (bool)data["contact_x002e_blu_hasanaccount"]) : (bool)data["account_x002e_blu_hasanaccount"], CustomerType = data["*****@*****.**"] == null ? 0 : (data["*****@*****.**"].ToString() == "account" ? 1 : 2), CustomerTypeText = data["*****@*****.**"] == null ? "" : data["*****@*****.**"].ToString() }; var portalUser = new PortalUser() { Id = data["blu_portaluserid"] == null ? Guid.Empty : Guid.Parse(data["blu_portaluserid"].ToString()), Name = data["blu_name"] == null ? "" : data["blu_name"].ToString(), Username = data["blu_username"] == null ? "" : data["blu_username"].ToString(), CustomerId = customer.Id, PortalUserRole = data["blu_portaluserrole"] == null ? 0 : (int)data["blu_portaluserrole"], Customer = customer, PriceLists = new List <PriceList>() }; return(portalUser); } return(null); }