示例#1
0
        private async void LoadaData()
        {
            if (UserView.userType == 0)
            {
                List <Azure.User> lista = await App.MobileService.GetTable <Azure.User>().Where(x => x.id == Convert.ToString(UserView.userID)).ToListAsync();

                if (lista.Count != 0)
                {
                    Azure.User u = new Azure.User();
                    u                 = lista.Find(x => x.id == Convert.ToString(UserView.userID));
                    korisnik          = new User();
                    korisnik.Name     = u.Name;
                    korisnik.Surname  = u.Surname;
                    korisnik.Id       = Convert.ToInt32(u.id);
                    korisnik.Password = u.Password;
                    korisnik.Username = u.Username;
                    korisnik.Email    = u.Email;
                }
            }
            else if (UserView.userType == 1)
            {
                List <Azure.Owner> listaVlasnika = await App.MobileService.GetTable <Azure.Owner>().Where(x => x.id == Convert.ToString(UserView.userID)).ToListAsync();

                if (listaVlasnika.Count != 0)
                {
                    Azure.Owner u = new Azure.Owner();
                    u                 = listaVlasnika.Find(x => x.id == Convert.ToString(UserView.userID));
                    korisnik          = new Owner();
                    korisnik.Name     = u.Name;
                    korisnik.Surname  = u.Surname;
                    korisnik.Id       = Convert.ToInt32(u.id);
                    korisnik.Password = u.Password;
                    korisnik.Username = u.Username;
                    korisnik.Email    = u.Email;

                    List <Azure.Parking> listaParkinga = await App.MobileService.GetTable <Azure.Parking>().Where(x => x.id_vlasnika == (UserView.userID)).ToListAsync();

                    if (listaParkinga.Count != 0)
                    {
                        Parkings = new List <Parking>();

                        foreach (Azure.Parking p in listaParkinga)
                        {
                            Parking novi = new Parking();
                            novi.Id             = Convert.ToInt32(p.id);
                            novi.Name           = p.Name;
                            novi.Address        = p.Address;
                            novi.Capacity       = p.Capacity;
                            novi.CoordX         = p.CoordX;
                            novi.CoordY         = p.CoordY;
                            novi.MinCredits     = Convert.ToInt32(p.MinCredits);
                            novi.MinCredits     = Convert.ToInt32(p.MonthlyProfit);
                            novi.NumTakenSpaces = p.NumTakenSpaces;
                            novi.Price          = Convert.ToInt32(p.Price);
                            novi.MonthlyProfit  = Convert.ToInt32(p.MonthlyProfit);
                            novi.TodaysProfit   = Convert.ToInt32(p.TodaysProfit);
                            novi.WorkingHours   = new KeyValuePair <DateTime, DateTime>(Convert.ToDateTime(p.WorkingFrom), Convert.ToDateTime(p.WorkingTo));
                            novi.Zone           = p.Zone;
                            Parkings.Add(novi);
                        }
                    }
                }
            }
        }
        private async void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            if (Model.Validator.RegistrationDetailsEmpty(TextBoxName.Text.ToString(), TextBoxSurname.Text.ToString(), TextBoxPassword.Password.ToString(), TextBoxUsername.Text.ToString(), TextBoxEmail.Text.ToString()))
            {
                throw new IOException("Nijedno polje ne smije biti prazno!");
            }
            if (!Model.Validator.EmailIsValid(TextBoxEmail.Text.ToString()))
            {
                throw new IOException("Neispravan Email format!");
            }
            try
            {
                using (var db = new SPARKDbContext())
                {
                    List <Azure.User> lista = await App.MobileService.GetTable <Azure.User>().ToListAsync();

                    List <Azure.Owner> listaVlasnika = await App.MobileService.GetTable <Azure.Owner>().ToListAsync();

                    var user = new User();
                    if (UserView.userType == 0)
                    {
                        IMobileServiceTable <Azure.User> userTableObj = App.MobileService.GetTable <Azure.User>();

                        try
                        {
                            Azure.User obj = lista.Find(x => x.id == Convert.ToString(usr));
                            //    await userTableObj.DeleteAsync(obj);
                            obj.Name     = TextBoxName.Text.ToString();
                            obj.Surname  = TextBoxSurname.Text.ToString();
                            obj.id       = Convert.ToString(UserView.userID);
                            obj.Username = TextBoxUsername.Text.ToString();
                            obj.Password = TextBoxPassword.Password.ToString();
                            obj.Email    = TextBoxEmail.Text.ToString();
                            await userTableObj.UpdateAsync(obj);

                            MessageDialog msgDialog = new MessageDialog("Uspješno ste ažurirali svoj profil.");
                            await msgDialog.ShowAsync();
                        }
                        catch (IOException ex)
                        {
                            MessageDialog msgDialogError = new MessageDialog("Greška : " + ex.Message);
                            await msgDialogError.ShowAsync();
                        }
                    }
                    else if (UserView.userType == 1)
                    {
                        IMobileServiceTable <Azure.Owner> userTableObj = App.MobileService.GetTable <Azure.Owner>();
                        try
                        {
                            Azure.Owner obj = listaVlasnika.Find(x => x.id == Convert.ToString(UserView.userID));
                            //   await userTableObj.DeleteAsync(obj);
                            obj.Name     = TextBoxName.Text.ToString();
                            obj.Surname  = TextBoxSurname.Text.ToString();
                            obj.id       = Convert.ToString(UserView.userID);
                            obj.Username = TextBoxUsername.Text.ToString();
                            obj.Password = TextBoxPassword.Password.ToString();
                            obj.Email    = TextBoxEmail.Text.ToString();
                            await userTableObj.UpdateAsync(obj);

                            MessageDialog msgDialog = new MessageDialog("Uspješno ste ažurirali svoj profil.");
                            await msgDialog.ShowAsync();
                        }
                        catch (IOException ex)
                        {
                            MessageDialog msgDialogError = new MessageDialog("Greška : " + ex.Message);
                            await msgDialogError.ShowAsync();
                        }
                    }
                }
            }catch (IOException ee)
            {
                MessageDialog msgDialogError = new MessageDialog("Greška : " + ee.Message);
                await msgDialogError.ShowAsync();
            }

            /*  using (var db = new SPARKDbContext())
             * {
             *    int trazeni_id = 6;
             *    var u = db.User.Where(b => b.Id == trazeni_id).FirstOrDefault();
             *    db.Database.ExecuteSqlCommand("delete from User where id=" + trazeni_id.ToString());
             *    u.Name = TextBoxName.Text;
             *    u.Surname = TextBoxSurname.Text;
             *    u.Password = TextBoxPassword.Text;
             *    u.Username = TextBoxUsername.Text;
             *    u.Email = TextBoxEmail.Text;
             *
             *    db.User.Add(u);
             *    db.SaveChanges();
             * }*/



            var dialog = new MessageDialog("Vaš korisnički račun je uspješno izmijenjen!");

            dialog.Commands.Add(new UICommand {
                Label = "Ok"
            });
            await dialog.ShowAsync();
        }