public MKorisnik Insert(KorisnikUpsertRequest request) { var entity = _mapper.Map <Database.Korisnik>(request); entity.Status = true; if (request.Password != request.PasswordConfirmation) { throw new UserException("Passwordi se ne slažu"); } entity.LozinkaSalt = GenerateSalt(); entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password); _context.Korisnik.Add(entity); _context.SaveChanges(); foreach (var uloga in request.Uloge) { _context.KorisnikUloga.Add(new KorisnikUloga() { DatumPromjene = DateTime.Now, KorisnikId = entity.KorisnikId, UlogaId = uloga }); } _context.SaveChanges(); return(_mapper.Map <MKorisnik>(entity)); }
private async void btnSave_Click(object sender, EventArgs e) { KorisnikUpsertRequest request = new KorisnikUpsertRequest(); request.Email = txtEmail.Text; request.KorisnickoIme = txtUserNAme.Text; request.Ime = txtName.Text; request.Prezime = txtSurname.Text; request.Telefon = txtPhoneNumb.Text; int id = await _serviceGetID.Get <int>(new KorisnikSearchRequest { KorisnickoIme = APIService.UserName }); Model.Korisnik k = await _service.Update <Korisnik>(id, request); MessageBox.Show("Changed completed", "Succes", MessageBoxButtons.OK, MessageBoxIcon.Information); txtEmail.Text = k.Email; txtName.Text = k.Ime; txtSurname.Text = k.Prezime; txtUserNAme.Text = k.KorisnickoIme; txtPhoneNumb.Text = k.Telefon; APIService.UserName = k.KorisnickoIme; if (k.Email.Equals("*****@*****.**") && k.Ime.Equals("Unesi ime") && k.Prezime.Equals("Unesi prezime") && k.Telefon.Equals("000/000-000")) { APIService.EditovanProfil = false; } else { APIService.EditovanProfil = true; } }
private async void btnSnimi_Click(object sender, EventArgs e) { if (Validacija()) { MessageBox.Show("Ispravno unesite podatke.", "Info", MessageBoxButtons.OK); } else { if (txtNovaLozinka.Text != "") { txtLozinka.Text = txtNovaLozinka.Text; } KorisnikUpsertRequest model = new KorisnikUpsertRequest() { Ime = txtIme.Text, Prezime = txtPrezime.Text, Adresa = txtAdresa.Text, KorisnickoIme = txtKorisnickoIme.Text, Mail = txtMail.Text, Telefon = txtTelefon.Text, Lozinka = txtLozinka.Text, }; var nesto = await _korisnik.Update <Model.Korisnik>(Global.prijavljeniKorisnik.KorisnikId, model); MessageBox.Show("Uspješno promijenjeni podaci!", "Info", MessageBoxButtons.OK); } }
public Model.Korisnik Update(int id, KorisnikUpsertRequest request) { var entity = _context.Korisniks.Find(id); _context.Korisniks.Attach(entity); _context.Korisniks.Update(entity); _mapper.Map(request, entity); _context.SaveChanges(); return(_mapper.Map <Model.Korisnik>(entity)); }
private async void btnSave_Click(object sender, EventArgs e) { KorisnikUpsertRequest request = new KorisnikUpsertRequest { Ime = txtName.Text, Prezime = txtSurName.Text, KorisnickoIme = txtUserName.Text, Email = txtEmail.Text, Telefon = txtPhone.Text, Password = "******", PasswordConfirmation = "test" }; if (requestUpdate == null) { await _service.Insert <Korisnik>(request); int korisnikID = await _serviceGetIDKorisnik.Get <int>(new KorisnikSearchRequest { KorisnickoIme = txtUserName.Text }); UposlenikUpsertRequest uposlenikRequest = new UposlenikUpsertRequest { PartnerId = APIService.PartnerID, KorisnikId = korisnikID, DatumIzmjene = DateTime.Now }; await _serviceUposlenik.Insert <Uposlenik>(uposlenikRequest); if (int.TryParse(cmbRole.SelectedValue.ToString(), out int idRola)) { await _serviceKorisniciUloge.Insert <KorisniciUloge>(new KorisniciUlogeUpsertRequest { DatumIzmjene = DateTime.Now, KorisnikId = korisnikID, UlogaId = idRola }); } MessageBox.Show("Successfully created User", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); Dispose(); } else { await _service.Update <Korisnik>(KORISNIKID, request); await _serviceKorisniciUlogeDELETE.Delete <KorisniciUloge>(KORISNIKID); if (int.TryParse(cmbRole.SelectedValue.ToString(), out int idRola)) { await _serviceKorisniciUloge.Insert <KorisniciUloge>(new KorisniciUlogeUpsertRequest { DatumIzmjene = DateTime.Now, KorisnikId = KORISNIKID, UlogaId = idRola }); } MessageBox.Show("User successfully updated", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private async void promijeniEmail_Clicked(object sender, EventArgs e) { if (promijeniEmailEntry.Text != null) { ErrorLabelEmail.Text = null; if (!(Regex.IsMatch(promijeniEmailEntry.Text, emailRegex, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)))) { ErrorLabelEmail.Text = "Email nije u tačnom formatu [email protected]!"; } else { ErrorLabelEmail.Text = null; var korisnik = await _korisnikService.GetById <MKorisnik>(Global.prijavljeniKupac.KorisnikId); var uloge = await _korisnikService.Get <List <MKorisnikUloga> >(new KorisnikSearchRequest { KorisnikId = korisnik.KorisnikId }); KorisnikUpsertRequest request = new KorisnikUpsertRequest { Adresa = korisnik.Adresa, Email = promijeniEmailEntry.Text, Ime = korisnik.Ime, Prezime = korisnik.Prezime, KorisnickoIme = korisnik.KorisnickoIme, Password = passwordEntry.Text, PasswordConfirmation = passwordEntry.Text, Telefon = korisnik.Telefon, Uloge = uloge.Select(i => i.UlogaId).ToList() }; await _korisnikService.Update <MKorisnik>(korisnik.KorisnikId, request); promijeniEmailEntry.IsReadOnly = true; promijeniEmailEntry.BackgroundColor = Color.LightGray; } } else { if (promijeniEmailEntry.IsReadOnly == true) { promijeniEmailEntry.IsReadOnly = false; promijeniEmailEntry.BackgroundColor = Color.White; } else { ErrorLabelEmail.Text = "Polje je mandatorno!"; } } }
public MKorisnik Insert(KorisnikUpsertRequest insert) { //provera tacnosti lozinke if (insert.Lozinka != insert.PotrvrdnaLozinka) { throw new Exception("Lozinke se ne slazu!"); } var entity = _mapper.Map <Database.Korisnik>(insert); entity.LozinkaSalt = GenerateSalt(); entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, insert.Lozinka); _context.Korisnik.Add(entity); _context.SaveChanges(); return(_mapper.Map <MKorisnik>(entity)); }
public override Model.Korisnik Insert(KorisnikUpsertRequest request) { Korisnik korisnik = new Korisnik(); korisnik.Ime = request.Ime; korisnik.Prezime = request.Prezime; korisnik.Adresa = request.Adresa; korisnik.KorisnickoIme = request.KorisnickoIme; korisnik.Lozinka = request.Lozinka; korisnik.Telefon = request.Telefon; korisnik.Mail = request.Mail; _db.Korisnik.Add(korisnik); _db.SaveChanges(); return(_mapper.Map <Model.Korisnik>(korisnik)); }
public Korisnik Insert(KorisnikUpsertRequest request) { var entity = _mapper.Map <Database.Korisnici>(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.Korisnici.Add(entity); _context.SaveChanges(); return(_mapper.Map <Model.Models.Korisnik>(entity)); }
public Model.Korisnik Insert(KorisnikUpsertRequest request) { if (request.Password != request.PasswordConfirmation) { throw new Exception("passwordi nisu jednaki"); } var entity = _mapper.Map <Korisnik>(request); entity.LozinkaSalt = GenerateSalt(); entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password); _context.Korisniks.Add(entity); _context.SaveChanges(); return(_mapper.Map <Model.Korisnik>(entity)); }
public override Model.Korisnik Update(int id, KorisnikUpsertRequest request) { var korisnik = _db.Korisnik.Find(id); korisnik.Ime = request.Ime; korisnik.Prezime = request.Prezime; korisnik.Adresa = request.Adresa; korisnik.KorisnickoIme = request.KorisnickoIme; korisnik.Lozinka = request.Lozinka; korisnik.Telefon = request.Telefon; korisnik.Mail = request.Mail; _db.Korisnik.Attach(korisnik); _db.Korisnik.Update(korisnik); _db.SaveChanges(); return(_mapper.Map <Model.Korisnik>(korisnik)); }
public MKorisnik Update(int id, KorisnikUpsertRequest request) { var entity = _context.Korisnik.Find(id); if (!string.IsNullOrWhiteSpace(request.Password)) { if (request.Password != request.PasswordConfirmation) { throw new UserException("Passwordi se ne slažu"); } entity.LozinkaSalt = GenerateSalt(); entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password); _context.SaveChanges(); } _mapper.Map(request, entity); _context.SaveChanges(); return(_mapper.Map <MKorisnik>(entity)); }
public MKorisnik Update(int id, KorisnikUpsertRequest request) { var entity = _context.Korisnik.Find(id); //proveravamo da li je ista unesena stara lozinka sa postojecom u bazi, ako jeste, omogucava var unetastaraLozinkaHash = GenerateHash(entity.LozinkaSalt, request.StaraLozinka); if (unetastaraLozinkaHash == entity.LozinkaHash) { if (!string.IsNullOrWhiteSpace(request.Lozinka)) { entity.LozinkaSalt = GenerateSalt(); entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Lozinka); _context.SaveChanges(); } } _mapper.Map(request, entity); _context.SaveChanges(); //prebaciti na login return(_mapper.Map <MKorisnik>(entity)); }
private async void promijeniAdresu_Clicked(object sender, EventArgs e) { if (promijeniAdresuEntry.Text != null) { ErrorLabelAdresa.Text = null; var korisnik = await _korisnikService.GetById <MKorisnik>(Global.prijavljeniKupac.KorisnikId); var uloge = await _korisnikService.Get <List <MKorisnikUloga> >(new KorisnikSearchRequest { KorisnikId = korisnik.KorisnikId }); KorisnikUpsertRequest request = new KorisnikUpsertRequest { Adresa = promijeniAdresuEntry.Text, Email = korisnik.Email, Ime = korisnik.Ime, Prezime = korisnik.Prezime, KorisnickoIme = korisnik.KorisnickoIme, Password = passwordEntry.Text, PasswordConfirmation = passwordEntry.Text, Telefon = korisnik.Telefon, Uloge = uloge.Select(i => i.UlogaId).ToList() }; await _korisnikService.Update <MKorisnik>(korisnik.KorisnikId, request); promijeniAdresuEntry.IsReadOnly = true; promijeniAdresuEntry.BackgroundColor = Color.LightGray; } else { if (promijeniAdresuEntry.IsReadOnly == true) { promijeniAdresuEntry.IsReadOnly = false; promijeniAdresuEntry.BackgroundColor = Color.White; } else { ErrorLabelAdresa.Text = "Polje je mandatorno!"; } } }
public Korisnik Update(int Id, KorisnikUpsertRequest request) { var entity = _context.Korisnici.FirstOrDefault(x => x.KorisnikId == Id); _context.Korisnici.Attach(entity); _context.Korisnici.Update(entity); request.KorisnikId = entity.KorisnikId; 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.Models.Korisnik>(entity)); }
async Task RegistrujSe() { if (ValidirajPolja()) { var upsertKorisnik = new KorisnikUpsertRequest(); upsertKorisnik.Email = Email; upsertKorisnik.KorisnickoIme = KorisnickoIme; upsertKorisnik.Lozinka = Lozinka; upsertKorisnik.PotrvrdnaLozinka = PotvrdnaLozinka; var noviKorisnik = await _korisnik.Insert <MKorisnik>(upsertKorisnik); //korisnik_uloga dodavanje var upsertKorisnikUloga = new KorisnikUlogaUpsertRequest(); upsertKorisnikUloga.KorisnikId = noviKorisnik.Id; var uloge = await _uloga.Get <List <MUloga> >(null); upsertKorisnikUloga.UlogaId = uloge.FirstOrDefault(x => x.Naziv == "Kandidat").Id; await _korisnikUloga.Insert <MKorisnikUloga>(upsertKorisnikUloga); //dodati kandidata var noviKandidat = new KandidatUpsertRequest { Ime = Ime, Prezime = Prezime, DatumRodjenja = DatumRodjenja, Status = false, KorisnikId = noviKorisnik.Id, Slika = Slika }; var kandidat = await _kandidat.Insert <MKandidat>(noviKandidat); if (kandidat != null) { await Application.Current.MainPage.DisplayAlert("Registracija", "Registracija uspjesna!", "OK"); Application.Current.MainPage = new LoginPage(); } } }
public async Task Register() { await ValidirajPolja(); if (errorLabelIme == null && errorLabelPrezime == null && errorLabelUsername == null && errorLabelEmail == null && errorLabelPassword == null && errorLabelConfirm == null) { IsBusy = true; try { List <int> ulogazakupca = new List <int>(); ulogazakupca.Add(3); KorisnikUpsertRequest request = new KorisnikUpsertRequest { Ime = _ime, Prezime = _prezime, KorisnickoIme = _username, Password = _password, PasswordConfirmation = _passwordConfirmation, Email = _email, Telefon = "+387xx/xxx-xxx", Adresa = "Nepoznato", Uloge = ulogazakupca }; await _service.Insert <dynamic>(request); await Application.Current.MainPage.DisplayAlert("Uspjeh", "Uspješno ste se registrovali", "OK"); Application.Current.MainPage = new LoginPage(); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Greška", ex.Message, "OK"); } } }
private async void button1_Click(object sender, EventArgs e) { if (Validacija()) { MessageBox.Show("Ispravno unesite podatke.", "Info", MessageBoxButtons.OK); } else { KorisnikUpsertRequest model = new KorisnikUpsertRequest(); model.Ime = txtIme.Text; model.Prezime = txtPrezime.Text; model.Mail = txtMail.Text; model.KorisnickoIme = txtKorisnickoIme.Text; model.Adresa = txtAdresa.Text; model.Telefon = txtTelefon.Text; model.Lozinka = txtLozinka.Text; var nesto = await _korisnik.Insert <Model.Korisnik>(model); MessageBox.Show("Uspjesna registracija.", "Info", MessageBoxButtons.OK); Close(); } }
public MKorisnik Update(int id, [FromBody] KorisnikUpsertRequest request) { return(_service.Update(id, request)); }
public MKorisnik Insert(KorisnikUpsertRequest request) { return(_korisniciServis.Insert(request)); }
private async void promijeniPassword_Clicked(object sender, EventArgs e) { if (passwordEntry.Text != null && passwordConfirmationEntry.Text != null) { ErrorLabelConfirmation.Text = null; ErrorLabelPassword.Text = null; if (passwordEntry.Text.Length >= 6) { ErrorLabelPassword.Text = null; if (passwordEntry.Text == passwordConfirmationEntry.Text) { ErrorLabelConfirmation.Text = null; var korisnik = await _korisnikService.GetById <MKorisnik>(Global.prijavljeniKupac.KorisnikId); var uloge = await _korisnikService.Get <List <MKorisnikUloga> >(new KorisnikSearchRequest { KorisnikId = korisnik.KorisnikId }); KorisnikUpsertRequest request = new KorisnikUpsertRequest { Adresa = korisnik.Adresa, Email = korisnik.Email, Ime = korisnik.Ime, Prezime = korisnik.Prezime, KorisnickoIme = korisnik.KorisnickoIme, Password = passwordEntry.Text, PasswordConfirmation = passwordEntry.Text, Telefon = korisnik.Telefon, Uloge = uloge.Select(i => i.UlogaId).ToList() }; await _korisnikService.Update <MKorisnik>(korisnik.KorisnikId, request); await DisplayAlert("Upozorenje", "Aplikacija će vas odjaviti, potrebno je da se opet prijavite sa novim podacima", "Uredu"); await Navigation.PushModalAsync(new LoginPage()); } else { ErrorLabelConfirmation.Text = "Passwordi se ne slažu!"; } } else { ErrorLabelPassword.Text = "Password mora imati bar 6 karaktera!"; } } else { //ako jeste jednako null, to znaci da su polja zakljucana, otkljucaj ih //ako je zakljucano, a kliknula sam na promjenu if (passwordEntry.IsReadOnly == true) { //otkljucaj polja i spremi za unos passwordEntry.IsReadOnly = false; passwordEntry.BackgroundColor = Color.White; PasswordConfirmation.IsVisible = true; passwordConfirmationEntry.BackgroundColor = Color.White; } else { ErrorLabelConfirmation.Text = "Polje je mandatorno!"; ErrorLabelPassword.Text = "Polje je mandatorno!"; } } }
public MKorisnik Update(int id, KorisnikUpsertRequest request) { return(_korisniciServis.Update(id, request)); }
private async void btnSacuvaj_Click(object sender, EventArgs e) { var upsertKorisnik = new KorisnikUpsertRequest(); if (_UposlenikId.HasValue) { MKorisnik korisnik = null; MUposlenik uposlenik = null; var trenutniUposlenik = await _uposlenik.GetById <MUposlenik>(_UposlenikId); //ovde menjamo postojece podatke za tablu korisnik if (!IzmjenaSlike) { upsertUposlenik.Slika = _Slika; } upsertKorisnik.Id = APIService.trenutniKorisnik.Id; upsertKorisnik.Email = txtIzmenaEmail.Text; upsertKorisnik.KorisnickoIme = txtIzmenaKorisnickoIme.Text; upsertKorisnik.StaraLozinka = txtStaraLozinka.Text; upsertKorisnik.Lozinka = txtNovaLozinka.Text; if (txtStaraLozinka.Text != null && txtNovaLozinka.Text != null) { korisnik = await _korisnik.Update <MKorisnik>(APIService.trenutniKorisnik.Id, upsertKorisnik); } //izmena za tablelu uposlenik upsertUposlenik.Id = trenutniUposlenik.Id; upsertUposlenik.Ime = txtIzmenaIme.Text; upsertUposlenik.Prezime = txtIzmenaPrezime.Text; upsertUposlenik.DatumRodjenja = trenutniUposlenik.DatumRodjenja; upsertUposlenik.KorisnikId = APIService.trenutniKorisnik.Id; uposlenik = await _uposlenik.Update <MUposlenik>(_UposlenikId, upsertUposlenik); if (korisnik != null && uposlenik != null) { MessageBox.Show("Uspjesno izmjenjeni podaci!"); } else { MessageBox.Show("Doslo je do greske!"); } frmNoviUposlenik_Load(this, EventArgs.Empty); } if (ValidirajPolja()) { // dodavanje korisnickog naloga upsertKorisnik.Email = txtEmail.Text; upsertKorisnik.KorisnickoIme = txtKorisnickoIme.Text; upsertKorisnik.Lozinka = txtLozinka.Text; upsertKorisnik.PotrvrdnaLozinka = txtLozinka.Text; var noviKorisnik = await _korisnik.Insert <MKorisnik>(upsertKorisnik); //korisnik_uloga dodavanje var upsertKorisnikUloga = new KorisnikUlogaUpsertRequest(); var upsertUposlenikTip = new UTUUpsertRequest(); var tipUposlenikaId = cbTipUposlenika.SelectedValue; if (int.TryParse(tipUposlenikaId.ToString(), out int TUId)) { upsertKorisnikUloga.UlogaId = TUId; } upsertKorisnikUloga.KorisnikId = noviKorisnik.Id; await _korisnikUloga.Insert <MKorisnikUloga>(upsertKorisnikUloga); //dodavanje objekta uposlenik upsertUposlenik.Ime = txtIme.Text; upsertUposlenik.Prezime = txtPrezime.Text; upsertUposlenik.DatumRodjenja = dtpDatumRodjenja.Value; upsertUposlenik.KorisnikId = noviKorisnik.Id; var noviUposlenik = await _uposlenik.Insert <MUposlenik>(upsertUposlenik); if (noviUposlenik != null) { MessageBox.Show("Uposlenik uspjesno dodan!"); this.Close(); Parent.Reload(); } //uposlenik_tipUposlenika var TipId = cbTipUposlenika.SelectedValue; if (int.TryParse(TipId.ToString(), out int Id)) { upsertUposlenikTip.TipUposlenikaId = Id; } upsertUposlenikTip.UposlenikId = noviUposlenik.Id; await _UposlenikTip.Insert <MUposlenikTipUposlenika>(upsertUposlenikTip); } }
public Korisnik Update(int id, [FromBody] KorisnikUpsertRequest request)//zasto from body { return(_service.Update(id, request)); }
public Model.Models.Korisnik Insert(KorisnikUpsertRequest request) { return(_service.Insert(request)); }
public Model.Models.Korisnik Update(int id, [FromBody] KorisnikUpsertRequest request) { var r = _service.Update(id, request); return(r); }