Beispiel #1
0
        private string UploadedFile(UposleniciDodajViewModel model)
        {
            string uniqueFileName = null;

            if (model.Slika != null)
            {
                string uploadsFolder = Path.Combine(hostingEnvironment.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 Dodaj(UposleniciDodajViewModel model)
        {
            if (ModelState.IsValid)
            {
                string     uniqueFileName = UploadedFile(model);
                Uposlenici noviUposlenik  = new Uposlenici
                {
                    Ime         = model.Ime,
                    Prezime     = model.Prezime,
                    Email       = model.Email,
                    RadnoMjesto = model.RadnoMjesto,
                    Slika       = uniqueFileName
                };

                _uposleniciRepository.DodajUposlenika(noviUposlenik);

                return(RedirectToAction("details", new { id = noviUposlenik.Id }));
            }

            return(View());
        }