public static List <Postal> FindAllPostals()
        {
            var result     = new List <Postal>();
            var connection = new System.Data.SqlClient.SqlConnection(_connectionString);

            connection.Open();
            var command = new System.Data.SqlClient.SqlCommand("", connection);

            command.CommandText = @"
            Select * from [PostalTable]";
            var reader = command.ExecuteReader();

            while (reader.Read())
            {
                Postal item = new Postal();
                //item.ID = reader["ID"].ToString();
                item.PostalCode = Convert.ToInt32(reader["PostalCode"]);
                item.Section    = reader["Section"].ToString();
                item.English    = reader["English"].ToString();
                result.Add(item);
            }
            connection.Close();


            return(result);
        }
Beispiel #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="AbstractCityResponse" /> class.
 /// </summary>
 protected AbstractCityResponse()
 {
     City         = new City();
     Location     = new Location();
     Postal       = new Postal();
     Subdivisions = new List <Subdivision>();
 }
Beispiel #3
0
 protected virtual void CreateArtists(UnitOfWork session) {
     Artist artist = null;
     MovieArtistLine line = MovieArtistLine.GetDirector(session);
     artist = CreateArtist(session, "James", "Cameron");
     Avatar.AddArtist(artist, line);
     artist = CreateArtist(session, "Uwe", "Boll");
     Postal.AddArtist(artist, MovieArtistLine.GetDirector(session));
 }
        public SendEmailResponse SendEmail(Postal.Email email, ILogger log)
        {
            var output = new SendEmailResponse();

            #if !DEBUG
            try
            {
            #endif
            // Process email with Postal
            var emailService = ServiceLocator.Current.GetInstance<Postal.IEmailService>();
            using (var message = emailService.CreateMailMessage(email))
            {
                var htmlView = message.AlternateViews.FirstOrDefault(x => x.ContentType.MediaType.ToLower() == "text/html");
                if (htmlView != null)
                {
                    string body = new StreamReader(htmlView.ContentStream).ReadToEnd();

                    // move ink styles inline with PreMailer.Net
                    var result = PreMailer.Net.PreMailer.MoveCssInline(body, false, "#ignore");

                    htmlView.ContentStream.SetLength(0);
                    var streamWriter = new StreamWriter(htmlView.ContentStream);

                    streamWriter.Write(result.Html);
                    streamWriter.Flush();

                    htmlView.ContentStream.Position = 0;
                }

                // send email with default smtp client. (the same way as Postal)
                using (var smtpClient = new SmtpClient())
                {
                    try
                    {
                        smtpClient.Send(message);
                        output.Success = true;
                    }
                    catch (SmtpException exception)
                    {
                        _logger.Error("Exception: {0}, inner message {1}",exception.Message,(exception.InnerException!=null) ? exception.InnerException.Message : string.Empty);
                        output.Success = false;
                        output.Exception = exception;
                    }
                }
            }

            #if !DEBUG
            }

            catch (Exception ex)
            {
                _logger.Error("Error sending email", ex);
                output.Exception = ex;
            }

            #endif
            return output;
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = new List <ValidationResult>();

            if ((new[] { "US", "CA" }.Contains(CountryCode)) && string.IsNullOrWhiteSpace(Postal))
            {
                results.Add(new ValidationResult("Tape Address Postal Code is required.", new[] { "Postal" }));
            }

            if (CountryCode == "US" && Postal != null && !Regex.Match(Postal, @"^\d{1,5}(\-\d{4})?$").Success)
            {
                results.Add(new ValidationResult("Tape Address Postal Code is not valid.", new[] { "Postal" }));
            }

            if ((new[] { "US", "CA", "BR", "AU", "IT", "MX" }.Contains(CountryCode)) && string.IsNullOrWhiteSpace(StateProvince))
            {
                results.Add(new ValidationResult("Tape Address State/Province is required.", new[] { "StateProvince" }));
            }

            if (CountryCode == "CA" && !string.IsNullOrWhiteSpace(Postal))
            {
                if (!Regex.Match(Postal, @"(\D\d\D\s\d\D\d)").Success)
                {
                    results.Add(new ValidationResult("Tape Address Postal Code is not valid.", new[] { "Postal" }));
                }

                var canadaPostalValidations = new[]
                {
                    new Tuple <string, string> ("T", "AB"),
                    new Tuple <string, string> ("V", "BC"),
                    new Tuple <string, string> ("R", "MB"),
                    new Tuple <string, string> ("E", "NB"),
                    new Tuple <string, string> ("A", "NL"),
                    new Tuple <string, string> ("B", "NS"),
                    new Tuple <string, string> ("X", "NT"),
                    new Tuple <string, string> ("K", "ON"),
                    new Tuple <string, string> ("L", "ON"),
                    new Tuple <string, string> ("M", "ON"),
                    new Tuple <string, string> ("N", "ON"),
                    new Tuple <string, string> ("P", "ON"),
                    new Tuple <string, string> ("C", "PE"),
                    new Tuple <string, string> ("G", "QC"),
                    new Tuple <string, string> ("H", "QC"),
                    new Tuple <string, string> ("J", "QC"),
                    new Tuple <string, string> ("S", "SK"),
                    new Tuple <string, string> ("Y", "YT")
                };

                if (!canadaPostalValidations.Any(x => x.Item1 == Postal.Substring(0, 1).ToUpper() && StateProvince == x.Item2))
                {
                    results.Add(new ValidationResult("Tape Address State/Province and Postal Code is not a valid combination.", new[] { "Postal" }));
                }
            }

            return(results);
        }
Beispiel #6
0
        /*
         * Function to change a customers information.
         * This function will recieve a customer (a mix model). First the function will check if the customer
         * exists in the database for security reasons. If it exists the user data will be overwritten.
         * This function will also check if the new zipcode entered by the user exists or not. If it does not
         * exists it will be added to the database.
         */
        public bool editUser(Customer inCustomer)
        {
            try
            {
                using (var db = new ModelContext())
                {
                    // Find the user
                    User selectUser = db.Users.FirstOrDefault
                                          (u => u.personalIdentification == inCustomer.personalIdentification);

                    // User does not exists or something went wrong.
                    if (selectUser == null)
                    {
                        return(false);
                    }
                    else
                    {
                        // Overwrite old data with new data.
                        selectUser.firstname   = inCustomer.firstname;
                        selectUser.lastname    = inCustomer.lastname;
                        selectUser.address     = inCustomer.address;
                        selectUser.phoneNumber = inCustomer.phoneNumber;
                        selectUser.email       = inCustomer.email;

                        // Find the postal.
                        Postal verifyPostal = db.Postals.FirstOrDefault
                                                  (p => p.postalCode == inCustomer.zipCode);

                        // Postal does not exist.
                        if (verifyPostal == null)
                        {
                            // Adding new posta to database and merge with customer.
                            Postal newPostal = new Postal();
                            newPostal.postalCode = inCustomer.zipCode;
                            newPostal.city       = inCustomer.city;
                            db.Postals.Add(newPostal);
                            selectUser.postalCode = newPostal;
                        }
                        else
                        {
                            // Postal exists. Merge with customer.
                            selectUser.postalCode = verifyPostal;
                        }
                        db.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (Exception error)
            {
                logErrorToFile(error);
                return(false);
            }
        }
Beispiel #7
0
        // GET: api/Assets/5

        public IHttpActionResult GetHotel(int id)
        {
            //Asset asset =(Asset) db.Asset.Find(id);
            Postal item = _RepositoryHandlerCollection.PostalHandler.GetById(id);

            if (item == null)
            {
                return(NotFound());
            }

            return(Ok(item));
        }
Beispiel #8
0
        public void Test2()
        {
            var def    = MessageParser.ParseText(Test);
            var postal = new Postal();

            postal.OutputDir = AppDomain.CurrentDomain.BaseDirectory;
            var codeDOM = postal.GenerateCodeDOM("Test.postal", def);
            var code    = postal.GenerateCSharpCode(codeDOM);
            var header  = postal.GenerateHeaderFile(def);

            File.WriteAllText("Test.cs", code);
            var proto = postal.GenerateProtoFile("Test.cs", postal.GenerateCodeDOM("Test.postal", def), def);
        }
Beispiel #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 public CityIspOrgResponse(
     City city                             = null,
     Continent continent                   = null,
     Country country                       = null, Location location = null,
     Model.MaxMind maxMind                 = null,
     Postal postal                         = null,
     Country registeredCountry             = null,
     RepresentedCountry representedCountry = null,
     List <Subdivision> subdivisions       = null,
     Traits traits                         = null)
     : base(
         city, continent, country, location, maxMind, postal, registeredCountry, representedCountry, subdivisions, traits)
 {
 }
Beispiel #10
0
 public CityResponse(
     City city           = null,
     Continent continent = null,
     Country country     = null,
     Location location   = null,
     [Parameter("maxmind")] Model.MaxMind maxMind = null,
     Postal postal = null,
     [Parameter("registered_country")] Country registeredCountry = null,
     [Parameter("represented_country")] RepresentedCountry representedCountry = null,
     IEnumerable <Subdivision> subdivisions    = null,
     [Parameter("traits", true)] Traits traits = null)
     : base(
         city, continent, country, location, maxMind, postal, registeredCountry, representedCountry, subdivisions,
         traits)
 {
 }
Beispiel #11
0
        public List <Field> GetFields()
        {
            List <Field> fields = GetEmptyFields();

            fields[0].SetValue(Name);
            fields[1].SetValue(Surname);
            fields[2].SetValue(Dni.ToString());
            fields[3].SetValue(Mail);
            fields[4].SetValue(Tel.ToString());
            fields[5].SetValue(Dir);
            fields[6].SetValue(City);
            fields[7].SetValue(Postal.ToString());
            fields[8].SetValue(BirthDate.ToString("yyyy-MM-dd HH.mmm:ss:l"));
            fields[9].SetValue(Endabled.ToString());
            fields[10].SetValue(User);
            return(fields);
        }
        // GET: Postal
        public ActionResult Index(string search = "", int PostalCode = -1)
        {
            var postallocations = RV.Databases.PostalLocationDatabase.FindAllPostalLocation();
            var postals         = RV.Databases.PostalDatabase.FindAllPostals();

            if (postallocations.Count == 0)
            {
                postallocations = PostalData.GetPostalLocation();
                RV.Databases.PostalLocationDatabase.Create(postallocations);
            }
            if (postals.Count == 0)
            {
                postals = PostalData.GetPostal();
                RV.Databases.PostalDatabase.Create(postals);
            }
            if (!string.IsNullOrEmpty(search))
            {
                postals = postals
                          .Where(x =>
                                 x.PostalCode.ToString().Contains(search) ||
                                 x.Section.Contains(search))
                          .ToList();
            }
            ViewBag.Search = search;

            if (PostalCode != -1)
            {
                foreach (var postallocation in postallocations)
                {
                    if (postallocation.PostalCode == PostalCode)
                    {
                        PostalController.postallocation = postallocation;
                    }
                }
                foreach (var postal in postals)
                {
                    if (postal.PostalCode == PostalCode)
                    {
                        PostalController.postal = postal;
                    }
                }
            }
            //ViewBag.Stations = stations;

            return(View(postals));
        }
Beispiel #13
0
        public List <Field> GetFields()
        {
            List <Field> f = GetEmptyFields();

            f[0].SetValue(Cuit);
            f[1].SetValue(Rsocial);
            f[2].SetValue(Mail);
            f[3].SetValue(Tel.ToString());
            f[4].SetValue(Domicilio);
            f[5].SetValue(Localidad);
            f[6].SetValue(Ciudad);
            f[7].SetValue(Rubro);
            f[8].SetValue(Postal.ToString());
            f[9].SetValue(ProvNombre);
            f[10].SetValue(Endabled.ToString());
            f[11].SetValue(user);
            return(f);
        }
Beispiel #14
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="AbstractCityResponse" /> class.
 /// </summary>
 protected AbstractCityResponse(
     City city                              = null,
     Continent continent                    = null,
     Country country                        = null,
     Location location                      = null,
     Model.MaxMind maxMind                  = null,
     Postal postal                          = null,
     Country registeredCountry              = null,
     RepresentedCountry representedCountry  = null,
     IEnumerable <Subdivision> subdivisions = null,
     Traits traits                          = null)
     : base(continent, country, maxMind, registeredCountry, representedCountry, traits)
 {
     City         = city ?? new City();
     Location     = location ?? new Location();
     Postal       = postal ?? new Postal();
     Subdivisions = subdivisions != null ? new List <Subdivision>(subdivisions) : new List <Subdivision>();
 }
        /// <summary>
        /// Method for populating the database with address data.
        /// </summary>
        /// <param name="staticMapData">The staticdata object.</param>
        private void UpdateDatabase(StaticMapData staticMapData)
        {
            using (var context = new InformationContext())
            {
                Dispatcher.Invoke(() => { lblNumberOfRecords.Content = context.Persons.Count().ToString(); });

                Postal postal = context.Postals.Where(x =>
                                                      x.PostalCode == staticMapData.PostalCode &&
                                                      x.City == staticMapData.City).FirstOrDefault();

                if (postal == null)
                {
                    context.Postals.Add(staticMapData.GetPostal());
                    context.SaveChanges();
                    return;
                }

                Address address = context.Addresses.Where(x =>
                                                          x.Street == staticMapData.Addr1 &&
                                                          x.PostalCode == staticMapData.PostalCode).FirstOrDefault();

                if (address == null)
                {
                    postal.Addresses.Add(staticMapData.GetAddress(postal));
                    context.SaveChanges();
                    return;
                }

                Person person = context.Persons.Where(x =>
                                                      x.DataId.ToString() == staticMapData.Id).FirstOrDefault();

                if (person == null)
                {
                    address.Persons.Add(staticMapData.GetPerson(address));
                    context.SaveChanges();
                }
            }
        }
 private bool Send(Postal.Email emailMessage)
 {
     var result = _emailDispatcher.SendEmail(emailMessage, Log);
     if (result.Success)
         return true;
     Log.Error(result.Exception.Message, result.Exception);
     return false;
 }
 private bool AttemptSendOf(Postal.Email emailMessage)
 {
     try
     {
         return Send(emailMessage);
     }
     catch (Exception ex)
     {
         Log.Error("Error occured when sending ResetPassword emailMessage.", ex);
         return false;
     }
 }
 public SendEmailResponse SendEmail(Postal.Email email)
 {
     var log = LogManager.GetLogger();
     return SendEmail(email, log);
 }
 public SendEmailResponse SendEmail(Postal.Email email)
 {
     return SendEmail(email, _logger);
 }
Beispiel #20
0
        //
        // Oppsummering:
        //     Representerer testdata til prosjektet. Brukere, kontoer og transaksjoner opprettes her.
        //
        public static void initialize_test_data()
        {
            DB daldb = new DB();

            // Open connection to Database
            using (var db = new ModelContext())
            {
                // Get user
                var      exist   = from a in db.Users where a.firstname == "Ola" select a;
                DateTime setDate = DateTime.Now;

                // Check if user exist
                if (!exist.Any())
                {
                    try
                    {
                        string[] salt = { daldb.Create_Salt(), daldb.Create_Salt(), daldb.Create_Salt() };

                        Postal newPostal = null;
                        // Postalcode
                        newPostal = new Postal
                        {
                            postalCode = "0707",
                            city       = "Oslo"
                        };


                        // accountType
                        AccountType newAccountType = new AccountType
                        {
                            card      = true,
                            interest  = 3.00,
                            limit     = 10000,
                            yearlyFee = 0
                        };

                        // User1 account
                        Account account1 = new Account
                        {
                            accountNumber = "44444444444",
                            name          = "Savings account",
                            balance       = 10000,
                            accountType   = newAccountType,
                            active        = true
                        };

                        // User2 account1
                        Account account2_1 = new Account
                        {
                            accountNumber = "11111111111",
                            name          = "Savings account",
                            balance       = 4100.50,
                            accountType   = newAccountType,
                            active        = true
                        };

                        // User2 account2
                        Account account2_2 = new Account
                        {
                            accountNumber = "22222222222",
                            name          = "Checkings account",
                            balance       = 1533.40,
                            accountType   = newAccountType,
                            active        = true
                        };

                        // User2 account3
                        Account account2_3 = new Account
                        {
                            accountNumber = "33333333333",
                            name          = "Loan account",
                            balance       = 0.00,
                            accountType   = newAccountType,
                            active        = false
                        };

                        // User3 account
                        Account account3 = new Account
                        {
                            accountNumber = "55555555555",
                            name          = "Savings account",
                            balance       = 2500,
                            accountType   = newAccountType,
                            active        = true
                        };

                        // Transaction from user 1 account to user 2 account
                        Transaction transaction1 = new Transaction
                        {
                            date          = setDate.Date,
                            fromAccount   = account1,
                            toAccount     = account2_1,
                            amount        = 500,
                            message       = "Vi er skuls",
                            isTransferred = true
                        };

                        // Transaction from user 2 account too user 3 account
                        Transaction transaction2 = new Transaction
                        {
                            date          = setDate.Date,
                            fromAccount   = account2_1,
                            toAccount     = account3,
                            amount        = 250,
                            message       = "Mat greier",
                            isTransferred = true
                        };

                        // Transaction from user 3 account too user 1 account
                        Transaction transaction3 = new Transaction
                        {
                            date          = setDate.Date,
                            fromAccount   = account3,
                            toAccount     = account1,
                            amount        = 1500,
                            message       = "Nasty stuff",
                            isTransferred = false
                        };

                        // Add user 1
                        User user1 = new User
                        {
                            personalIdentification = "11111111111",
                            firstname   = "Ola",
                            lastname    = "Nordmann",
                            address     = "Nordmannveien 32",
                            postalCode  = newPostal,
                            phoneNumber = "07070707",
                            email       = "*****@*****.**",
                            salt        = salt[0],
                            password    = daldb.Create_Hash("password" + salt[0]),
                            active      = true,
                            accounts    = new List <Account> {
                                account1
                            }
                        };

                        // Add user 2
                        User user2 = new User
                        {
                            personalIdentification = "22222222222",
                            firstname   = "Kari",
                            lastname    = "Nordmann",
                            address     = "Nordmannveien 32",
                            postalCode  = newPostal,
                            phoneNumber = "06060606",
                            email       = "*****@*****.**",
                            salt        = salt[1],
                            password    = daldb.Create_Hash("password" + salt[1]),
                            active      = true,
                            accounts    = new List <Account> {
                                account2_1, account2_2, account2_3
                            }
                        };

                        // Add user 3
                        User user3 = new User
                        {
                            personalIdentification = "33333333333",
                            firstname   = "Nils",
                            lastname    = "Nordmann",
                            address     = "Nordmannveien 32",
                            postalCode  = newPostal,
                            phoneNumber = "05050505",
                            email       = "*****@*****.**",
                            salt        = salt[2],
                            password    = daldb.Create_Hash("password3" + salt[2]),
                            active      = true,
                            accounts    = new List <Account> {
                                account3
                            }
                        };

                        Admin admin1 = new Admin
                        {
                            personalIdentification = "22222222222"
                        };
                        db.Admins.Add(admin1);

                        // Add Transanctions
                        db.Transactions.Add(transaction1);
                        db.Transactions.Add(transaction2);
                        db.Transactions.Add(transaction3);

                        // Add Accounts
                        db.Accounts.Add(account1);
                        db.Accounts.Add(account2_1);
                        db.Accounts.Add(account2_2);
                        db.Accounts.Add(account2_3);
                        db.Accounts.Add(account3);

                        // Add Users
                        db.Users.Add(user1);
                        db.Users.Add(user2);
                        db.Users.Add(user3);

                        // Save data to Database
                        db.SaveChanges();
                    }
                    catch (Exception error)
                    {
                        Console.Write(error);
                    }
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Send a simple HTML based email
        /// </summary>
        private void Send(Postal.Email email)
        {
            ////create a new message object
            //var message = SendGrid.GenerateInstance();

            //message.AddTo(to);

            ////set the sender
            //message.From = new MailAddress(from);

            ////set the message body
            //message.Html = CreateHtmlMailFromView(view); // "<html><p>Hello</p><p>World</p></html>";

            //message.Text = "sdfsdfsdf";

            ////set the message subject
            //message.Subject = "Hello World HTML Test";

            ////enable Open Tracking
            //message.EnableOpenTracking();

            ////enable clicktracking
            //message.EnableClickTracking(false);

            ////enable spamcheck
            //message.EnableSpamCheck();

            ////create an instance of the SMTP transport mechanism
            //var transportInstance = SMTP.GenerateInstance(new NetworkCredential("username", "password"));

            ////send the mail
            //transportInstance.Deliver(message);
        }
        private async void RecallLookup_Clicked(object sender, EventArgs e)
        {
            try
            {
                bool connection = CrossConnectivity.Current.IsConnected;


                if (connection)
                {
                    Indicator.IsRunning = true;
                    Indicator.IsVisible = true;

                    if (userZip.Text != null && userZip.Text != "")
                    {
                        HttpClient client = new HttpClient();

                        /*added an exception for iOS in info.plist https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/ats#optout */

                        string dictionaryEndpoint    = "http://api.geonames.org/postalCodeSearchJSON?formatted=true&country=US&postalcode=" + userZip.Text + "&username=abezat";
                        Uri    dictionaryUri         = new Uri(dictionaryEndpoint);
                        HttpResponseMessage response = await client.GetAsync(dictionaryEndpoint);

                        if (response.IsSuccessStatusCode)
                        {
                            string jsonString = await response.Content.ReadAsStringAsync();

                            var myPostal = Postal.FromJson(jsonString);

                            PostalCode result    = myPostal.PostalCodes.First();
                            string     ZipToCity = result.PlaceName;
                            userEntry.Text = ZipToCity;

                            Analytics.TrackEvent("Successfully Retrived zip code info");
                        }
                    }
                    if (userEntry.Text != null && userEntry.Text != "")
                    {
                        string d1 = D1.Date.ToString("yyyyMMdd");
                        string d2 = D2.Date.ToString("yyyyMMdd");

                        //string userString = userEntry.Text;
                        //userString = userString.ToLower();

                        HttpClient          client             = new HttpClient();
                        string              dictionaryEndpoint = "https://api.fda.gov/drug/enforcement.json?search=report_date:[" + d1 + "+TO+" + d2 + "]+AND+city:" + userEntry.Text + "+AND+status:ongoing&limit=100";
                        Uri                 dictionaryUri      = new Uri(dictionaryEndpoint);
                        HttpResponseMessage response           = await client.GetAsync(dictionaryEndpoint);

                        if (response.IsSuccessStatusCode)
                        {
                            Indicator.IsRunning = false;
                            Indicator.IsVisible = false;
                            string jsonString = await response.Content.ReadAsStringAsync();

                            var myRecalls = MyRecalls.FromJson(jsonString);

                            //List<Define> myDefinitions = JsonConvert.DeserializeObject<List<Define>>(jsonContent);

                            //if (myRecalls.Meta.Results.Total > 0)
                            //{
                            myRecallsCollection.Clear();
                            myRecalls.Results.ForEach(myRecallsCollection.Add);
                            RecallsListView.ItemsSource = myRecallsCollection;
                            RecallsListView.IsVisible   = true;
                            userLabel.IsVisible         = false;

                            Analytics.TrackEvent("Successfully Retrived recall info");

                            //RecallsListView_Refreshing(RecallsListView, null);
                            //}

                            //else
                            //{
                            //    userLabel.Text = "NO RECALLS IN YOUR CITY WITHIN LAST YEAR";    //strings of letters that are not words, but still return success
                            //    userLabel.IsVisible = true;
                            //    RecallsListView.IsVisible = false;
                            //}
                        }
                        else
                        {
                            Indicator.IsRunning       = false;
                            Indicator.IsVisible       = false;
                            userLabel.Text            = "YOUR ENTRY RETURNED ZERO RESULTS"; //for empty strings
                            userLabel.IsVisible       = true;
                            RecallsListView.IsVisible = false;
                        }
                    }
                    else
                    {
                        Indicator.IsRunning = false;
                        Indicator.IsVisible = false;
                        userLabel.Text      = "PLEASE ENTER A CITY NAME";
                        userLabel.IsVisible = true;
                    }
                }
                else
                {
                    Indicator.IsRunning = false;
                    Indicator.IsVisible = false;
                    await DisplayAlert("No Internet", "No Internet Connection Detected", "OK");

                    userLabel.IsVisible       = true;
                    RecallsListView.IsVisible = false;
                }

                var s  = userZip.Text;
                var s2 = userEntry.Text;

                if ((userZip.Text == null || userZip.Text == "") && (userEntry.Text == null || userEntry.Text == ""))
                {
                    userSearch.IsVisible = false;
                }
                else
                {
                    userSearch.IsVisible = true;
                    userSearch.Text      = "You've searched: " + userEntry.Text;
                }
                if (userZip.Text != null && userZip.Text != "")
                {
                    userSearch.Text += ", " + userZip.Text;
                }
                userEntry.Text = null;
                userZip.Text   = null;
            }
            catch (Exception exception)
            {
                Crashes.TrackError(exception);
            }
        }
        public async Task saveFile(List <IFormFile> files, string directory, string subDirectory, CancellationToken cancellationToken)
        {
            subDirectory = subDirectory ?? string.Empty;
            var target = Path.Combine(directory, subDirectory);

            Directory.CreateDirectory(target);

            foreach (IFormFile file in files)
            {
                if (file.Length <= 0)
                {
                    return;
                }
                var filePath = Path.Combine(target, file.FileName);
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(stream, cancellationToken);

                    try
                    {
                        // add to read encoded 1252 values
                        using (var package = new ExcelPackage(stream))
                        {
                            // Express worksheet
                            ExcelWorksheet worksheet = package.Workbook.Worksheets["Express"];
                            int            colCount  = worksheet.Dimension.End.Column; //get Column Count
                            int            rowCount  = worksheet.Dimension.End.Row;

                            List <Express> lsShippingExpress = new List <Express>();
                            for (int row = 2; row < rowCount; row++)
                            {
                                Express shippingExpress = new Express();
                                shippingExpress.id = row - 1;
                                for (int col = 1; col < colCount; col++)
                                {
                                    string currValue = worksheet.Cells[row, col].Value == null ? string.Empty : worksheet.Cells[row, col].Value.ToString();
                                    switch (col)
                                    {
                                    case 1:
                                        // break if there is no fake rows
                                        if (!currValue.Equals("Express", StringComparison.OrdinalIgnoreCase))
                                        {
                                            goto ExpressEnd;
                                        }
                                        shippingExpress.type = currValue;
                                        break;

                                    case 2:
                                        shippingExpress.trackable = currValue;
                                        break;

                                    case 3:
                                        shippingExpress.service_level = currValue;
                                        break;

                                    case 4:
                                        shippingExpress.country = currValue;
                                        break;

                                    case 5:
                                        shippingExpress.country_code = currValue;
                                        break;

                                    case 6:
                                        shippingExpress.rate_flag = NumberUtil.convertStringToInt(currValue);
                                        break;

                                    case 7:
                                        shippingExpress.weight = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 8:
                                        shippingExpress.dhl_express = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 9:
                                        shippingExpress.sf_economy = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 10:
                                        shippingExpress.ninja_van = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 11:
                                        shippingExpress.zone = NumberUtil.convertStringToInt(currValue);
                                        break;
                                    }
                                }
                                lsShippingExpress.Add(shippingExpress);
                            }

ExpressEnd:
                            {
                                Console.WriteLine(lsShippingExpress.Count);

                                // delete everything in the database
                                await _shippingExpressRepository.deleteAllRecords(cancellationToken);

                                var result = await _shippingExpressRepository.insertRecords(lsShippingExpress, cancellationToken);
                            }

                            // process bulk file
                            worksheet = package.Workbook.Worksheets["Bulk Mail"];
                            colCount  = worksheet.Dimension.End.Column; //get Column Count
                            rowCount  = worksheet.Dimension.End.Row;
                            List <Bulk> lsShippingBulk = new List <Bulk>();
                            for (int row = 4; row < rowCount; row++)
                            {
                                Bulk shippingBulk = new Bulk();
                                shippingBulk.id = row - 3;
                                for (int col = 1; col < colCount; col++)
                                {
                                    string currValue = worksheet.Cells[row, col].Value == null ? string.Empty : worksheet.Cells[row, col].Value.ToString();
                                    switch (col)
                                    {
                                    case 1:
                                        // break if there is no fake rows
                                        if (!currValue.Equals("Bulk", StringComparison.OrdinalIgnoreCase))
                                        {
                                            goto BulkEnd;
                                        }
                                        shippingBulk.type = currValue;
                                        break;

                                    case 2:
                                        shippingBulk.trackable = currValue;
                                        break;

                                    case 3:
                                        shippingBulk.service_level = currValue;
                                        break;

                                    case 4:
                                        shippingBulk.country = currValue;
                                        break;

                                    case 5:
                                        shippingBulk.country_code = currValue;
                                        break;

                                    case 6:
                                        shippingBulk.item_weight_kg = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 7:
                                        shippingBulk.total_weight_kg = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 8:
                                        shippingBulk.ascendia_item_rate = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 9:
                                        shippingBulk.ascendia_rate_per_kg = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 10:
                                        shippingBulk.singpost_item_rate = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 11:
                                        shippingBulk.singpost_rate_per_kg = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 12:
                                        shippingBulk.dai_item_rate = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 13:
                                        shippingBulk.dai_rate_per_kg = NumberUtil.convertStringToDouble(currValue);
                                        break;
                                    }
                                }

                                lsShippingBulk.Add(shippingBulk);
                            }

BulkEnd:
                            {
                                Console.WriteLine(lsShippingBulk.Count);

                                // delete everything in the database
                                await _shippingBulkRepository.deleteAllRecords(cancellationToken);

                                var result = await _shippingBulkRepository.insertRecords(lsShippingBulk, cancellationToken);
                            }


                            // process bulk file
                            worksheet = package.Workbook.Worksheets["Postal"];
                            colCount  = worksheet.Dimension.End.Column; //get Column Count
                            rowCount  = worksheet.Dimension.End.Row;
                            List <Postal> lsShippingPostal = new List <Postal>();
                            for (int row = 4; row < rowCount; row++)
                            {
                                Postal shippingPostal = new Postal();
                                shippingPostal.id = row - 3;
                                for (int col = 1; col < colCount; col++)
                                {
                                    string currValue = worksheet.Cells[row, col].Value == null ? string.Empty : worksheet.Cells[row, col].Value.ToString();
                                    switch (col)
                                    {
                                    case 1:
                                        // break if there is no fake rows
                                        if (!currValue.Equals("Postal", StringComparison.OrdinalIgnoreCase))
                                        {
                                            goto PostalEnd;
                                        }
                                        shippingPostal.type = currValue;
                                        break;

                                    case 2:
                                        shippingPostal.trackable = currValue;
                                        break;

                                    case 3:
                                        shippingPostal.service_level_days = currValue;
                                        break;

                                    case 4:
                                        shippingPostal.country = currValue;
                                        break;

                                    case 5:
                                        shippingPostal.country_code = currValue;
                                        break;

                                    case 6:
                                        shippingPostal.item_weight_kg = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 7:
                                        shippingPostal.singpost_item_rate = NumberUtil.convertStringToDouble(currValue);
                                        break;

                                    case 8:
                                        shippingPostal.singpost_rate_per_kg = NumberUtil.convertStringToDouble(currValue);
                                        break;
                                    }
                                }

                                lsShippingPostal.Add(shippingPostal);
                            }

PostalEnd:
                            {
                                Console.WriteLine(lsShippingPostal.Count);

                                // delete everything in the database
                                await _shippingPostalRepository.deleteAllRecords(cancellationToken);

                                var result = await _shippingPostalRepository.insertRecords(lsShippingPostal, cancellationToken);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
        }