Ejemplo n.º 1
0
        private async void LoadLookups()
        {
            this.UseWaitCursor = true;
            var supplier = _context.Supplier.SingleOrDefault(s => s.EnumValue == (int)FlexInterfaces.Enumerations.FlexExternalSuppliers.FareHarbor);

            if (supplier == null)
            {
                this.DisplayError("The supplier was not found.");
            }
            else
            {
                var guid = supplier.GUID;
                _supplierConnection = _context.SupplierConnection.FirstOrDefault(s => s.Supplier_GUID == guid);
                var rq        = new CommonRQ();
                var companies = await GetDataFromAPI <Company>(typeof(CompaniesRS), _supplierConnection, "companies/", rq);

                imageComboBoxEditCompanies.Properties.Items.Add(new ImageComboBoxItem());
                imageComboBoxEditCompanies.Properties.Items.AddRange(
                    companies.Select(c => new ImageComboBoxItem()
                {
                    Description = c.Name, Value = c.Shortname
                }).ToArray());
            }

            var lookup = new List <CodeName> {
                new CodeName(null)
            };

            lookup.AddRange(_context.CITYCOD
                            .OrderBy(o => o.CODE)
                            .Select(s => new CodeName()
            {
                Code = s.CODE, Name = s.NAME
            }));
            searchLookUpEditCity.Properties.DataSource = lookup;

            lookup = new List <CodeName> {
                new CodeName(null)
            };
            lookup.AddRange(_context.SERVTYPE
                            .OrderBy(o => o.TYPE)
                            .Select(s => new CodeName()
            {
                Code = s.TYPE, Name = s.DESCRIP
            }));
            searchLookUpEditServiceType.Properties.DataSource = lookup;
            this.UseWaitCursor = false;
        }
Ejemplo n.º 2
0
        private async Task <List <T> > GetDataFromAPI <T>(Type type, SupplierConnection connection, string url, CommonRQ request)
        {
            Dictionary <string, string> headers = new Dictionary <string, string> {
                { "X-FareHarbor-API-App", connection.Login },
                { "X-FareHarbor-API-User", connection.Secret },
            };
            List <T> list = new List <T>();

            //convert strongly typed class to dictionary of request parameters
            Dictionary <string, string> parameters = request.AsDictionary();
            string result = await ApiInvoker.SendRequestGet(connection.URL + url, parameters, headers);

            var      rs     = JsonConvert.DeserializeObject(result, type); //Deserialize the data as the provided type
            CommonRS common = (CommonRS)rs;                                //We know all returned data can be cast to this basic type
            var      data   = common.GetData <T>();                        //Get the actual list of results as generic type

            list.AddRange(data);
            return(list);
        }