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(); }
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); } } } } }
public void RegistrujSe(object parameter) { using (var db = new ParkingDBContext()) { ImeErrorMessage = PrezimeErrorMessage = EmailErrorMessage = PasswordErrorMessage = RepeatPasswordErrorMessage = ""; bool flag = false; if (Ime == null || Prezime == null || Password == null || RepeatPassword == null || Email == null) { ErrorMessage = "Obavezno polje"; flag = true; return; } if (Ime.Length < 3 || Ime.Length > 12) { ImeErrorMessage = "Ime mora imati minimalno 3 i maximalno 12 karaktera"; flag = true; } if (Prezime.Length < 3) { PrezimeErrorMessage = "Prezime mora imati minimalno 3 i maximalno 12 karaktera"; flag = true; } if (!(new EmailAddressAttribute().IsValid(Email))) { EmailErrorMessage = "Pogresan email"; flag = true; } if (Password.Length < 8 || Password.Length > 24) { PasswordErrorMessage = "Password mora imati minimalno 8 i maximalno 24 karaktera"; flag = true; } if (RepeatPassword != Password) { RepeatPasswordErrorMessage = "Password se ne podudara"; flag = true; } if (!BoxChecked) { CheckBoxErrorMessage = "Morate prihvatiti uslove koristenja"; flag = true; } if (flag) { return; } User noviKorisnik = new User(); noviKorisnik.Ime = Ime; noviKorisnik.Prezime = Prezime; noviKorisnik.Email = Email; noviKorisnik.Sifra = Validacija.createMD5(Password); db.Useri.Add(noviKorisnik); db.SaveChanges(); try { Azure.User azureUser = new Azure.User(); azureUser.Ime = Ime; azureUser.Prezime = Prezime; azureUser.Email = Email; azureUser.Sifra = Validacija.createMD5(Password); userTbl.InsertAsync(azureUser); Validacija.message("Uspjesno ste se registrovali", "Cestitamo"); } catch (Exception e) { Validacija.message(e.Message, "Greska"); } NavigationService.Navigate(typeof(View.Pocetna), noviKorisnik); } }