コード例 #1
0
        public async void SignUp()
        {
            if (!CheckValidNewPassword())
            {
                return;
            }
            if (CheckExistUsername())
            {
                return;
            }

            ShowError = false;

            //TEST INTERNET CONNECTTION =========================================
            var    httpClient = new HttpClient();
            string x          = "";

            try
            {
                var testInternet = await httpClient.GetStringAsync(ServerDatabase.localhost + "store/getstorebyid/test");

                x = testInternet;
            }
            catch (Exception ex)
            {
                var stack = App.Current.MainPage.Navigation.NavigationStack;
                var page  = stack[stack.Count - 1];
                await page.DisplayAlert("Error", "Action fail, check your internet connection and try again!", "OK");

                return;
            }
            //===================================================
            //TẠO STORE
            string idStore  = "Store_" + DateTime.Now.ToString("HHmmss");
            Store  newStore = new Store
            {
                IDStore          = idStore,
                StoreName        = "",
                ImageURL         = "defaultstore",
                StoreDescription = "",
                StoreAddress     = "###",
                RatingStore      = 0,
                IsActive         = 0,
            };
            //encode password
            string encodePass = MD5Service.EncodeToMD5(NewPassword);
            //TẠO USER TƯƠNG ỨNG
            User newUser = new User
            {
                IDUser      = Username,
                Password    = encodePass,
                IDStore     = idStore,
                PhoneNumber = "",
                Address     = "###",
                Email       = "",
                ImageURL    = "defaultuser",
                BirthDate   = DateTime.Today,
                UserName    = "",
                IsLogined   = 0
            };

            //insert STORE và USER lên database local
            DataUpdater.AddStore(newStore);
            DataUpdater.AddUser(newUser);
            //insert STORE và USER lên database online
            await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "store/insert", newStore);

            await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "user/insert", newUser);

            await App.Current.MainPage.Navigation.PopAsync();
        }