Esempio n. 1
0
        private async void btnSnimi_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                var listaUloga = clbUloge.CheckedItems.Cast <Model.Uloga>().Select(x => x.UlogaId).ToList();

                var request = new KorisnikInsertRequest()
                {
                    Ime                  = txtIme.Text,
                    Prezime              = txtPrezime.Text,
                    Email                = txtEmail.Text,
                    BrojTelefona         = txtBrojTelefona.Text,
                    DatumRodjenja        = dateTimePicker.Value,
                    KorisnickoIme        = txtKorisnickoIme.Text,
                    Password             = txtPassword.Text,
                    PasswordConfirmation = txtPasswordConfirmation.Text,
                    Uloge                = listaUloga
                };

                if (!_Id.HasValue)
                {
                    await _service.Insert <Model.Korisnik>(request);
                }
                else
                {
                    await _service.Update <Model.Korisnik>(_Id, request);
                }
                MessageBox.Show("Operacija uspješna!");
            }
        }
        public Modeli.Korisnik Insert(KorisnikInsertRequest request)
        {
            if (_context.Korisnici.Any(x => x.Email == request.Email))
            {
                throw new UserException("Email \"" + request.Email + "\" je već zauzet!");
            }

            var entity = _mapper.Map <Korisnik>(request);

            entity.LozinkaSalt = GenerateSalt();
            entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password);

            _context.Korisnici.Add(entity);
            _context.SaveChanges();

            if (request.Uloge != null && request.Uloge.Count() > 0 && request.Uloge[0] != 0)
            {
                foreach (var uloga in request.Uloge)
                {
                    _context.KorisniciUloge.Add(new KorisnikUloga
                    {
                        UlogaId      = uloga,
                        KorisnikId   = entity.KorisnikId,
                        DatumIzmjene = DateTime.Now
                    });
                }
            }
            _context.SaveChanges();

            return(_mapper.Map <Modeli.Korisnik>(entity));
        }
Esempio n. 3
0
        private void SnimiButton_Clicked(object sender, EventArgs e)
        {
            if (!Validate())
            {
                return;
            }

            var _korisnik = _korisnikService.Get <List <Korisnik> >(new KorisnikSearchRequest {
                Email = ApiService.Email
            }).FirstOrDefault();
            var req = new KorisnikInsertRequest
            {
                Ime               = Ime.Text,
                Prezime           = Prezime.Text,
                Email             = Email.Text,
                GradId            = ((Grad)Gradovi.SelectedItem).Id,
                UlogaId           = _korisnik.UlogaId,
                DatumRodjenja     = DatumRodjenja.Date,
                DatumRegistracije = _korisnik.DatumRegistracije,
                Password          = Lozinka.Text,
                PasswordPotvrda   = Lozinka.Text
            };

            _korisnikService.Update <Korisnik>(_korisnik.Id, req);
            Navigation.PopAsync();
        }
Esempio n. 4
0
        public Model.Korisnik Insert(KorisnikInsertRequest request)
        {
            var entity = _mapper.Map <Database.Korisnik>(request);

            if (request.Password != request.PasswordConfirmation)
            {
                throw new UserException("Lozinke se ne podudaraju!");
            }

            entity.PasswordSalt = GenerateSalt();
            entity.PasswordHash = GenerateHash(entity.PasswordSalt, request.Password);

            _context.Korisnik.Add(entity);
            _context.SaveChanges();

            foreach (var item in request.Uloge)
            {
                _context.KorisnikUloga.Add(new Database.KorisnikUloga()
                {
                    DatumIzmjene = DateTime.Now,
                    KorisnikId   = entity.KorisnikId,
                    UlogaId      = item
                });
            }

            _context.SaveChanges();
            return(_mapper.Map <Model.Korisnik>(entity));
        }
Esempio n. 5
0
        public Model.Korisnik Insert(KorisnikInsertRequest request)
        {
            var entity = _mapper.Map <Data.EntityModels.Korisnik>(request);

            if (request.Lozinka != request.LozinkaPotvrda)
            {
                throw new UserException("Lozinke se ne podudaraju.");
            }
            if (CheckUsernameExists(request.KorisnickoIme))
            {
                throw new UserException("Korisničko ime je već u upotrebi.");
            }
            if (CheckEmailExists(request.Email))
            {
                throw new UserException("Email adresa je već u upotrebi.");
            }

            entity.Klijent = new Data.EntityModels.Klijent
            {
                DatumRegistracije = DateTime.Now
            };

            entity.LozinkaSalt = GenerateSalt();
            entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Lozinka);

            _context.Korisnik.Add(entity);
            _context.SaveChanges();

            return(_mapper.Map <Model.Korisnik>(entity));
        }
Esempio n. 6
0
        public async Task SaveEdit()
        {
            var request = new KorisnikInsertRequest
            {
                Ime           = Ime,
                Prezime       = Prezime,
                Email         = Email,
                KorisnickoIme = KorisnickoIme,
                GradID        = SelectedGrad.GradID,
                BrojTelefona  = Telefon,
                Slika         = Slika,
                SlikaThumb    = Slika,
                DatumRodjenja = Datum
            };

            try
            {
                await _korisnik.Update <Korisnik>(korisnikId, request);

                await Application.Current.MainPage.DisplayAlert("OK", "Uspješna izmjena podataka", "OK");
            }
            catch (Exception)
            {
            }
        }
Esempio n. 7
0
        public Model.Korisnik Update(int id, KorisnikInsertRequest request)
        {
            var entity = _context.Korisnici.Find(id);

            if ((!string.IsNullOrWhiteSpace(request.Password)))
            {
                if (request.Password != request.PasswordConfirmation)
                {
                    throw new UserException("Passwordi se ne slazu");
                }

                var korisnik = _context.Korisnici.Find(int.Parse(_httpContext.GetUserId()));

                var noviHash = GenerateHash(korisnik.LozinkaSalt, request.OldPassword);

                if (noviHash == korisnik.LozinkaHash)
                {
                    korisnik.LozinkaSalt = GenerateSalt();
                    korisnik.LozinkaHash = GenerateHash(korisnik.LozinkaSalt, request.Password);
                    _context.SaveChanges();
                    return(_mapper.Map <Model.Korisnik>(request));
                }
                throw new UserException("Unijeli se pogrešnu lozinku.");
            }

            _mapper.Map(request, entity);

            _context.SaveChanges();

            return(_mapper.Map <Model.Korisnik>(entity));
        }
        public async Task Registracija()
        {
            if (!Validate())
            {
                return;
            }


            KorisnikInsertRequest request = new KorisnikInsertRequest
            {
                Adresa               = this.Adresa,
                Email                = this.Email,
                GradId               = this.Grad.Id,
                Ime                  = this.Ime,
                Password             = this.Password,
                PasswordConfirmation = this.Password,
                PostanskiBroj        = this.PostanskiBroj,
                Prezime              = this.Prezime,
                Telefon              = this.Telefon,
                Username             = this.Username
            };

            Korisnik result = await _registracijaService.Insert <Korisnik>(request);

            if (result != default(Korisnik) && result != null)
            {
                await Application.Current.MainPage.DisplayAlert("Info", Messages.UspjesnaRegistracija, "OK");

                Application.Current.MainPage = new LoginPage();
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("Info", Messages.NeuspjesnaRegistracija, "OK");
            }
        }
        public Model.Korisnik Insert(KorisnikInsertRequest request)
        {
            var entity = _mapper.Map <Database.Korisnik>(request);

            if (request.Password != request.PasswordPotvrda)
            {
                throw new Exception("Passwordi se ne slažu");
            }

            entity.LozinkaSalt = GenerateSalt();
            entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password);

            _context.Korisnik.Add(entity);
            _context.SaveChanges();

            if (request.Uloge.Count() > 0)
            {
                foreach (var uloga in request.Uloge)
                {
                    Database.KorisnikUloga korisniciUloge = new Database.KorisnikUloga();
                    korisniciUloge.KorisnikId   = entity.KorisnikId;
                    korisniciUloge.UlogaId      = uloga;
                    korisniciUloge.DatumIzmjene = DateTime.Now;
                    _context.KorisnikUloga.Add(korisniciUloge);
                }
            }
            else
            {
                Database.KorisnikUloga korisniciUloge = new Database.KorisnikUloga();
                korisniciUloge.KorisnikId   = entity.KorisnikId;
                korisniciUloge.UlogaId      = request.Uloga;
                korisniciUloge.DatumIzmjene = DateTime.Now;
                _context.KorisnikUloga.Add(korisniciUloge);
            }
            _context.SaveChanges();
            // -------- dodano posebno
            var korisnik = new Model.Korisnik()
            {
                Ime           = entity.Ime,
                Prezime       = entity.Prezime,
                KorisnickoIme = entity.KorisnickoIme,
                Email         = entity.Email,
                Telefon       = entity.Telefon,
                KorisnikId    = entity.KorisnikId
            };

            //-----


            // return _mapper.Map<Model.Korisnici>(entity);
            return(korisnik);
        }
Esempio n. 10
0
        public Model.Korisnik Insert(KorisnikInsertRequest request)
        {
            var    entity = _mapper.Map <Database.Korisnik>(request);
            string _username;

            entity.Username = GenerateUsername(entity.Ime, entity.Prezime);
            string _password;

            if (request.Uloga == "Clan")
            {
                _password = RandomPass();
                _username = GenerateUsername(entity.Ime, entity.Prezime);
            }
            else
            {
                _password = request.Password;
                _username = request.Username;
            }
            entity.PasswordSalt = GenerateSalt();
            entity.PasswordHash = GenerateHash(entity.PasswordSalt, _password);
            entity.Username     = _username;
            _context.Korisnik.Add(entity);
            _context.SaveChanges();
            var korisnikUloga = new KorisnikUloga
            {
                KorisnikId   = entity.Id,
                UlogaId      = _context.Uloga.Where(x => x.Naziv == request.Uloga).Select(x => x.Id).SingleOrDefault(),
                DatumIzmjene = DateTime.Today
            };

            if (request.Uloga == "Clan")
            {
                MailData mailData = new MailData
                {
                    SmtpServer = _config.GetValue <string>("MailData:SmtpServer"),
                    Port       = _config.GetValue <int>("MailData:Port"),
                    Sender     = _config.GetValue <string>("MailData:Sender"),
                    UserName   = _config.GetValue <string>("MailData:UserName"),
                    Password   = _config.GetValue <string>("MailData:Password")
                };
                string       emailSubject = "Login podaci";
                string       emailBody    = "Username: "******"    Password:  " + _password;
                EmailMessage emailMessage = Email.CreateEmailMessage(mailData.Sender, entity.Email, emailSubject, emailBody);
                MimeMessage  mimeMessage  = Email.CreateMimeMessage(emailMessage);
                Email.Send(mimeMessage, mailData);
            }
            _context.KorisnikUloga.Add(korisnikUloga);
            _context.SaveChanges();
            return(_mapper.Map <Model.Korisnik>(entity));
        }
        public Modeli.Korisnik Update(int id, KorisnikInsertRequest request)
        {
            var entity = _context.Korisnici.Include(x => x.KorisnikUloga).FirstOrDefault(x => x.KorisnikId == id);

            _context.Korisnici.Attach(entity);
            _context.Korisnici.Update(entity);

            if (!string.IsNullOrWhiteSpace(request.Password))
            {
                entity.LozinkaSalt = GenerateSalt();
                entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password);
            }

            _mapper.Map(request, entity);
            _context.SaveChanges();

            var korisnikUloge = _context.KorisniciUloge.Where(x => x.KorisnikId == entity.KorisnikId);

            if (request.Uloge.Count() < korisnikUloge.Count())
            {
                foreach (var uloga in korisnikUloge)
                {
                    if (!request.Uloge.Contains(uloga.UlogaId))
                    {
                        _context.KorisniciUloge.Remove(uloga);
                    }
                }
            }

            if (request.Uloge != null && request.Uloge.Count() > 0 && request.Uloge[0] != 0)
            {
                foreach (var uloga in request.Uloge)
                {
                    if (!_context.KorisniciUloge.Any(x => x.KorisnikId == entity.KorisnikId && x.UlogaId == uloga))
                    {
                        _context.KorisniciUloge.Add(new KorisnikUloga
                        {
                            UlogaId      = uloga,
                            KorisnikId   = entity.KorisnikId,
                            DatumIzmjene = DateTime.Now
                        });
                    }
                }
            }
            _context.SaveChanges();

            return(_mapper.Map <Modeli.Korisnik>(entity));
        }
Esempio n. 12
0
        public Model.Korisnik Update(int id, KorisnikInsertRequest request)
        {
            var entity = _context.Korisnik.Find(id);

            _mapper.Map(request, entity);

            if (!string.IsNullOrWhiteSpace(request.Password))
            {
                if (request.Password != request.PasswordConfirmation)
                {
                    throw new UserException("Lozinke se ne podudaraju!");
                }
            }
            _context.SaveChanges();
            return(_mapper.Map <Model.Korisnik>(entity));
        }
Esempio n. 13
0
 public RegisterVM(KorisnikInsertRequest model)
 {
     RegisterCommand = new Command(async() => await Register());
     if (model.Postojeci)
     {
         KorisnickoIme = model.KorisnickoIme;
         Ime           = model.Ime;
         Prezime       = model.Prezime;
         Sifra         = model.Sifra;
         Email         = model.Email;
         BrojTelefona  = model.BrojTelefona;
         DatumRodjenja = model.DatumRodjenja;
         KorisnickoIme = model.KorisnickoIme;
         JMBG          = model.Jmbg;
         Postojeci     = true;
         KorisnikId    = model.KorisnikId;
     }
 }
Esempio n. 14
0
        private void UpdatePassword(KorisnikInsertRequest request)
        {
            if (request.Password != request.PasswordConfirmation)
            {
                throw new UserException("Passwordi se ne slazu");
            }

            var korisnik = _context.Korisnici.Find(int.Parse(_httpContext.GetUserId()));

            var noviHash = GenerateHash(korisnik.LozinkaSalt, request.OldPassword);

            if (noviHash == korisnik.LozinkaHash)
            {
                korisnik.LozinkaSalt = GenerateSalt();
                korisnik.LozinkaHash = GenerateHash(korisnik.LozinkaSalt, request.Password);
                _context.SaveChanges();
                return;
            }

            throw new UserException("Unijeli se pogrešnu lozinku.");
        }
Esempio n. 15
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            if (!Validation())
            {
                return;
            }

            var korisnik = new KorisnikInsertRequest
            {
                DatumRegistracije = DateTime.Now,
                DatumRodjenja     = DatumRodjenja.Date,
                Email             = Email.Text,
                Password          = Sifra.Text,
                PasswordPotvrda   = SifraPotvrda.Text,
                Ime     = Ime.Text,
                Prezime = Prezime.Text,
                UlogaId = _ulogaService.Get <List <Uloga> >(new UlogaSearchRequest {
                    NazivUloge = "User"
                }).Select(s => s.Id).FirstOrDefault(),                                                                                       //_ulogaService.GetByName<Uloga>("User").Id,
                GradId = ((Grad)GradoviListaPicker.SelectedItem).Id
            };

            _korisnikService.Add(korisnik);
            await Task.Delay(2000);

            var k = _korisnikService.Get <List <Korisnik> >(new KorisnikSearchRequest {
                Email = Email.Text
            }).FirstOrDefault();

            if (k != null)
            {
                await Navigation.PopToRootAsync();

                await Navigation.PushAsync(new LoginPage());
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("Greska", "Vas racun nije kreiran. Pokusajte ponovno.", "Ok");
            }
        }
        private async void SpremiNovogClana()
        {
            if (ValidateChildren())
            {
                var request = new KorisnikInsertRequest
                {
                    BrojKartice  = txtBrojKartice.Text,
                    DatumRodenja = dtpDatumRodenja.Value.Date,
                    Email        = txtEmail.Text,
                    Ime          = txtIme.Text,
                    Prezime      = txtPrezime.Text,
                    Spol         = cmbSpol.SelectedItem.ToString(),
                    Telefon      = txtTelefon.Text,
                    Uloga        = "Clan",
                    Username     = "******",
                    Password     = "******"
                };
                using (MemoryStream ms = new MemoryStream())
                {
                    if (pictureBox1.Image != null)
                    {
                        pictureBox1.Image.Save(ms, ImageFormat.Jpeg);
                        request.Slika = ms.ToArray();
                    }
                    else
                    {
                        MessageBox.Show("Potrebno je uslikati!", "", MessageBoxButtons.OK);
                        return;
                    }
                }
                Korisnik entity = null;
                entity = await _service.Insert <Korisnik>(request);

                if (entity != null)
                {
                    MessageBox.Show("Uspješno izvršeno");
                    this.Close();
                }
            }
        }
Esempio n. 17
0
        public async Task NavigateFromMenu(int id)
        {
            if (!MenuPages.ContainsKey(id))
            {
                switch (id)
                {
                case (int)MenuItemType.PretragaSmjestaja:
                    MenuPages.Add(id, new NavigationPage(new PocetnaPage(Model)));
                    break;

                case (int)MenuItemType.Rezervacije:
                    MenuPages.Add(id, new NavigationPage(new RezervacijeViewPage(Model)));
                    break;

                case (int)MenuItemType.Profil:
                    KorisnikInsertRequest request = new KorisnikInsertRequest();
                    MenuPages.Add(id, new NavigationPage(new RegisterPage(Model)));
                    break;

                case (int)MenuItemType.Odjava:
                    Application.Current.MainPage = new LoginPage();
                    break;
                }
            }

            var newPage = MenuPages[id];

            if (newPage != null && Detail != newPage)
            {
                Detail = newPage;

                if (Device.RuntimePlatform == Device.Android)
                {
                    await Task.Delay(100);
                }

                IsPresented = false;
            }
        }
Esempio n. 18
0
        public KorisnikInsertRequest Insert(KorisnikInsertRequest request)
        {
            var k = _mapper.Map <Models.Korisnik>(request);

            k.SifraSalt = GenerateSalt();
            k.SifraHash = GenerateHash(k.SifraSalt, request.Sifra);
            if (request.Role == 2)
            {
                k.IsAdmin = true;
            }
            if (!_context.Korisnik.Any(x => x.KorisnickoIme == request.KorisnickoIme && x.Email == request.Email))
            {
                _context.Korisnik.Add(k);
                _context.SaveChanges();
                if (request.Role == 3)
                {
                    Klijent novi = new Klijent
                    {
                        KorisnikId = k.KorisnikId
                    };
                    _context.Klijent.Add(novi);
                    _context.SaveChanges();
                }
                else if (request.Role == 1)
                {
                    Izdavac novi = new Izdavac {
                        KorisnikId = k.KorisnikId
                    };
                    _context.Izdavac.Add(novi);
                    _context.SaveChanges();
                }
            }
            else
            {
                request.Response = "Korisničko ime ili e-mail je zauzet!";
            }
            return(request);
        }
Esempio n. 19
0
        public async Task UpdatePassword()
        {
            var request = new KorisnikInsertRequest
            {
                Password             = Lozinka,
                PasswordConfirmation = LozinkaPotvrda,
                OldPassword          = StaraLozinka
            };

            try
            {
                await _korisnik.Update <Korisnik>(korisnikId, request);

                await Application.Current.MainPage.DisplayAlert("OK", "Uspješna izmjena podataka", "OK");

                Lozinka = StaraLozinka = LozinkaPotvrda = "";

                Application.Current.MainPage = new NavigationPage(new LoginPage());
            }
            catch (Exception)
            {
            }
        }
Esempio n. 20
0
        private async void btnUpdatePassword_Click(object sender, EventArgs e)
        {
            var request = new KorisnikInsertRequest
            {
                Password             = txtPasswordNovi.Text,
                PasswordConfirmation = txtPotvrda.Text,
                OldPassword          = txtPasswordStari.Text
            };

            try
            {
                var result = await _apiService.Update <Model.Korisnik>(1, request);

                if (result != null)
                {
                    MessageBox.Show("Uspješno izvršeno! Logirajte se ponovo!");
                    Application.Restart();
                }
            }
            catch (Exception)
            {
            }
        }
        public Model.Korisnik Update(int id, KorisnikInsertRequest request)
        {
            var entity = _context.Korisnik.Find(id);

            _context.Korisnik.Attach(entity);
            _context.Korisnik.Update(entity);

            if (!string.IsNullOrWhiteSpace(request.Password))
            {
                if (request.Password != request.PasswordPotvrda)
                {
                    throw new Exception("Passwordi se ne slažu");
                }

                entity.LozinkaSalt = GenerateSalt();
                entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password);
            }

            _mapper.Map(request, entity);

            _context.SaveChanges();

            return(_mapper.Map <Model.Korisnik>(entity));
        }
        public async Task Register()
        {
            if (!Validate())
            {
                return;
            }
            var request = new KorisnikInsertRequest
            {
                Ime                  = Ime,
                Prezime              = Prezime,
                Email                = Email,
                KorisnickoIme        = KorisnickoIme,
                GradID               = SelectedGrad.GradID,
                Password             = Lozinka,
                PasswordConfirmation = LozinkaPotvrda,
                BrojTelefona         = Telefon,
                Slika                = Slika,
                SlikaThumb           = SlikaThumb,
                DatumRodjenja        = Datum
            };

            try
            {
                var k = await _korisnik.Insert <Korisnik>(request);

                if (k != null)
                {
                    await Application.Current.MainPage.DisplayAlert("OK", "Uspješna registracija", "OK");

                    await Application.Current.MainPage.Navigation.PopAsync();
                }
            }
            catch (Exception)
            {
            }
        }
Esempio n. 23
0
 private void bttnRegistrujSe_Click(object sender, EventArgs e)
 {
     if (this.ValidateChildren())
     {
         var korisnik = new KorisnikInsertRequest
         {
             DatumRegistracije = DateTime.Now,
             DatumRodjenja     = dtpDatumRodjenja.Value,
             Email             = txtEmail.Text,
             Password          = txtSifra.Text,
             PasswordPotvrda   = txtSifraPotvrda.Text,
             Ime     = txtIme.Text,
             Prezime = txtPrezime.Text,
             UlogaId = _ulogaApiService.Get <List <Uloga> >(new UlogaSearchRequest {
                 NazivUloge = "User"
             }).FirstOrDefault().Id,
             GradId = cbGrad.SelectedIndex
         };
         _korisnikApiService.Add(korisnik);
         var loginForma = new frmLogin();
         loginForma.Show();
         Hide();
     }
 }
Esempio n. 24
0
        public Model.Korisnik Insert(KorisnikInsertRequest request)
        {
            var getAll = _context.Korisnici.ToList();

            foreach (var k in getAll)
            {
                if (k.KorisnickoIme == request.KorisnickoIme)
                {
                    throw new UserException("Korisničko ime već postoji!");
                }
                if (k.Email == request.Email)
                {
                    throw new UserException("Već postoji profil registrovan na " + request.Email);
                }
            }

            var entity = _mapper.Map <Database.Korisnik>(request);

            if (request.Password != request.PasswordConfirmation)
            {
                throw new UserException("Passwordi se ne slazu");
            }

            entity.LozinkaSalt = GenerateSalt();
            entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password);
            entity.IsVozac     = false;

            _context.Korisnici.Add(entity);
            _context.SaveChanges();

            if (request.Uloge.Count != 0)
            {
                foreach (var uloga in request.Uloge)
                {
                    entity.KorisniciUloge.Add(new Database.KorisniciUloge
                    {
                        KorisnikId   = entity.KorisnikID,
                        DatumIzmjene = DateTime.Now,
                        UlogaId      = uloga
                    });
                }
            }

            _context.SaveChanges();

            var model = new Model.Korisnik
            {
                KorisnikID    = entity.KorisnikID,
                BrojTelefona  = entity.BrojTelefona,
                DatumRodjenja = entity.DatumRodjenja,
                Email         = entity.Email,
                GradID        = entity.GradID,
                Ime           = entity.Ime,
                IsVozac       = entity.IsVozac,
                KorisnickoIme = entity.KorisnickoIme,
                Prezime       = entity.Prezime,
                Slika         = entity.Slika
            };

            model.KorisniciUloge = new List <Model.KorisniciUloge>();
            foreach (var item in entity.KorisniciUloge)
            {
                model.KorisniciUloge.Add(new Model.KorisniciUloge
                {
                    DatumIzmjene    = item.DatumIzmjene,
                    KorisnikId      = item.KorisnikId,
                    KorisnikUlogaId = item.KorisnikUlogaId,
                    UlogaId         = item.UlogaId
                });
            }

            return(model);
        }
Esempio n. 25
0
        async Task Register()
        {
            if (!Postojeci)
            {
                if (Ime == null || Ime.Length < 3)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Ime nije pravilno uneseno!", "Ok");

                    return;
                }
                if (Prezime == null || Prezime.Length < 3)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Prezime nije pravilno uneseno!", "Ok");

                    return;
                }
                Regex regex = new Regex(@"^\d+$");

                if (!regex.Match(JMBG).Success || JMBG.Length != 13)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "JMBG nije pravilno unesen!", "Ok");

                    return;
                }

                bool isPhone = Regex.IsMatch(BrojTelefona, @"\(?\d{3}\)?-? *\d{3}-? *-?\d{4}");

                if (isPhone || BrojTelefona.Length < 8)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Telefon je neispravno unesen!", "Ok");

                    return;
                }

                if (DatumRodjenja != null)
                {
                    if (DatumRodjenja > DateTime.Today)
                    {
                        await Application.Current.MainPage.DisplayAlert("Greška", "Datum je neispravno unesen!", "Ok");

                        return;
                    }
                }

                bool isEmail = Regex.IsMatch(Email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);

                if (!isEmail || Email.Length < 6)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "E-Mail je neispravno unesen!", "Ok");

                    return;
                }

                if (KorisnickoIme == null || KorisnickoIme.Length < 3)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Korisnicko Ime nije pravilno uneseno!", "Ok");

                    return;
                }

                if (Sifra == null || Sifra.Length < 6)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Šifra mora biti duža od 6 karaktera!", "Ok");

                    return;
                }

                if (SifraPonovo == Sifra && Sifra != null)
                {
                    KorisnikInsertRequest request = new KorisnikInsertRequest
                    {
                        Ime           = Ime,
                        Prezime       = Prezime,
                        Jmbg          = JMBG,
                        KorisnickoIme = KorisnickoIme,
                        IsAdmin       = false,
                        Sifra         = Sifra,
                        Role          = 3,
                        Email         = Email,
                        BrojTelefona  = BrojTelefona,
                        DatumRodjenja = DatumRodjenja
                    };
                    request = await service.Register <KorisnikInsertRequest>(request);

                    if (request.Response == null)
                    {
                        Application.Current.MainPage = new LoginPage();
                    }
                    else
                    {
                        await Application.Current.MainPage.DisplayAlert("Greška", request.Response, "OK");
                    }
                    return;
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Šifre nisu iste", "Ok");

                    return;
                }
            }
            else
            {
                if (Ime == null || Ime.Length < 3)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Ime nije pravilno uneseno!", "Ok");

                    return;
                }
                if (Prezime == null || Prezime.Length < 3)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Prezime nije pravilno uneseno!", "Ok");

                    return;
                }
                Regex regex = new Regex(@"^\d+$");

                if (!regex.Match(JMBG).Success || JMBG.Length != 13)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "JMBG nije pravilno unesen!", "Ok");

                    return;
                }

                bool isPhone = Regex.IsMatch(BrojTelefona, @"\(?\d{3}\)?-? *\d{3}-? *-?\d{4}");

                if (isPhone || BrojTelefona.Length < 8)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Telefon je neispravno unesen!", "Ok");

                    return;
                }

                if (DatumRodjenja != null)
                {
                    if (DatumRodjenja > DateTime.Today)
                    {
                        await Application.Current.MainPage.DisplayAlert("Greška", "Datum je neispravno unesen!", "Ok");

                        return;
                    }
                }

                bool isEmail = Regex.IsMatch(Email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);

                if (!isEmail || Email.Length < 6)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "E-Mail je neispravno unesen!", "Ok");

                    return;
                }

                if (KorisnickoIme == null || KorisnickoIme.Length < 3)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Korisnicko Ime nije pravilno uneseno!", "Ok");

                    return;
                }

                if (Sifra == null || Sifra.Length < 6)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Šifra mora biti duža od 6 karaktera!", "Ok");

                    return;
                }

                if (SifraPonovo == Sifra && Sifra != null)
                {
                    KorisnikEditRequest request = new KorisnikEditRequest
                    {
                        KorisnikId    = KorisnikId,
                        Ime           = Ime,
                        Prezime       = Prezime,
                        Jmbg          = JMBG,
                        KorisnickoIme = KorisnickoIme,
                        Sifra         = Sifra,
                        Email         = Email,
                        BrojTelefona  = BrojTelefona,
                        DatumRodjenja = DatumRodjenja
                    };
                    await service.Update <KorisnikEditRequest>(KorisnikId, request);

                    KorisnikModel k = new KorisnikModel
                    {
                        Ime           = Ime,
                        Prezime       = Prezime,
                        KorisnickoIme = KorisnickoIme
                    };
                    Application.Current.MainPage = new PocetnaPage(k);
                }
            }
        }
 public Model.Korisnik Insert(KorisnikInsertRequest request)
 {
     return(_service.Insert(request));
 }
        private async void Button_Clicked(object sender, EventArgs e)
        {
            if (!Regex.IsMatch(this.Ime.Text, @"^[a-zA-Z]+$") && this.Ime.Text.Length < 3)
            {
                await DisplayAlert("Greška", "Ime se sastoji samo od slova i minimalno 3 karaktera", "OK");
            }
            else if (!Regex.IsMatch(this.Prezime.Text, @"^[a-zA-Z]+$") && this.Prezime.Text.Length < 3)
            {
                await DisplayAlert("Greška", "Prezime se sastoji samo od slova i minimalno 3 karaktera", "OK");
            }
            else if (!Regex.IsMatch(this.Telefon.Text, @"^[+]{1}\d{3}[ ]?\d{2}[ ]?\d{3}[ ]?\d{3}"))
            {
                await DisplayAlert("Greška", "Format telefona je: +123 45 678 910", "OK");
            }
            else if (!Regex.IsMatch(this.Email.Text, @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"))
            {
                await DisplayAlert("Greška", "Neispravan format email-a!", "OK");
            }
            else if (!Regex.IsMatch(this.KorisnickoIme.Text, @"^(?=.{4,40}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$"))
            {
                await DisplayAlert("Greška", "Neispravan format ili dužina korisničkog imena (4-40)", "OK");
            }
            else if (string.IsNullOrWhiteSpace(this.Password.Text))
            {
                await DisplayAlert("Greška", "Morate unijeti novu ili staru lozinku", "OK");
            }
            else if (this.Password.Text != this.PasswordPotvrda.Text)
            {
                await DisplayAlert("Greška", "Lozinke moraju biti iste", "OK");
            }
            else if (this.Password.Text.Length < 4)
            {
                await DisplayAlert("Greška", "Lozinka ne smije biti kraća od 4 karaktera", "OK");
            }
            else
            {
                try
                {
                    KorisnikInsertRequest req = new KorisnikInsertRequest()
                    {
                        Ime             = this.Ime.Text,
                        Prezime         = this.Prezime.Text,
                        KorisnickoIme   = this.KorisnickoIme.Text,
                        Password        = this.Password.Text,
                        PasswordPotvrda = this.PasswordPotvrda.Text,
                        Telefon         = this.Telefon.Text,
                        Email           = this.Email.Text,
                    };
                    var lozinka    = APIService.Password;
                    var korisnicko = APIService.Username;
                    await _korisnik.Update <Korisnik>(korisnickiprofil.korisnik.KorisnikId, req);
                    await DisplayAlert("OK", "Uspješno uneseni podaci", "OK");

                    if (lozinka != this.Password.Text || korisnicko != this.KorisnickoIme.Text)
                    {
                        App.Current.MainPage = new LoginPage();
                    }
                }
                catch (Exception err)
                {
                    throw new Exception(err.Message);
                }
            }
        }
 public Model.Korisnik Update(int id, KorisnikInsertRequest request)
 {
     return(_korisnikService.Update(id, request));
 }
 public Model.Korisnik Update(int id, [FromBody] KorisnikInsertRequest request)
 {
     return(_service.Update(id, request));
 }
Esempio n. 30
0
        private async void btnSacuvaj_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                var roleList = clbRole.CheckedItems.Cast <Model.Uloga>().Select(x => x.UlogaId).ToList();

                var request = new KorisnikInsertRequest
                {
                    Email           = txtEmail.Text,
                    Ime             = txtIme.Text,
                    KorisnickoIme   = txtKorisnickoIme.Text,
                    Password        = txtPassword.Text,
                    PasswordPotvrda = txtPassPotvrda.Text,
                    Prezime         = txtPrezime.Text,
                    Telefon         = txtTelefon.Text,
                    Uloge           = roleList
                };

                Model.Korisnik entity = null;
                if (!_id.HasValue)
                {
                    try
                    {
                        await _service.Insert <Model.Korisnik>(request);

                        MessageBox.Show("Uspješno sačuvani podaci");
                        this.Close();
                    }

                    catch (Exception)
                    {
                        DialogResult r = MessageBox.Show("Nemate pravo pristupa");
                        if (r == DialogResult.OK)
                        {
                            this.Close();
                        }
                    }
                }
                else
                {
                    try
                    {
                        await _service.Update <Model.Korisnik>(_id.Value, request);

                        MessageBox.Show("Uspješno sačuvani podaci");
                        this.Close();
                    }

                    catch (Exception)
                    {
                        DialogResult r = MessageBox.Show("Nemate pravo pristupa");
                        if (r == DialogResult.OK)
                        {
                            this.Close();
                        }
                    }
                }

                if (entity != null)
                {
                    MessageBox.Show("Uspješno izvršeno");
                }
            }
            else
            {
                MessageBox.Show("Operacija nije uspjela");
                this.Close();
            }
        }