Exemplo n.º 1
0
        //Търсене на информация за ЧСИ по регистрационен номер и дата
        public async Task <CSIModel> GetCSIByNumberAndDate(string csiNumber, DateTime date)
        {
            var httpClient = new HttpClient();

            UriBuilder builder = new UriBuilder("https://register.bcpea.org/api/findAgentByDateAndNumber");

            System.Collections.Specialized.NameValueCollection collection = System.Web.HttpUtility.ParseQueryString(string.Empty);

            collection.Add("number", csiNumber);
            collection.Add("date", date.ToString("dd-MM-yyyy"));

            builder.Query = collection.ToString();

            var response = await httpClient.GetAsync(builder.Uri);

            if (response.IsSuccessStatusCode)
            {
                var contents = await response.Content.ReadAsStringAsync();

                CSIModel csi = JsonConvert.DeserializeObject <CSIModel>(contents);
                return(csi);
            }
            else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                return(null);
            }
            else
            {
                throw new Exception("Error searching in CHSI register");
            }
        }
Exemplo n.º 2
0
        //Търсене на информация за ЧСИ по регистрационен номер и помощници
        public async Task <CSIModel> GetCSIByNumber(string csiNumber, bool helpers = false)
        {
            var httpClient = new HttpClient();

            UriBuilder builder = new UriBuilder("https://register.bcpea.org/api/findAgentByNumber");

            System.Collections.Specialized.NameValueCollection collection = System.Web.HttpUtility.ParseQueryString(string.Empty);

            collection.Add("number", csiNumber);

            if (helpers == true)
            {
                collection.Add("helpers", "true");
            }

            builder.Query = collection.ToString();

            var response = await httpClient.GetAsync(builder.Uri);

            var contents = await response.Content.ReadAsStringAsync();

            CSIModel csi = JsonConvert.DeserializeObject <CSIModel>(contents);

            return(csi);
        }
        private bool ValidateCHSI(CSIModel model, string fullName)
        {
            bool isValidCHSI = (model.Date_from.HasValue && model.Date_from < DateTime.Now) &&
                               (!model.Date_to.HasValue || model.Date_to > DateTime.Now);

            if (isValidCHSI)
            {
                string[] holderNames  = fullName.Split(' ');
                string[] registerName = model.Name_en.Split(' ');

                isValidCHSI = holderNames[0].ToUpper() == registerName[0].ToUpper() &&
                              holderNames[1].ToUpper() == registerName[1].ToUpper() &&
                              holderNames[2].ToUpper() == registerName[2].ToUpper();
            }

            return(isValidCHSI);
        }