private async void potvrda_Click(object sender, RoutedEventArgs e) { IMobileServiceTable <Models.Radnik> tabelaRadnici = App.MobileService.GetTable <Models.Radnik>(); string ime = ime1.Text; string prezime = prezime2.Text; object Temp = pozicija2.SelectedItem; string pozicija = Temp.ToString(); string plata = plata2.Text; string korisnicko = korisnicko2.Text; string lozinka = lozinka2.Password.ToString(); string potvrda = potvrdalozinka2.Password.ToString(); //DateTime datum = dat2.get; greska1.Foreground = new SolidColorBrush(Colors.Red); if (ime.Length == 0 || prezime.Length == 0 || pozicija.Length == 0 || plata.Length == 0 || korisnicko.Length == 0) { greska1.Text = "Morate popuniti sva polja!"; } else if (lozinka.Length <= 3) { greska1.Text = "Lozinka mora imati više od tri znaka!"; } else if (korisnicko.Length <= 3) { greska1.Text = "Korisničko ime mora imati više od tri znaka!"; } else if (!lozinka.Equals(potvrda)) { greska1.Text = "Lozinke se ne podudaraju!"; } else { greska1.Text = " "; Boolean b = await radnikvm.Registruj(lozinka, korisnicko, ime, prezime, pozicija, default(DateTime)); if (b) { // await showDialog4.ShowAsync(); // this.Frame.Navigate(typeof(PocetnaForma)); } ECopy.Models.Radnik novi = new ECopy.Models.Radnik(ime, prezime, korisnicko, lozinka, pozicija, float.Parse(plata), default(DateTime)); novi.id = 0; tabelaRadnici.InsertAsync(novi); MessageDialog showDialog = new MessageDialog("Uspješno ste se registrovali"); await showDialog.ShowAsync(); } }
public async Task <bool> Registruj(string Password, string Username, string FirstName, string LastName, string Position, DateTime DateOfBirth) { Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient(); var headers = httpClient.DefaultRequestHeaders; string header = "ie"; if (!headers.UserAgent.TryParseAdd(header)) { throw new Exception("Invalid header value: " + header); } header = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"; if (!headers.UserAgent.TryParseAdd(header)) { throw new Exception("Invalid header value: " + header); } //string stri = Convert.ToBase64String(Image); korisnik = new Models.Radnik(FirstName, LastName, Username, Password, Position, 1000, DateOfBirth); Uri requestUri = new Uri("http://localhost:60625/Radniks/Add/" + "?ime=" + korisnik.Ime + "&prezime=" + korisnik.Prezime + "&korisnickoIme=" + korisnik.KorisnickoIme + "&lozinka=" + korisnik.Lozinka + "&pozicija=" + korisnik.Pozicija + "&plata=" + korisnik.Plata.ToString() + "&datum=" + korisnik.DatumRodjenja); Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage(); string httpResponseBody = ""; try { //var success = await Windows.System.Launcher.LaunchUriAsync(requestUri); httpResponse = await httpClient.PostAsync(requestUri, null); httpResponse.EnsureSuccessStatusCode(); httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); string json = httpResponseBody; } catch (Exception ex) { httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message; } return(true); }