private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (naziv.Text.Length > 0)
            {
                PolicaWM polica = new PolicaWM();
                polica.Naziv      = naziv.Text;
                polica.KorisnikID = Global.prijavljeniKorisnik.Id;
                HttpResponseMessage response = policaService.PostResponse(polica);

                if (response.IsSuccessStatusCode)
                {
                    MessageDialog msg = new MessageDialog("Polica uspješno dodana!");
                    msg.ShowAsync();
                }
                else
                {
                    body.Text = "Greška!";
                }
                this.Hide();
            }
            else
            {
                body.Text = "UNESITE NAZIV POLICE";
            }
        }
Exemplo n.º 2
0
        // POST: api/Policas

        /*[ResponseType(typeof(PolicaWM))]
         * public IHttpActionResult PostPolica(PolicaWM polica)
         * {
         *      if (!ModelState.IsValid)
         *      {
         *              return BadRequest(ModelState);
         *      }
         *
         *      db.Policas.Add(polica);
         *      db.SaveChanges();
         *
         *      return CreatedAtRoute("DefaultApi", new { id = polica.Id }, polica);
         * }
         */
        public PolicaWM PostPolica(PolicaWM polica)
        {
            Polica p = new Polica();

            p.KorisnikID = polica.KorisnikID;
            p.Naziv      = polica.Naziv;

            db.Policas.Add(p);
            db.SaveChanges();

            return(polica);
        }
        private void potvrdiButton_Click(object sender, EventArgs e)
        {
            HttpResponseMessage rm = usernameService.GetResponse(usernameInput.Text);

            if (usernameInput.Text.Length > 0 && rm.IsSuccessStatusCode && rm.Content.ReadAsAsync <bool>().Result == true)
            {
                if (this.ValidateChildren())
                {
                    Korisnik k = new Korisnik();
                    k.Ime        = imeInput.Text;
                    k.Prezime    = prezimeInput.Text;
                    k.username   = usernameInput.Text;
                    k.password   = passwordInput.Text;
                    k.Email      = emailInput.Text;
                    k.created_at = DateTime.Now;
                    if (muskoRB.Checked)
                    {
                        k.Spol = "M";
                    }
                    else if (zenskoRB.Checked)
                    {
                        k.Spol = "Z";
                    }
                    else
                    {
                        k.Spol = "M";
                    }
                    k.Grad = gradInput.Text;

                    if (Id >= 1)
                    {
                        k.Id = Id;
                    }

                    HttpResponseMessage response = korisnikService.PostResponse(k);
                    if (response.IsSuccessStatusCode)
                    {
                        MessageBox.Show(Global.GetMessage("korisnik_succ"), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Clear();

                        if (!(Id >= 1))
                        {
                            int      korisnikId = response.Content.ReadAsAsync <Korisnik>().Result.Id;
                            PolicaWM p          = new PolicaWM();
                            p.KorisnikID = korisnikId;
                            p.BookCount  = 0;

                            p.Naziv = "To Read";
                            policaService.PostResponse(p);

                            p.Naziv = "Currently Reading";
                            policaService.PostResponse(p);

                            p.Naziv = "Read";
                            policaService.PostResponse(p);
                        }
                    }
                    else
                    {
                        MessageBox.Show(response.ReasonPhrase, Global.GetMessage("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    Clear();
                }
            }
            else
            {
                MessageBox.Show("username nije unique!");
            }
        }
Exemplo n.º 4
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (usernameInput.Text.Length == 0)
            {
                MessageDialog msg = new MessageDialog("Username je obavezno!");
                await msg.ShowAsync();
            }
            else
            {
                HttpResponseMessage uq = usernameService.GetResponse(usernameInput.Text.Trim());
                if (uq.Content.ReadAsAsync <bool>().Result == true)
                {
                    bool IsValid = true;

                    if (emailInput.Text.Length == 0 || gradInput.Text.Length == 0 || passwordInput.Password.Length == 0 || prezimeInput.Text.Length == 0 || imeInput.Text.Length == 0)
                    {
                        IsValid = false;
                    }
                    if (emailInput.Text.Contains('@') == false)
                    {
                        IsValid = false;
                    }

                    if (IsValid)
                    {
                        Korisnik k = new Korisnik();
                        k.created_at = DateTime.Now;
                        k.Email      = emailInput.Text;
                        k.Grad       = gradInput.Text;
                        k.Ime        = imeInput.Text;
                        k.password   = passwordInput.Password;
                        k.Prezime    = prezimeInput.Text;
                        if (muskoRB.IsChecked == true)
                        {
                            k.Spol = "M";
                        }
                        else if (zenskoRB.IsChecked == true)
                        {
                            k.Spol = "Z";
                        }
                        else
                        {
                            k.Spol = "M";
                        }
                        k.username = usernameInput.Text;

                        HttpResponseMessage response = korisnikService.PostResponse(k);

                        if (response.IsSuccessStatusCode)
                        {
                            PolicaWM p = new PolicaWM();
                            p.KorisnikID = response.Content.ReadAsAsync <Korisnik>().Result.Id;
                            p.BookCount  = 0;

                            p.Naziv = "To Read";
                            policaService.PostResponse(p);

                            p.Naziv = "Currently Reading";
                            policaService.PostResponse(p);

                            p.Naziv = "Read";
                            policaService.PostResponse(p);

                            MessageDialog msg = new MessageDialog("Registracija uspješna!");
                            await msg.ShowAsync();

                            Frame.Navigate(typeof(LoginPage));
                        }
                        else
                        {
                            MessageDialog msg = new MessageDialog("Registracija nije uspješna!");
                            await msg.ShowAsync();

                            Frame.Navigate(typeof(LoginPage));
                        }
                    }
                    else
                    {
                        MessageDialog msg = new MessageDialog("Sva polja su obavezna, ili niste dobro unijeli email!");
                        await msg.ShowAsync();
                    }
                }
                else
                {
                    MessageDialog msg = new MessageDialog("Username već postoji!");
                    await msg.ShowAsync();
                }
            }
        }