Beispiel #1
0
        private string UploadedFile(KorisnikDodajStomatologViewModel model)
        {
            string uniqueFileName = "blank-profile.jpg";

            if (model.Slika != null)
            {
                string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Slika.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.Slika.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
Beispiel #2
0
        public IActionResult DodajStomatolog()
        {
            var model = new KorisnikDodajStomatologViewModel
            {
                Gradovi = _context.Grads.Select
                              (i => new SelectListItem {
                    Text = i.Naziv, Value = i.GradId.ToString()
                }).ToList(),
                Titule = _context.Titulas.Select
                             (i => new SelectListItem {
                    Text = i.Naziv, Value = i.TitulaId.ToString()
                }).ToList()
            };

            return(View("DodajStomatolog", model));
        }
Beispiel #3
0
        public IActionResult DodajStomatolog(KorisnikDodajStomatologViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Gradovi = _context.Grads.Select
                                    (i => new SelectListItem {
                    Text = i.Naziv, Value = i.GradId.ToString()
                }).ToList();
                model.Titule = _context.Titulas.Select
                                   (i => new SelectListItem {
                    Text = i.Naziv, Value = i.TitulaId.ToString()
                }).ToList();
                return(View("DodajStomatolog", model));
            }

            if (_context.KorisnickiNalogs.Any(i => i.Email == model.Email))
            {
                TempData["errorMessage"] = "Email adresa se koristi.";
                model.Gradovi            = _context.Grads.Select
                                               (i => new SelectListItem {
                    Text = i.Naziv, Value = i.GradId.ToString()
                }).ToList();
                model.Titule = _context.Titulas.Select
                                   (i => new SelectListItem {
                    Text = i.Naziv, Value = i.TitulaId.ToString()
                }).ToList();
                return(View("DodajStomatolog", model));
            }

            byte[] lozinkaSalt = PasswordSettings.GetSalt();
            var    templozinka = GenerateRandomPassword();
            string lozinkaHash = PasswordSettings.GetHash(templozinka, lozinkaSalt);


            string uniqueFileName = UploadedFile(model);

            KorisnickiNalog korisnickiNalog = new KorisnickiNalog
            {
                Ime           = model.Ime,
                Prezime       = model.Prezime,
                Email         = model.Email,
                LozinkaHash   = lozinkaHash,
                LozinkaSalt   = Convert.ToBase64String(lozinkaSalt),
                Permisije     = 1,
                Kreirano      = DateTime.Now,
                Mobitel       = model.Mobitel,
                GradId        = model.GradID,
                Adresa        = model.Adresa,
                JMBG          = model.JMBG,
                DatumRodjenja = model.DatumRodjenja,
                Spol          = model.Spol,
                Slika         = uniqueFileName
            };
            Stomatolog stomatolog = new Stomatolog
            {
                KorisnickiNalog = korisnickiNalog,
                TitulaID        = model.TitulaID,
                DatumZaposlenja = model.DatumZaposlenja,
                BrojZiroRacuna  = model.BrojZiroRacuna,
                Aktivan         = model.Aktivan
            };

            _context.KorisnickiNalogs.Add(korisnickiNalog);
            _context.Stomatologs.Add(stomatolog);

            _context.SaveChanges();

            string primalacPoruke = korisnickiNalog.Ime + " " + korisnickiNalog.Prezime;
            string poruka         = primalacPoruke + " vaši pristupni podaci su: \nEmail: " + korisnickiNalog.Email +
                                    "\nPassword: "******"Nalog napravljen", poruka);

            TempData["successMessage"] = "Uspješno ste dodali novog stomatologa.";
            return(RedirectToAction("uredi-stomatolog"));
        }