示例#1
0
        /// <summary>
        /// Inventories the master interface.
        /// </summary>
        /// <param name="lastRunDate">The last run date.</param>
        /// <param name="facilityPK">The facility pk.</param>
        /// <param name="syncFlag">if set to <c>true</c> [synchronize flag].</param>
        /// <returns>Task.</returns>
        private static async Task InventoryMasterInterface(DateTime lastRunDate, Guid?facilityPK, bool?syncFlag)
        {
            const string INVNTORY_URL_TMPL           = "/odata/Inventory/GetAllFromDate(from={0},facilityId={1},syncFlag={2})";
            const string INVNTORY_LOCATIONS_URL_TMPL = "/odata/InventoryLocations/GetAllFromDate(from={0},facilityId={1},syncFlag={2})";
            const string INVNTORY_VENDORS_URL_TMPL   = "/odata/InventoryVendors/GetAllFromDate(from={0},facilityId={1},syncFlag={2})";
            const string VENDORS_URL_TMPL            = "/odata/Vendors/GetVendorsInfo(facilityId={0})";
            const string DATE_FORMAT = "yyyy-MM-dd";

            var client = new EnviODataClient(_baseAddress, _clientId, _username, _password);

            //Retrieving of Inventory Info
            var inventoryUrl = string.Format(INVNTORY_URL_TMPL,
                                             lastRunDate.ToString(DATE_FORMAT),
                                             facilityPK?.ToString() ?? "null",
                                             syncFlag?.ToString() ?? "null");
            var inventoryResponse = await client.Get <ODataListResponse <Inventory> >(inventoryUrl);

            // Retrieving of corresponding Inventory/Locations
            var inventoryLocationsUrl = string.Format(INVNTORY_LOCATIONS_URL_TMPL,
                                                      lastRunDate.ToString(DATE_FORMAT),
                                                      facilityPK?.ToString() ?? "null",
                                                      syncFlag?.ToString() ?? "null");
            var inventoryLocationsResponse = await client.Get <ODataListResponse <InventoryLocation> >(inventoryLocationsUrl);

            // Retrieving of corresponding Inventory/Vendors
            var inventoryVendorsUrl = string.Format(INVNTORY_VENDORS_URL_TMPL,
                                                    lastRunDate.ToString(DATE_FORMAT),
                                                    facilityPK?.ToString() ?? "null",
                                                    syncFlag?.ToString() ?? "null");
            var inventoryVendorsResponse = await client.Get <ODataListResponse <InventoryVendor> >(inventoryVendorsUrl);

            // Getting information combined (adding of Inventory/Vendors and Inventory/Locations to corresponding Inventory)
            inventoryResponse.Value.ForEach(i => i.InventoryLocations = new List <InventoryLocation>(inventoryLocationsResponse.Value.Where(il => il.InventoryId == i.InventoryId).ToList()));
            inventoryResponse.Value.ForEach(i => i.InventoryVendors   = new List <InventoryVendor>(inventoryVendorsResponse.Value.Where(iv => iv.InventoryId == i.InventoryId).ToList()));

            // Retrieving of resulting Vendor Ids
            var vendorIds = inventoryVendorsResponse.Value.GroupBy(pk => pk.VendorId).Select(g => g.Key).ToList();

            // Retrieving of Vendors information
            var vendorsUrl = string.Format(VENDORS_URL_TMPL, facilityPK?.ToString() ?? "null");
            var idList     = new ListRepresentation <Guid?> {
                Value = vendorIds
            };
            var vendorsResponse = await client.Post <ListRepresentation <Guid?>, ODataListResponse <VendorInfo> >(vendorsUrl, idList);

            //Interface data consists of two lists:
            var vendors   = vendorsResponse.Value;
            var inventory = inventoryResponse.Value;

            await Task.FromResult(0);
        }
示例#2
0
        /// <summary>
        /// Inventories the examples.
        /// </summary>
        /// <returns>Task.</returns>
        private static async Task InventoryExamples()
        {
            var client = new EnviODataClient(_baseAddress, _clientId, _username, _password);

            var inventoryList = await client.Get <ODataListResponse <Inventory> >("/odata/Inventory");

            var inventoryId = inventoryList.Value[0].InventoryId;;

            if (inventoryId != null)
            {
                var inventoryById = await GetInventoryById(inventoryId.Value);
            }

            var newItem  = GetNewInventory();
            var response = await client.Post <Inventory, ODataSingleValueResponse <Guid> >("/odata/Inventory", newItem);

            var inventory = await client.Get <Inventory>($"/odata/Inventory({response.Value})");

            inventory.HCPCSCode  = "H0001";
            inventory.UNSPSCCode = "41120000";

            var success = await client.Put <Inventory>($"/odata/Inventory({inventory.InventoryId.Value})", inventory);

            if (success)
            {
                if (inventory.InventoryId != null)
                {
                    var inventoryById = await client.Get <Inventory>($"/odata/Inventory({inventory.InventoryId.Value})");
                }
            }

            Inventory patch = new Inventory
            {
                UNSPSCCode = "41120000ch"
            };

            success = await client.Patch <Inventory>($"/odata/Inventory({inventory.InventoryId.Value})", patch);

            if (inventory.InventoryId != null && success)
            {
                var inventoryById = await client.Get <Inventory>($"/odata/Inventory({inventory.InventoryId.Value})");
            }
        }