public JsonResult GetPortalUser(string username, string password) { var httpClient = GetHttpClient(); var portalUser = PortalUserService.QueryPortalUserByUsernameByPassword(httpClient, username, password); if (portalUser == null) { return(Json("error", JsonRequestBehavior.AllowGet)); } if (portalUser.PortalUserRole == 0) { return(Json("error:Portaluserrole attribute of portal user object is null!", JsonRequestBehavior.AllowGet)); } List <PriceList> portalUserPriceLists; switch (portalUser.PortalUserRole) { case (int)PortalUserrole.Consumer: portalUserPriceLists = PriceListService.QueryPriceListByPortalUserRole(httpClient, portalUser.PortalUserRole); portalUser.PriceLists.AddRange(portalUserPriceLists); break; case (int)PortalUserrole.Vendor: if (portalUser.CustomerId == Guid.Empty) { return(Json("error:CustomerId attribute of portal user object is null!", JsonRequestBehavior.AllowGet)); } portalUserPriceLists = PriceListService.QueryPriceListByCustomer(GetHttpClient(), portalUser.CustomerId); if (portalUserPriceLists == null || portalUserPriceLists.Count == 0) { portalUserPriceLists = PriceListService.QueryPriceListByPortalUserRole(httpClient, (int)PortalUserrole.Consumer); } portalUser.PriceLists.AddRange(portalUserPriceLists); break; } var currentUser = new CurrentUser() { PortalUser = portalUser }; return(Json(currentUser, JsonRequestBehavior.AllowGet)); }
//public JsonResult GetPriceListItemsByPriceListsByInspection(PortalUser portalUser, Guid inspectionId) //{ // var currentUserPriceLists = portalUser.PriceLists; // return Json(null, JsonRequestBehavior.AllowGet); //} //public JsonResult GetPriceListItemsByPriceLists(List<PriceList> priceLists) //{ // var priceListItems = PriceListService.QueryPriceListItemsByPriceLists(GetHttpClient(), priceLists); // return Json(priceListItems, JsonRequestBehavior.AllowGet); //} public JsonResult GetPriceListItemsByPortalUserRole(int portalUserRole) { var priceListItems = PriceListService.QueryPriceListByPortalUserRole(GetHttpClient(), portalUserRole); return(Json(priceListItems, JsonRequestBehavior.AllowGet)); }
public static List <CartItem> QueryCartItemByInspection(HttpClient httpClient, Guid inspectionId, List <PriceList> priceLists) { try { var cartItems = new List <CartItem>(); if (priceLists == null || priceLists.Count == 0) { priceLists = PriceListService.QueryPriceListByPortalUserRole(httpClient, (int)PortalUserrole.Consumer); } 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='defaultuomid' />"; fetchXml += " <attribute name='blu_buyerpays' />"; fetchXml += " <attribute name='parentproductid' />"; fetchXml += " <attribute name='blu_appointmentduration' />"; fetchXml += " <attribute name='blu_requiredinspectorskills' />"; fetchXml += " <attribute name='blu_sellableto' />"; fetchXml += " <attribute name='blu_reportisreleasedto' />"; fetchXml += " <attribute name='blu_finalbuyerpays' />"; fetchXml += " <attribute name='blu_freereport' />"; fetchXml += " <attribute name='blu_reportisreleasedto' />"; fetchXml += " <filter type='and'>"; fetchXml += " <condition attribute='blu_reportisresellable' operator='eq' value='1' />"; 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 += " </filter>"; fetchXml += " <link-entity name='blu_inspectiondetail' from='blu_productid' to='productid' link-type='inner' alias='ae'>"; fetchXml += " <filter type='and'>"; fetchXml += " <condition attribute='statecode' operator='eq' value='0' />"; 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 += " <link-entity name='product' from='productid' to='blu_stockingproduct' link-type='inner' alias='ag'>"; fetchXml += " <link-entity name='blu_productinventory' from='blu_reporttype' to='productid' link-type='inner' alias='ah'>"; fetchXml += " <filter type='and'>"; fetchXml += " <condition attribute='blu_property' operator='eq' value='" + inspectionId + "' />"; fetchXml += " </filter>"; fetchXml += " </link-entity>"; fetchXml += " </link-entity>"; fetchXml += " </entity>"; fetchXml += "</fetch>"; var encodedQuery = SharedService.UrlEncode(fetchXml); var odataQuery = webApiQueryUrl + EntityPluralName + "?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 cartItem = new CartItem() { ProductId = data["productid"] == null ? Guid.Empty : Guid.Parse(data["productid"].ToString()), ProductName = data["name"] == null ? "" : data["name"].ToString(), ParentProductName = data["*****@*****.**"] ?? "", Amount = data["blu_buyerpays"] == null ? 0 : (decimal)data["blu_buyerpays"], AmountText = data["*****@*****.**"] ?? "", UomId = data["_defaultuomid_value"] == null ? Guid.Empty : Guid.Parse(data["_defaultuomid_value"].ToString()), InspectionDetailStateCode = data["ae_x002e_statecode"] == null ? 0 : (int)data["ae_x002e_statecode"], InspectionDetailStatusCode = data["ae_x002e_statuscode"] == null ? 0 : (int)data["ae_x002e_statuscode"], ProductSkills = data["blu_requiredinspectorskills"] == null ? new string[0] : data["blu_requiredinspectorskills"].ToString().Split(','), AppointmentDuration = data["blu_appointmentduration"] == null ? 0 : (int)data["blu_appointmentduration"], IsPriceOverriden = true, ProductCategory = true, SellableTo = data["blu_sellableto"] == null ? 0 : (int)data["blu_sellableto"], BuyerPays = data["blu_buyerpays"] == null ? 0 : (decimal)data["blu_buyerpays"], BuyerPaysText = data["*****@*****.**"] ?? "", FinalBuyerPays = data["blu_finalbuyerpays"] == null ? 0 : (decimal)data["blu_finalbuyerpays"], FinalBuyerPaysText = data["*****@*****.**"] ?? "", ReportIsReleasedTo = data["blu_reportisreleasedto"] == null ? 0 : (int)data["blu_reportisreleasedto"], ReportIsReleasedToText = data["*****@*****.**"] == null ? "" : data["*****@*****.**"], Conditions = data["blu_conditions"] == null ? "" : data["blu_conditions"], FreeReport = data["blu_freereport"] != null && (bool)data["blu_freereport"], }; 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); } }