private async void btnSpremi_Click(object sender, EventArgs e) { if (prikaziPritisnut == true) { if (ValidateChildren() && await ZauzetoKorisnickoIme() == false) { var korisnikId = int.Parse(dgvOsoblje.SelectedRows[0].Cells[0].Value.ToString()); OsobljeInsertRequest osoba = await _apiService.GetById <OsobljeInsertRequest>(korisnikId); //ePostrojenje.Model.Osoblje trenutni = await _apiService.GetById<ePostrojenje.Model.Osoblje>(korisnikId); var request = new OsobljeInsertRequest() { Mail = txtMail.Text, Ime = txtImeUnos.Text, Prezime = txtPrezimeUnos.Text, DatumRodjenja = dtpRodjendan.Value, Jmbg = txtJmbg.Text, KorisnickoIme = txtKorisnickoIme.Text, Pitanje = osoba.Pitanje, Odgovor = osoba.Odgovor //Password = osoba }; await _apiService.Update <ePostrojenje.Model.Osoblje>(korisnikId, request); if (request != null) { MessageBox.Show("Uspješno izvršeno"); } } } }
public Model.Osoblje Update(int id, OsobljeInsertRequest request) { var entity = _context.Osoblje.Find(id); _context.Osoblje.Attach(entity); _context.Osoblje.Update(entity); if (!string.IsNullOrWhiteSpace(request.Password)) { if (request.Password != request.PasswordConfirmation) { throw new Exception("Passwordi se ne slažu"); } entity.LozinkaSalt = GenerateSalt(); entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password); } //entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password); _mapper.Map(request, entity); _context.SaveChanges(); return(_mapper.Map <Model.Osoblje>(entity)); }
public Model.Osoblje Insert(OsobljeInsertRequest request) { var entity = _mapper.Map <Database.Osoblje>(request); if (request.Password != request.PasswordConfirmation) { throw new Exception("Passwordi se ne slažu"); } entity.LozinkaSalt = GenerateSalt(); entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password); _context.Osoblje.Add(entity); _context.SaveChanges(); foreach (var odjel in request.Odjeli) { Database.OdjeliOsoblje odjeliOsoblje = new Database.OdjeliOsoblje(); odjeliOsoblje.OsobljeId = entity.OsobljeId; odjeliOsoblje.OdjelId = odjel; _context.OdjeliOsoblje.Add(odjeliOsoblje); } _context.SaveChanges(); return(_mapper.Map <Model.Osoblje>(entity)); }
public Model.Osoblje Update(int id, OsobljeInsertRequest update) { var entity = _context.Osoblje.Find(id); _mapper.Map(update, entity); _context.SaveChanges(); return(_mapper.Map <Model.Osoblje>(entity)); }
private async void btnRegistracija_Click(object sender, EventArgs e) { if (await ZauzetoKorisnickoIme() == false) { if (ValidateChildren()) { //var odjeli = clbOdjeli.CheckedItems.Cast<ePostrojenje.Model.Odjeli>().Select(x => x.OdjelId).ToList(); //ePostrojenje.Model.Osoblje trenutni = await _apiService.GetById<ePostrojenje.Model.Osoblje>(korisnikId); var request = new OsobljeInsertRequest() { Ime = txtUsername.Text, KorisnickoIme = txtUsername.Text, Mail = "*****@*****.**", Password = txtPassword.Text, PasswordConfirmation = txtPotvrda.Text, Pitanje = txtPitanje.Text, Odgovor = txtOdgovor.Text, DatumRodjenja = DateTime.Now }; VrstaAplikacijeInsert vrstaApp = new VrstaAplikacijeInsert(); vrstaApp.DesktopStatus = 1; await _serviceVrsta.Update <dynamic>(1, vrstaApp); await _service.Insert <Osoblje>(request); //await _service.Insert<OsobljeInsertRequest>(request); if (request != null) { MessageBox.Show("Uspješno izvršeno"); txtUsername.Clear(); txtPassword.Clear(); txtPotvrda.ResetText(); txtPitanje.Clear(); txtOdgovor.Clear(); this.Close(); //pbSlika.ResetText(); } } } }
public Model.Osoblje Insert(OsobljeInsertRequest insert) { var entity = _mapper.Map <Database.Osoblje>(insert); if (insert.Lozinka != insert.PotvrdiLozinku) { throw new UserException("Lozinke se ne podudaraju"); } entity.LozinkaSalt = Util.PasswordGenerator.GenerateSalt(); entity.LozinkaHash = Util.PasswordGenerator.GenerateHash(insert.Lozinka, entity.LozinkaSalt); _context.Osoblje.Add(entity); _context.SaveChanges(); //foreach (var item in insert.Uloge) //{ // var korisniciUloga = new Database.KorisniciUloge(); // korisniciUloga.DatumIzmjene = DateTime.Now; // korisniciUloga.KorisnikId =entity.Id; // korisniciUloga.UlogaId = item; // _context.KorisniciUloge.Add(korisniciUloga); //} return(_mapper.Map <Model.Osoblje>(entity)); }
public Model.Osoblje Update(int id, OsobljeInsertRequest update) { return(_service.Update(id, update)); }
public Model.Osoblje Insert(OsobljeInsertRequest insert) { return(_service.Insert(insert)); }
private async void btnSacuvaj_Click(object sender, EventArgs e) { if (await ZauzetoKorisnickoIme() == false) { if (ValidateChildren()) { var odjeli = clbOdjeli.CheckedItems.Cast <Odjeli>().Select(x => x.OdjelId).ToList(); //ePostrojenje.Model.Osoblje trenutni = await _apiService.GetById<ePostrojenje.Model.Osoblje>(korisnikId); var request = new OsobljeInsertRequest(); //request.Odjeli = new List<int>(); request.Ime = txtIme.Text; request.Prezime = txtPrezime.Text; request.KorisnickoIme = txtKorisnickoIme.Text; request.DatumRodjenja = dtpRodjendan.Value; request.Mail = txtMail.Text; request.Jmbg = txtJMBG.Text; //clbOdjeli.ClearSelected(); request.Password = txtLozinka.Text; request.PasswordConfirmation = txtLozinkaPotvrda.Text; request.Pitanje = txtPitanje.Text; request.Odgovor = txtOdgovor.Text; request.Odjeli = odjeli; //pbSlika.ResetText(); VrstaAplikacijeInsert vrstaApp = new VrstaAplikacijeInsert(); vrstaApp.DesktopStatus = 1; APIService.Username = baza; APIService.Password = baza; await _serviceVrsta.Update <dynamic>(1, vrstaApp); APIService.Username = user; APIService.Password = pass; await _service.Insert <Osoblje>(request); //await _service.Insert<OsobljeInsertRequest>(request); if (request != null) { MessageBox.Show("Uspješno izvršeno"); txtIme.Clear(); txtPrezime.Clear(); dtpRodjendan.ResetText(); txtMail.Clear(); txtJMBG.Clear(); clbOdjeli.ClearSelected(); clbOdjeli.ResetText(); clbOdjeli.SetItemChecked(0, false); clbOdjeli.SetItemChecked(1, false); clbOdjeli.SetItemChecked(2, false); //clbOdjeli.Items. txtKorisnickoIme.Clear(); txtLozinka.Clear(); txtLozinkaPotvrda.Clear(); txtPitanje.Clear(); txtOdgovor.Clear(); //pbSlika.ResetText(); } } } }