Exemplo n.º 1
0
        public Models.ApplicationUser.ApplicationUser Insert(ApplicationUserInsert insert)
        {
            var entity = _mapper.Map <eTraining.Database.Entities.ApplicationUser>(insert);

            if (insert.Password != insert.PasswordConfirm)
            {
                throw new Exception("Passwordi se ne slazu.");
            }
            entity.PasswordSalt = GenerateSalt();
            entity.PasswordHash = GenerateHash(entity.PasswordSalt, insert.Password);
            _ctx.ApplicationUser.Add(entity);
            _ctx.SaveChanges();
            return(_mapper.Map <Models.ApplicationUser.ApplicationUser>(entity));
        }
Exemplo n.º 2
0
        public Models.ApplicationUser.ApplicationUser Update(int id, ApplicationUserInsert update)
        {
            var entity = _ctx.ApplicationUser.Include(x => x.Opcina).Where(x => x.Id == id).FirstOrDefault();

            _mapper.Map(update, entity);
            if (!string.IsNullOrWhiteSpace(update.Password))
            {
                if (update.Password != update.PasswordConfirm)
                {
                    throw new Exception("Passwordi se ne slazu.");
                }
                //TODO:update pass
            }
            _ctx.SaveChanges();
            return(_mapper.Map <Models.ApplicationUser.ApplicationUser>(entity));
        }
Exemplo n.º 3
0
        private async void btnSacuvaj_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren() && int.TryParse(comboOpcine.SelectedValue.ToString(), out int idOpcina))
            {
                string spol = "Not specified";
                if (btnZ.Checked)
                {
                    spol = "Z";
                }
                else if (btnM.Checked)
                {
                    spol = "M";
                }

                var insert = new ApplicationUserInsert()
                {
                    Email           = txtEmail.Text,
                    Ime             = txtIme.Text,
                    Prezime         = txtPrezime.Text,
                    Password        = txtPassword.Text,
                    PasswordConfirm = txtPotvrda.Text,
                    Username        = txtUsername.Text,
                    OpcinaId        = idOpcina,
                    JMBG            = txtJMBG.Text,
                    Spol            = spol,
                    DatumRodjenja   = dateRodjenje.Value
                };
                if (img != null)
                {
                    insert.Slika = img;
                }

                if (_id.HasValue)
                {
                    //ovo baguje
                    await _service.Update <Models.ApplicationUser.ApplicationUser>(_id, insert);
                }
                else
                {
                    await _service.Insert <Models.ApplicationUser.ApplicationUser>(insert);
                }
                MessageBox.Show("Uspješno obavljeno.");
            }
        }