Exemplo n.º 1
0
        public async Task <ActionResult> RouteIncoming(string From)
        {
            var response = new TwilioResponse();

            //look up the from and if we recognize it dial the associated client
            IMobileServiceTable <PhoneNumber> phoneNumberTable = MobileService.GetTable <PhoneNumber>();
            var phoneNumbers = await phoneNumberTable.ReadAsync <PhoneNumber>(phoneNumberTable.Where(p => p.Value == From));

            PhoneNumber phoneNumber = phoneNumbers.FirstOrDefault();

            if (phoneNumber == null)
            {
                response.Say("Could not find your phone number.  Please register first");
            }
            else
            {
                response.Say("Connecting you now");
                response.DialClients(phoneNumber.Key.ToString("N"));
            }
            return(TwiML(response));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> ConnectAgentTwo(string To)
        {
            //check the caller ID and try to find a call config that matches it
            IMobileServiceTable <WarmCall> warmCallTable = MobileService.GetTable <WarmCall>();
            var warmCalls = await warmCallTable.ReadAsync <WarmCall>(warmCallTable.Where(w => w.AgentTwoPhone == To));

            var warmCall = warmCalls.FirstOrDefault();

            if (warmCall != null)
            {
                var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken);
                var result = client.InitiateOutboundCall("+17862200728", warmCall.AgentTwoPhone, Url.ActionAbsolute("HandleAgentTwoCall"));

                if (result.RestException != null)
                {
                    Console.WriteLine(result.RestException.Message);
                }
            }

            return(new EmptyResult());
        }
Exemplo n.º 3
0
        public async Task <IEnumerable <Employee> > GetAllEmployeesAsync()
        {
            try
            {
                await InitializeAsync();

                return(await _employeeTable.ReadAsync());
            }
            catch (MobileServiceInvalidOperationException ex)
            {
                Debug.WriteLine(String.Format("Cannot read from remote table: {0}", ex.Message));

                return(new List <Employee>());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);

                return(new List <Employee>());
            }
        }
Exemplo n.º 4
0
        public static async Task <Korisnik> dajKorisnika(string username, string password)
        {
            try
            {
                IMobileServiceTable <korisnici> Korisnici = App.MobileService.GetTable <korisnici>();

                IEnumerable <korisnici> tabela = await Korisnici.ReadAsync();

                foreach (var element in tabela)
                {
                    if (element.username.Equals(username) && element.password.Equals(password))
                    {
                        Racun racun = new Racun();
                        IMobileServiceTable <racuni> Racuni = App.MobileService.GetTable <racuni>();

                        IEnumerable <racuni> tabelaR = await Racuni.ReadAsync();

                        foreach (var elementR in tabelaR)
                        {
                            if (elementR.ID.Equals(element.racun_id))
                            {
                                racun.Stanje   = elementR.stanje;
                                racun.Blokiran = elementR.blokiran;
                            }
                        }

                        return(new Korisnik(element.ime, element.prezime, element.jmbg, element.brojTelefona, element.adresa, element.username,
                                            element.password, element.uposlen, racun));
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }


            return(new Korisnik()); // nece se nikada izvrsiti
        }
        async void mSpinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            if (counter == 0)
            {
                counter++;
            }
            else
            {
                MobileServiceClient baskentpaticlubClient = new MobileServiceClient("https://baskentpaticlub.azurewebsites.net");
                IMobileServiceTable KULUBETEMELTABLO      = baskentpaticlubClient.GetTable("KULUBETEMEL");

                kisim = e.Parent.GetItemAtPosition(e.Position).ToString();
                JToken JKulube = await KULUBETEMELTABLO.ReadAsync("$filter=KULUBEADI eq" + "'" + kisim + "'");

                List <KULUBETEMEL> items = JsonConvert.DeserializeObject <List <KULUBETEMEL> >(JKulube.ToString());
                var activity2            = new Intent(this, typeof(UserActivity));
                kId = (items[0].KULUBEID).ToString();
                activity2.PutExtra("kId", kId);
                activity2.PutExtra("kAd", items[0].KULUBEADI);
                StartActivity(activity2);
            }
        }
Exemplo n.º 6
0
        public async Task <ActionResult> HandleCustomerCall(string CallSid, string From)
        {
            var response = new TwilioResponse();

            //check the caller ID and try to find a call config that matches it
            IMobileServiceTable <WarmCall> warmCallTable = MobileService.GetTable <WarmCall>();
            var warmCalls = await warmCallTable.ReadAsync <WarmCall>(warmCallTable.Where(w => w.CustomerPhone == From));

            var warmCall = warmCalls.FirstOrDefault();

            if (warmCall != null)
            {
                //update with the call sid
                warmCall.CustomerCallSid = CallSid;
                await warmCallTable.UpdateAsync(warmCall);

                //put the customer into a conference
                response.Say("Please while while we conjure a support agent");
                response.DialConference(CallSid);

                //dial an agent
                var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken);
                var result = client.InitiateOutboundCall("+17862200728", warmCall.AgentOnePhone, Url.ActionAbsolute("HandleAgentOneCall"));

                if (result.RestException != null)
                {
                    Console.WriteLine(result.RestException.Message);
                }
                //let the browser know that the customer has connected and we're calling the agent
            }
            else
            {
                response.Say("Who are you?  Go away!");
                response.Hangup();
            }


            return(TwiML(response));
        }
        public async Task ReadAsyncWithValidIntIdAgainstIntIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithIntId>();

            IMobileServiceTable <ToDoWithIntId> table = GetClient().GetTable <ToDoWithIntId>();

            ToDoWithIntId item = new ToDoWithIntId()
            {
                String = "Hey"
            };
            await table.InsertAsync(item);

            IEnumerable <ToDoWithIntId> results = await table.ReadAsync();

            ToDoWithIntId[] items = results.ToArray();

            Assert.AreEqual(1, items.Count());
            Assert.IsTrue(items[0].Id > 0);
            Assert.AreEqual("Hey", items[0].String);

            await table.DeleteAsync(item);
        }
        public async Task ReadAsyncWithUserParameters()
        {
            TestHttpHandler hijack = new TestHttpHandler();

            hijack.SetResponseContent("{\"Count\":1, People: [{\"Id\":\"12\", \"String\":\"Hey\"}] }");
            IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

            var userDefinedParameters = new Dictionary <string, string>()
            {
                { "tags", "#pizza #beer" }
            };

            IMobileServiceTable table = service.GetTable("tests");

            JToken people = await table.ReadAsync("$filter=id eq 12", userDefinedParameters);

            Assert.Contains(hijack.Request.RequestUri.ToString(), "tests");
            Assert.Contains(hijack.Request.RequestUri.AbsoluteUri, "tags=%23pizza%20%23beer");
            Assert.Contains(hijack.Request.RequestUri.ToString(), "$filter=id eq 12");

            Assert.AreEqual(1, (int)people["Count"]);
            Assert.AreEqual(12, (int)people["People"][0]["Id"]);
            Assert.AreEqual("Hey", (string)people["People"][0]["String"]);
        }
Exemplo n.º 9
0
        public async Task AsyncTableOperationsWithAllSystemProperties()
        {
            await EnsureEmptyTableAsync <RoundTripTableItemWithSystemPropertiesType>();

            string id = Guid.NewGuid().ToString();
            IMobileServiceTable <RoundTripTableItemWithSystemPropertiesType> table = GetClient().GetTable <RoundTripTableItemWithSystemPropertiesType>();

            RoundTripTableItemWithSystemPropertiesType item = new RoundTripTableItemWithSystemPropertiesType()
            {
                Id = id, Name = "a value"
            };
            await table.InsertAsync(item);

            Assert.IsNotNull(item.CreatedAt);
            Assert.IsNotNull(item.UpdatedAt);
            Assert.IsNotNull(item.Version);

            // Read
            IEnumerable <RoundTripTableItemWithSystemPropertiesType> results = await table.ReadAsync();

            RoundTripTableItemWithSystemPropertiesType[] items = results.ToArray();

            Assert.AreEqual(1, items.Count());
            Assert.IsNotNull(items[0].CreatedAt);
            Assert.IsNotNull(items[0].UpdatedAt);
            Assert.IsNotNull(items[0].Version);

            // Filter against version
            // BUG #1706815 (OData query for version field (string <--> byte[] mismatch)

            /*
             * results = await table.Where(i => i.Version == items[0].Version).ToEnumerableAsync();
             * RoundTripTableItemWithSystemPropertiesType[] filterItems = results.ToArray();
             *
             * Assert.AreEqual(1, items.Count());
             * Assert.AreEqual(filterItems[0].CreatedAt, items[0].CreatedAt);
             * Assert.AreEqual(filterItems[0].UpdatedAt, items[0].UpdatedAt);
             * Assert.AreEqual(filterItems[0].Version, items[0].Version);
             *
             * // Filter against createdAt
             * results = await table.Where(i => i.CreatedAt == items[0].CreatedAt).ToEnumerableAsync();
             * RoundTripTableItemWithSystemPropertiesType[] filterItems = results.ToArray();
             *
             * Assert.AreEqual(1, items.Count());
             * Assert.AreEqual(filterItems[0].CreatedAt, items[0].CreatedAt);
             * Assert.AreEqual(filterItems[0].UpdatedAt, items[0].UpdatedAt);
             * Assert.AreEqual(filterItems[0].Version, items[0].Version);
             *
             * // Filter against updatedAt
             * results = await table.Where(i => i.UpdatedAt == items[0].UpdatedAt).ToEnumerableAsync();
             * filterItems = results.ToArray();
             *
             * Assert.AreEqual(1, items.Count());
             * Assert.AreEqual(filterItems[0].CreatedAt, items[0].CreatedAt);
             * Assert.AreEqual(filterItems[0].UpdatedAt, items[0].UpdatedAt);
             * Assert.AreEqual(filterItems[0].Version, items[0].Version);
             */

            // Projection
            var projectedResults = await table.Select(i => new { XId = i.Id, XCreatedAt = i.CreatedAt, XUpdatedAt = i.UpdatedAt, XVersion = i.Version }).ToEnumerableAsync();

            var projectedItems = projectedResults.ToArray();

            Assert.AreEqual(1, projectedResults.Count());
            Assert.AreEqual(projectedItems[0].XId, items[0].Id);
            Assert.AreEqual(projectedItems[0].XCreatedAt, items[0].CreatedAt);
            Assert.AreEqual(projectedItems[0].XUpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(projectedItems[0].XVersion, items[0].Version);

            // Lookup
            item = await table.LookupAsync(id);

            Assert.AreEqual(id, item.Id);
            Assert.AreEqual(item.Id, items[0].Id);
            Assert.AreEqual(item.CreatedAt, items[0].CreatedAt);
            Assert.AreEqual(item.UpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(item.Version, items[0].Version);

            // Refresh
            item = new RoundTripTableItemWithSystemPropertiesType()
            {
                Id = id
            };
            await table.RefreshAsync(item);

            Assert.AreEqual(id, item.Id);
            Assert.AreEqual(item.Id, items[0].Id);
            Assert.AreEqual(item.CreatedAt, items[0].CreatedAt);
            Assert.AreEqual(item.UpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(item.Version, items[0].Version);

            // Update
            item.Name = "Hello!";
            await table.UpdateAsync(item);

            Assert.AreEqual(item.Id, items[0].Id);
            Assert.AreEqual(item.CreatedAt, items[0].CreatedAt);
            Assert.IsTrue(item.UpdatedAt >= items[0].UpdatedAt);
            Assert.IsNotNull(item.Version);
            Assert.AreNotEqual(item.Version, items[0].Version);

            // Read Again
            results = await table.ReadAsync();

            items = results.ToArray();
            Assert.AreEqual(id, item.Id);
            Assert.AreEqual(item.Id, items[0].Id);
            Assert.AreEqual(item.CreatedAt, items[0].CreatedAt);
            Assert.AreEqual(item.UpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(item.Version, items[0].Version);

            await table.DeleteAsync(item);
        }
Exemplo n.º 10
0
 public Task <IEnumerable <XamagramItem> > ReadXamagramItemsAsync()
 {
     return(_xamagramItemTable.ReadAsync());
 }
 public async Task <JToken> ReadAsync(string query)
 {
     return(await _table.ReadAsync(query));
 }
        public async Task AsyncTableOperationsWithValidStringIdAgainstStringIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithStringId>();

            string[] testIdData = IdTestData.ValidStringIds;

            foreach (string testId in testIdData)
            {
                IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>();

                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId, String = "Hey"
                };
                await table.InsertAsync(item);

                // Read
                IEnumerable <ToDoWithStringId> results = await table.ReadAsync();

                ToDoWithStringId[] items = results.ToArray();

                Assert.AreEqual(1, items.Count());
                Assert.AreEqual(testId, items[0].Id);
                Assert.AreEqual("Hey", items[0].String);

                // Filter
                results = await table.Where(i => i.Id == testId).ToEnumerableAsync();

                items = results.ToArray();

                Assert.AreEqual(1, items.Count());
                Assert.AreEqual(testId, items[0].Id);
                Assert.AreEqual("Hey", items[0].String);

                // Projection
                var projectedResults = await table.Select(i => new { XId = i.Id, XString = i.String }).ToEnumerableAsync();

                var projectedItems = projectedResults.ToArray();

                Assert.AreEqual(1, projectedItems.Count());
                Assert.AreEqual(testId, projectedItems[0].XId);
                Assert.AreEqual("Hey", projectedItems[0].XString);

                // Lookup
                item = await table.LookupAsync(testId);

                Assert.AreEqual(testId, item.Id);
                Assert.AreEqual("Hey", item.String);

                // Update
                item.String = "What?";
                await table.UpdateAsync(item);

                Assert.AreEqual(testId, item.Id);
                Assert.AreEqual("What?", item.String);

                // Refresh
                item = new ToDoWithStringId()
                {
                    Id = testId, String = "Hey"
                };
                await table.RefreshAsync(item);

                Assert.AreEqual(testId, item.Id);
                Assert.AreEqual("What?", item.String);

                // Read Again
                results = await table.ReadAsync();

                items = results.ToArray();

                Assert.AreEqual(1, items.Count());
                Assert.AreEqual(testId, items[0].Id);
                Assert.AreEqual("What?", items[0].String);

                await table.DeleteAsync(item);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Executes a query against the table.
 /// </summary>
 /// <param name="table">
 /// The instance of table to read from.
 /// </param>
 /// <param name="query">
 /// A query to execute.
 /// </param>
 /// <param name="parameters">
 /// A dictionary of user-defined parameters and values to include in
 /// the request URI query string.
 /// </param>
 /// <returns>
 /// A task that will return with results when the query finishes.
 /// </returns>
 public static Task <JToken> ReadAsync(this IMobileServiceTable table, string query, IDictionary <string, string> parameters)
 => table.ReadAsync(query, parameters, wrapResult: false);
Exemplo n.º 14
0
        private async Task DownloadChanges()
        {
            this.OnSyncProgress(new SyncProgressEventArgs("Downloading changes from server..."));
            foreach (Type t in SyncedTypes.Keys)
            {
                IMobileServiceTable table = MobileService.GetTable(SyncedTypes[t]);
                table.SystemProperties |= MobileServiceSystemProperties.All;

                Anchor anchor     = siaqodbMobile.Query <Anchor>().Where(anc => anc.EntityType == ReflectionHelper.GetDiscoveringTypeName(t)).FirstOrDefault();
                string filter     = "";
                string anchorJSON = "";
                if (anchor != null)
                {
                    string dateTimeString = new DateTime(anchor.TimeStamp.Ticks, DateTimeKind.Utc).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK", CultureInfo.InvariantCulture);

                    filter     = "$filter=(__updatedAt gt " + string.Format(CultureInfo.InvariantCulture, "datetime'{0}'", dateTimeString) + ")";
                    anchorJSON = dateTimeString;//JsonConvert.SerializeObject(anchor.TimeStamp);
                }
                Dictionary <string, string> paramAMS = GetParamsAMS();
                paramAMS.Add("Anchor", anchorJSON);
                var token = await table.ReadAsync(filter, paramAMS);

                //Type typeIList = typeof(List<>).MakeGenericType(t);
                //ConstructorInfo ctor = typeIList.GetConstructor(new Type[] { });
                //IList list = (IList)ctor.Invoke(new object[]{});
                this.OnSyncProgress(new SyncProgressEventArgs("Items downloaded,start store locally..."));

                DownloadedBatch serverEntities = JsonConvert.DeserializeObject(token.ToString(), typeof(DownloadedBatch)) as DownloadedBatch;
                if (serverEntities != null)
                {
                    siaqodbMobile.StartBulkInsert(t);
                    try
                    {
                        if (serverEntities.ItemsList != null)
                        {
                            syncStatistics.TotalDownloads = (uint)serverEntities.ItemsList.Count;
                            foreach (var entity in serverEntities.ItemsList)
                            {
                                object objEn = JsonConvert.DeserializeObject(((JObject)entity).ToString(), t);
                                siaqodbMobile.StoreDownloadedEntity(objEn);
                            }
                        }
                        if (serverEntities.TombstoneList != null)
                        {
                            syncStatistics.TotalDownloads += (uint)serverEntities.TombstoneList.Count;

                            foreach (var delEntity in serverEntities.TombstoneList)
                            {
                                var    delEnJ = (JObject)delEntity;
                                JToken ENId   = delEnJ.GetValue("enid");

                                Dictionary <string, object> criteria = new Dictionary <string, object>();
                                criteria.Add(ExternalMetaHelper.GetBackingField(ReflectionHelper.GetIdProperty(t)), ENId.ToString());
                                int nrDeleted = siaqodbMobile.DeleteObjectByBase(t, criteria);
                            }
                        }
                    }
                    finally
                    {
                        siaqodbMobile.EndBulkInsert(t);
                    }
                    if (anchor != null)
                    {
                        anchor.TimeStamp = serverEntities.TimeStamp;
                    }
                    else
                    {
                        anchor = new Anchor()
                        {
                            EntityType = ReflectionHelper.GetDiscoveringTypeName(t), TimeStamp = serverEntities.TimeStamp
                        };
                    }
                    siaqodbMobile.StoreObjectBase(anchor);
                }
            }
            siaqodbMobile.Flush();
            this.OnSyncProgress(new SyncProgressEventArgs("Download and store locally finished..."));
        }
Exemplo n.º 15
0
 private async Task Query <T, U>(Func <IMobileServiceTable <T>, MobileServiceTableQuery <U> > getQuery)
 {
     IMobileServiceTable <T>     table = GetClient().GetTable <T>();
     MobileServiceTableQuery <U> query = getQuery(table);
     await table.ReadAsync(query);
 }
Exemplo n.º 16
0
 public Task <IEnumerable <SurveyQuestion> > GetQuestionsAsync()
 {
     Initialize();
     return(questionsTable.ReadAsync());
 }
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            MobileServiceClient baskentpaticlubClient = new MobileServiceClient("https://baskentpaticlub.azurewebsites.net");

            CurrentPlatform.Init();
            IMobileServiceTable KULUBETABLO = baskentpaticlubClient.GetTable("KULUBEBILGI2");
            kulube newKulube = new kulube();

            gelenKulubeId = Int32.Parse(Intent.GetStringExtra("kId"));
            gelenKulubeAd = Intent.GetStringExtra("kAd");

            JToken Jkulube = await KULUBETABLO.ReadAsync("$filter=kid eq " + "'" + gelenKulubeId + "'" + "&$orderby=tarih desc");

            List <KULUBEBILGI2> items = JsonConvert.DeserializeObject <List <KULUBEBILGI2> >(Jkulube.ToString());


            newKulube.mKulubeAdi = "Bölge  : " + gelenKulubeAd;

            if (items[0].su == true)
            {
                newKulube.mKulubeSu = "Su Kabı : DOLU...";
            }
            else
            {
                newKulube.mKulubeSu = "Su Kabı : BOŞ !!!";
            }

            if (items[0].yemek == true)
            {
                newKulube.mKulubeYemek = "Yemek Kabı : DOLU...";
            }
            else
            {
                newKulube.mKulubeYemek = "Yemek Kabı : BOŞ !!!";
            }

            newKulube.mKulubeTemp = Convert.ToInt32(items[0].sicaklik);
            newKulube.KulubeHavaDurumu();
            newKulube.mKulubeGirisCikis = items[0].giriscikis;

            SetContentView(Resource.Layout.activity_user);
            mListView = FindViewById <ListView>(Resource.Id.listView);

            if (newKulube.mKulubeGirisCikis > 1)
            {
                KullanimSayisi = (newKulube.mKulubeGirisCikis / 2).ToString();
            }
            if (newKulube.mKulubeGirisCikis <= 1)
            {
                KullanimSayisi = newKulube.mKulubeGirisCikis.ToString();
            }
            tarih      = "Son Güncelleme : " + items[0].tarih.ToShortDateString() + " " + items[0].tarih.ToShortTimeString();
            kSituation = new List <string>();
            kSituation.Add(newKulube.mKulubeAdi);
            kSituation.Add(newKulube.mKulubeSu);
            kSituation.Add(newKulube.mKulubeYemek);
            kSituation.Add(newKulube.mKulubeHava);
            kSituation.Add("Kulübe Kullanımı : " + KullanimSayisi + " KEZ...");
            kSituation.Add(tarih);

            ArrayAdapter <string> adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, kSituation);

            mListView.Adapter = adapter;

            mButtonKonum        = FindViewById <Button>(Resource.Id.buttonKonum);
            mButtonKonum.Click += (object Sender, EventArgs args) =>
            {
                FragmentTransaction transaction = FragmentManager.BeginTransaction();
                var mapActivity = new Intent(this, typeof(Gmaps));
                mapActivity.PutExtra("kName", gelenKulubeAd);
                StartActivity(mapActivity);
            };
            mButtonKulube        = FindViewById <Button>(Resource.Id.buttonKulube);
            mButtonKulube.Click += (object Sender, EventArgs args) =>
            {
                FragmentTransaction transaction = FragmentManager.BeginTransaction();
                var kulubeActivity = new Intent(this, typeof(GirisAktivite));
                StartActivity(kulubeActivity);
            };
        }
Exemplo n.º 18
0
 public async Task <IEnumerable <TodoItem> > GetTodoItemsAsync()
 {
     return(await mst.ReadAsync());
 }
Exemplo n.º 19
0
        private async void RegSubmitButtonClick(object sender, RoutedEventArgs e)
        {
            if (NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.None)
            {
                if (UserNameTextBox.Text != "" && PasswordTextBox.Password != "" && RePasswordTextBox.Password != "")
                {
                    if (!UserNameTextBox.Text.Trim().Equals("default"))
                    {
                        ProgressIndicator progress = new ProgressIndicator
                        {
                            IsVisible       = true,
                            IsIndeterminate = true,
                            Text            = "注册中..."
                        };
                        SystemTray.SetProgressIndicator(this, progress);

                        IEnumerable <User> list = await userTable.ReadAsync();

                        List <User> userList = list.ToList();

                        // Boolean isReg = false;

                        User newuser;

                        foreach (User user in userList)
                        {
                            if (user.UserId.Equals(UserNameTextBox.Text))
                            {
                                MessageBox.Show("此用户名已经有人使用了,请重新选择一个!");
                                return;
                            }
                        }

                        if (!PasswordTextBox.Password.Equals(RePasswordTextBox.Password))
                        {
                            MessageBox.Show("两次密码输入不符,请重新输入!");
                            return;
                        }

                        newuser = new User();

                        newuser.UserId   = UserNameTextBox.Text.Trim();
                        newuser.Password = PasswordTextBox.Password.Trim();

                        await userTable.InsertAsync(newuser);

                        MessageBox.Show("注册完成,现在返回登录页面!");
                        NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
                    }
                    else
                    {
                        MessageBox.Show("用户名不能为default,请重新选择一个用户名!");
                    }
                }
                else
                {
                    MessageBox.Show("请完整输入用户名以及密码!");
                }
            }
            else
            {
                Debug.WriteLine("[DEBUG]Network Interface Available Status:" + NetworkInterface.GetIsNetworkAvailable());
                Debug.WriteLine("[DEBUG]Network Interface Type Status:" + NetworkInterface.NetworkInterfaceType);
                MessageBox.Show("注册账户需要网络连接,请开启手机的移动网络。");
            }
        }
Exemplo n.º 20
0
        private async Task <int> ReadMarcaServerTableAsync(IMobileServiceTable <Marca> serverTable, Marca marca)
        {
            var count = await serverTable.ReadAsync($"select id from Marca where id='{marca.Id}' and Marca.Nome='{marca.Nome}'");

            return(count?.ToList()?.Count ?? 0);
        }
Exemplo n.º 21
0
 public async Task <IEnumerable <Deporte> > ReadDeportesAsync()
 {
     return(await _deporteItemTable.ReadAsync());
 }
        public async Task AsyncTableOperationsWithAllSystemProperties()
        {
            await EnsureEmptyTableAsync <ToDoWithSystemPropertiesType>();

            string id = "an id";
            IMobileServiceTable <ToDoWithSystemPropertiesType> table = GetClient().GetTable <ToDoWithSystemPropertiesType>();

            ToDoWithSystemPropertiesType item = new ToDoWithSystemPropertiesType()
            {
                Id = id, String = "a value"
            };
            await table.InsertAsync(item);

            Assert.IsNotNull(item.CreatedAt);
            Assert.IsNotNull(item.UpdatedAt);
            Assert.IsNotNull(item.Version);

            // Read
            IEnumerable <ToDoWithSystemPropertiesType> results = await table.ReadAsync();

            ToDoWithSystemPropertiesType[] items = results.ToArray();

            Assert.AreEqual(1, items.Count());
            Assert.IsNotNull(items[0].CreatedAt);
            Assert.IsNotNull(items[0].UpdatedAt);
            Assert.IsNotNull(items[0].Version);

            // Filter against version
            results = await table.Where(i => i.Version == items[0].Version).ToEnumerableAsync();

            ToDoWithSystemPropertiesType[] filterItems = results.ToArray();

            Assert.AreEqual(1, items.Count());
            Assert.AreEqual(filterItems[0].CreatedAt, items[0].CreatedAt);
            Assert.AreEqual(filterItems[0].UpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(filterItems[0].Version, items[0].Version);

            // Filter against createdAt
            results = await table.Where(i => i.CreatedAt == items[0].CreatedAt).ToEnumerableAsync();

            filterItems = results.ToArray();

            Assert.AreEqual(1, items.Count());
            Assert.AreEqual(filterItems[0].CreatedAt, items[0].CreatedAt);
            Assert.AreEqual(filterItems[0].UpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(filterItems[0].Version, items[0].Version);

            // Filter against updatedAt
            results = await table.Where(i => i.UpdatedAt == items[0].UpdatedAt).ToEnumerableAsync();

            filterItems = results.ToArray();

            Assert.AreEqual(1, items.Count());
            Assert.AreEqual(filterItems[0].CreatedAt, items[0].CreatedAt);
            Assert.AreEqual(filterItems[0].UpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(filterItems[0].Version, items[0].Version);

            // Projection
            var projectedResults = await table.Select(i => new { XId = i.Id, XCreatedAt = i.CreatedAt, XUpdatedAt = i.UpdatedAt, XVersion = i.Version }).ToEnumerableAsync();

            var projectedItems = projectedResults.ToArray();

            Assert.AreEqual(1, projectedResults.Count());
            Assert.AreEqual(projectedItems[0].XId, items[0].Id);
            Assert.AreEqual(projectedItems[0].XCreatedAt, items[0].CreatedAt);
            Assert.AreEqual(projectedItems[0].XUpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(projectedItems[0].XVersion, items[0].Version);

            // Lookup
            item = await table.LookupAsync(id);

            Assert.AreEqual(id, item.Id);
            Assert.AreEqual(item.Id, items[0].Id);
            Assert.AreEqual(item.CreatedAt, items[0].CreatedAt);
            Assert.AreEqual(item.UpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(item.Version, items[0].Version);

            // Refresh
            item = new ToDoWithSystemPropertiesType()
            {
                Id = id
            };
            await table.RefreshAsync(item);

            Assert.AreEqual(id, item.Id);
            Assert.AreEqual(item.Id, items[0].Id);
            Assert.AreEqual(item.CreatedAt, items[0].CreatedAt);
            Assert.AreEqual(item.UpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(item.Version, items[0].Version);

            // Update
            item.String = "Hello!";
            await table.UpdateAsync(item);

            Assert.AreEqual(item.Id, items[0].Id);
            Assert.AreEqual(item.CreatedAt, items[0].CreatedAt);
            Assert.IsTrue(item.UpdatedAt >= items[0].UpdatedAt);
            Assert.IsNotNull(item.Version);
            Assert.AreNotEqual(item.Version, items[0].Version);

            // Read Again
            results = await table.ReadAsync();

            items = results.ToArray();
            Assert.AreEqual(id, item.Id);
            Assert.AreEqual(item.Id, items[0].Id);
            Assert.AreEqual(item.CreatedAt, items[0].CreatedAt);
            Assert.AreEqual(item.UpdatedAt, items[0].UpdatedAt);
            Assert.AreEqual(item.Version, items[0].Version);

            await table.DeleteAsync(item);
        }
Exemplo n.º 23
0
        public static async Task <bool> moguceIzvrsitiTransakciju(int posiljalac, int primalac, float iznos)
        {
            if (posiljalac == 1)
            {
                return(true);                //(PS, zbog ovog mi treba onaj insan sa id=1 sto sam ga gore opisao)
            }
            //ako posiljalac ima stanjeRacuna < iznos vratiti false

            IMobileServiceTable <korisnici> Korisnici = App.MobileService.GetTable <korisnici>();
            IMobileServiceTable <racuni>    Racuni    = App.MobileService.GetTable <racuni>();

            IEnumerable <korisnici> tabelaK = await Korisnici.ReadAsync();

            IEnumerable <racuni> tabelaR = await Racuni.ReadAsync();

            //provjera da li uopste postoje posiljalac i primalac u bazi
            bool postojiPosiljalac = false;
            bool postojiPrimalac   = false;

            foreach (var pos in tabelaK)
            {
                if (pos.ID.Equals(posiljalac))
                {
                    postojiPosiljalac = true;
                    break;
                }
            }
            foreach (var prim in tabelaK)
            {
                if (prim.ID.Equals(primalac))
                {
                    postojiPrimalac = true;
                    break;
                }
            }

            //ako ne postoje transakcija se naravno ne moze izvrsiti
            if (!postojiPrimalac || !postojiPosiljalac)
            {
                return(false);
            }



            //ovo je ustvari povezivanje preko foreign keya - korisnici.racun_id i racuni.ID

            foreach (var elementK in tabelaK)
            {
                if (elementK.ID.Equals(posiljalac))
                {
                    foreach (var elementR in tabelaR)
                    {
                        if (elementK.racun_id.Equals(elementR.ID))
                        {
                            if (elementR.stanje < iznos)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }


            return(true);
        }
        public async Task AsyncTableOperationsWithIntegerAsStringIdAgainstIntIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithStringIdAgainstIntIdTable>();

            IMobileServiceTable <ToDoWithStringIdAgainstIntIdTable> stringIdTable = GetClient().GetTable <ToDoWithStringIdAgainstIntIdTable>();
            ToDoWithStringIdAgainstIntIdTable item = new ToDoWithStringIdAgainstIntIdTable()
            {
                String = "Hey"
            };

            // Insert
            await stringIdTable.InsertAsync(item);

            string testId = item.Id.ToString();

            // Read
            IEnumerable <ToDoWithStringIdAgainstIntIdTable> results = await stringIdTable.ReadAsync();

            ToDoWithStringIdAgainstIntIdTable[] items = results.ToArray();

            Assert.AreEqual(1, items.Count());
            Assert.AreEqual(testId, items[0].Id);
            Assert.AreEqual("Hey", items[0].String);

            // Filter
            results = await stringIdTable.Where(i => i.Id == testId).ToEnumerableAsync();

            items = results.ToArray();

            Assert.AreEqual(1, items.Count());
            Assert.AreEqual(testId, items[0].Id);
            Assert.AreEqual("Hey", items[0].String);

            // Projection
            var projectedResults = await stringIdTable.Select(i => new { XId = i.Id, XString = i.String }).ToEnumerableAsync();

            var projectedItems = projectedResults.ToArray();

            Assert.AreEqual(1, projectedItems.Count());
            Assert.AreEqual(testId, projectedItems[0].XId);
            Assert.AreEqual("Hey", projectedItems[0].XString);

            // Lookup
            ToDoWithStringIdAgainstIntIdTable stringIdItem = await stringIdTable.LookupAsync(testId);

            Assert.AreEqual(testId, stringIdItem.Id);
            Assert.AreEqual("Hey", stringIdItem.String);

            // Update
            stringIdItem.String = "What?";
            await stringIdTable.UpdateAsync(stringIdItem);

            Assert.AreEqual(testId, stringIdItem.Id);
            Assert.AreEqual("What?", stringIdItem.String);

            // Refresh
            stringIdItem = new ToDoWithStringIdAgainstIntIdTable()
            {
                Id = testId, String = "Hey"
            };
            await stringIdTable.RefreshAsync(stringIdItem);

            Assert.AreEqual(testId, stringIdItem.Id);
            Assert.AreEqual("What?", stringIdItem.String);

            // Read Again
            results = await stringIdTable.ReadAsync();

            items = results.ToArray();

            Assert.AreEqual(1, items.Count());
            Assert.AreEqual(testId, items[0].Id);
            Assert.AreEqual("What?", items[0].String);

            // Delete
            await stringIdTable.DeleteAsync(item);
        }
Exemplo n.º 25
0
 public Task <IEnumerable <SharitItem> > ReadSharitItemsAsync()
 {
     return(_sharitItemTable.ReadAsync());
 }
Exemplo n.º 26
0
        public static async Task <Osoba> dajKorisnika(string username, string password)
        {
            try
            {
                IMobileServiceTable <tabela> Korisnici = App.MobileService.GetTable <tabela>();

                IEnumerable <tabela> tabela = await Korisnici.ReadAsync();

                foreach (var element in tabela)
                {
                    if (element.korisnickoime.Equals(username) && element.sifra.Equals(password))
                    {
                        //List<Smjestaj> smjestaji = new List<Smjestaj>();
                        Smjestaj smjestaj = new Smjestaj();
                        IMobileServiceTable <tabela1> Smjestaji = App.MobileService.GetTable <tabela1>();

                        IEnumerable <tabela1> tabelaR = await Smjestaji.ReadAsync();

                        foreach (var elementR in tabelaR)
                        {
                            if (elementR.idvlasnika.Equals(element.id))
                            {
                                smjestaj.BrojCimera = elementR.brojcimera;
                                smjestaj.Cijena     = elementR.cijena;
                                //fali datum smjestaj.datum
                                smjestaj.Kvadratura = elementR.kvadratura;
                                smjestaj.Lokacija   = elementR.lokacija;
                                smjestaj.Opis       = elementR.dodatniopis;
                                String         pomocna = elementR.vrstasmjestaja;
                                VrstaSmejstaja vrsta   = kojaVrstaSmjestaja(pomocna);
                                smjestaj.Vrsta = vrsta;
                                break;//ne treba kada bude lista
                                //TODO: dodati jos
                            }
                        }
                        List <Smjestaj> regSmjestaji = new List <Smjestaj>();
                        regSmjestaji.Add(smjestaj);
                        Osoba o = new Osoba()
                        {
                            Ime      = element.ime,
                            Prezime  = element.prezime,
                            Username = element.korisnickoime,
                            Spol     = dajMiSpol(element.spol),
                            ID       = element.id,
                            Mail     = element.email,
                            Password = element.sifra,
                            Telefon  = element.broj,
                            Adresa   = element.adresa,
                            //datumrodjenja
                            //TODO: ostatak ctrl space
                            RegistrovaniSmjestaji = regSmjestaji
                                                    //registorvanerezervacije?
                        };
                        return(o);
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }


            return(new Osoba()); // nece se nikada izvrsiti
        }
Exemplo n.º 27
0
        public async Task <List <Customer> > GetAllCustomers()
        {
            Initialize();

            return((await customersTable.ReadAsync()).ToList());
        }