private async Task Sacuvaj()
        {
            if (String.IsNullOrWhiteSpace(Username) || String.IsNullOrWhiteSpace(Ime) || String.IsNullOrWhiteSpace(Prezime) || String.IsNullOrWhiteSpace(Email))
            {
                await App.Current.MainPage.DisplayAlert("Greška", "Potrebno je unijeti obavezna polja", "OK");
            }
            else
            {
                KorisniciUpdateRequest request = new KorisniciUpdateRequest();
                request.KorisnikId    = Global.PrijavljeniKorisnik.KorisnikId;
                request.Ime           = Ime;
                request.Prezime       = Prezime;
                request.KorisnickoIme = Username;
                request.Lozinka       = Password;
                request.Email         = Email;
                request.Telefon       = Telefon;
                request.Adresa        = Adresa;

                var entity = await _korisniciService.Update <Biblioteka_Model.Korisnici>(request.KorisnikId, request);

                if (entity != null)
                {
                    await App.Current.MainPage.DisplayAlert("Info", "Uspješno ste sačuvali podatke", "OK");
                }
            }
        }
Ejemplo n.º 2
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (_korisnik == null)
            {
                var ulogeList   = clbUloge.CheckedItems.Cast <Uloge>();
                var ulogeIdList = ulogeList.Select(x => x.UlogaId).ToList();
                //insert
                KorisniciInsertRequest request = new KorisniciInsertRequest()
                {
                    Ime             = txtIme.Text,
                    Prezime         = txtPrezime.Text,
                    Email           = txtEmail.Text,
                    KorisnickoIme   = txtUsername.Text,
                    Password        = txtPassword.Text,
                    PasswordPotvrda = txtPasswordPotvrda.Text,
                    Status          = chkStatus.Checked,
                    Uloge           = ulogeIdList
                };

                var korisnik = await korisniciService.Insert <Korisnici>(request);
            }
            else
            {
                //update
                KorisniciUpdateRequest request = new KorisniciUpdateRequest()
                {
                    Ime     = txtIme.Text,
                    Prezime = txtPrezime.Text,
                    Status  = chkStatus.Checked
                };

                var korisnik = await korisniciService.Update <Korisnici>(_korisnik.KorisnikId, request);
            }
        }
Ejemplo n.º 3
0
        public Model.Korisnici Update(int id, KorisniciUpdateRequest request)
        {
            //doboavljanje iz baze
            var entity = _context.Korisnici.Find(id);

            _mapper.Map(request, entity);

            _context.SaveChanges();

            return(_mapper.Map <Model.Korisnici>(entity));
        }
Ejemplo n.º 4
0
        public Model.Korisnici Update(int id, KorisniciUpdateRequest request)
        {
            var entity = _context.Korisnici.Find(id); //get user

            _mapper.Map(request, entity);             //transfer in model from database

            //if (!string.IsNullOrWhiteSpace(request.Password)) //check pass, if passe exist
            //{
            //    if (request.Password != request.PasswordConfrimation) //check similarity
            //        throw new Exception("Password is not the same!");
            //}
            _context.SaveChanges();                        //save it
            return(_mapper.Map <Model.Korisnici>(entity)); //return our model, than go to controller
        }
Ejemplo n.º 5
0
        public Model.Korisnik Update(KorisniciUpdateRequest request, int id)
        {
            if (request.Password != request.PasswordConfirmation)
            {
                throw new UserException("Passwordi nisu jednaki!");
            }

            var x = _db.Korisnik.Where(s => s.KorisnikId == id).FirstOrDefault() ?? throw new Exception(Constants.NotFoundErrorMessage + id);

            _mapper.Map(request, x);

            _db.Update(x);
            _db.SaveChanges();

            return(_mapper.Map <Model.Korisnik>(x));
        }
        private async void btnSacuvaj_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                if (_korisnik == null)
                {
                    var ulogeList   = clbUloge.CheckedItems.Cast <Uloge>();
                    var ulogeIdList = ulogeList.Select(x => x.UlogaId).ToList();
                    // insert
                    KorisniciInsertRequest request = new KorisniciInsertRequest
                    {
                        Ime             = txtIme.Text,
                        Prezime         = txtPrezime.Text,
                        Email           = txtEmail.Text,
                        KorisnickoIme   = txtUsername.Text,
                        Password        = txtPassword.Text,
                        PasswordPotvrda = txtPotvrda.Text,
                        Status          = chkStatus.Checked,
                        Telefon         = txtTelefon.Text,
                        Uloge           = ulogeIdList
                    };
                    var korisnik = await korisniciService.Insert <Korisnici>(request);
                }
                else
                {
                    var ulogeList   = clbUloge.CheckedItems.Cast <Uloge>();
                    var ulogeIdList = ulogeList.Select(x => x.UlogaId).ToList();
                    // update
                    KorisniciUpdateRequest request = new KorisniciUpdateRequest
                    {
                        Ime     = txtIme.Text,
                        Prezime = txtPrezime.Text,
                        Status  = chkStatus.Checked,
                        Telefon = txtTelefon.Text,
                        Email   = txtEmail.Text,
                        Uloge   = ulogeIdList
                    };

                    var korisnik = await korisniciService.Update <Korisnici>(_korisnik.KorisnikId, request);
                }

                MessageBox.Show("Operacija uspjesna");
                this.Close();
            }
        }
        public Biblioteka_Model.Korisnici Update(int id, KorisniciUpdateRequest request)
        {
            var entity = _context.Korisnici.Find(id);

            request.UlogaId = entity.UlogaId.Value;
            _context.Korisnici.Attach(entity);
            _context.Korisnici.Update(entity);

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

            _mapper.Map(request, entity);

            _context.SaveChanges();

            return(_mapper.Map <Biblioteka_Model.Korisnici>(entity));
        }
Ejemplo n.º 8
0
        public Model.Korisnici Update(int id, KorisniciUpdateRequest request)
        {
            var result = _context.Korisnici.Where(x => x.Id == id);

            result = IncludeUserDetails(result);

            var entity = result.FirstOrDefault();

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

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

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

            _mapper.Map(request, entity);

            if (request.Pacijent1 != null)
            {
                entity.Pacijent.Alergije           = request.Pacijent1.Alergije;
                entity.Pacijent.BrojKartona        = request.Pacijent1.BrojKartona;
                entity.Pacijent.BrojKnjizice       = request.Pacijent1.BrojKnjizice;
                entity.Pacijent.DatumRegistracije  = request.Pacijent1.DatumRegistracije;
                entity.Pacijent.KrvnaGrupaId       = request.Pacijent1.KrvnaGrupaId;
                entity.Pacijent.SpecijalniZahtjevi = request.Pacijent1.SpecijalniZahtjevi;
                entity.Pacijent.Tezina             = request.Pacijent1.Tezina;
                entity.Pacijent.Visina             = request.Pacijent1.Visina;
            }

            _context.SaveChanges();

            return(_mapper.Map <Model.Korisnici>(entity));
        }
Ejemplo n.º 9
0
        public Model.Korisnici Update(int id, KorisniciUpdateRequest request)
        {
            Database.Korisnici entity = _context.Korisnici.Where(x => x.KorisniciId == id).FirstOrDefault();

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

            if (request.Lozinka != string.Empty)
            {
                if (request.Lozinka != request.LozinkaPotvrda)
                {
                    throw new Exception("Passwordi se ne slažu");
                }

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

            entity = _mapper.Map(request, entity);

            _context.SaveChanges();

            return(_mapper.Map <Model.Korisnici>(entity));
        }
Ejemplo n.º 10
0
 public Model.Korisnici Update(int id, [FromBody] KorisniciUpdateRequest request)
 {
     return(_service.Update(id, request));
 }