Example #1
0
        public IActionResult Prijava(int oglasId)
        {
            var naziv = _context.Oglas.FirstOrDefault(x => x.Id == oglasId).Naslov;
            var model = new OglasPrijava()
            {
                OglasId = oglasId,
                Naslov  = naziv
            };

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> PosaljiPrijavu(OglasPrijava prijava, IFormFile CV)
        {
            var user = await _userManager.FindByNameAsync(prijava.Username);

            var korisnik = new KorisnikOglas()
            {
                DatumPrijave = DateTime.Now,
                KorisnikId   = user.Id,
                OglasId      = prijava.OglasId
            };

            _context.KorisnikOglas.Add(korisnik);
            await _context.SaveChangesAsync();

            var entity = await _context.KorisnikOglas.FirstOrDefaultAsync(x => x.KorisnikId == user.Id);

            if (CV != null)
            {
                if (CV.Length > 0)
                {
                    // wwwroot/CV/UserID/
                    var path = Path.Combine(_hostingEnvironment.WebRootPath, "CV-R", entity.Id.ToString());
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    // wwwroot/CV/UserID/OglasID.pdf
                    var filename  = prijava.OglasId.ToString();
                    var extension = Path.GetExtension(CV.FileName);

                    var fullPath = Path.Combine("CV-R", entity.Id.ToString(), filename + extension).Replace("\\", "_");

                    var bytes         = Encoding.UTF8.GetBytes(fullPath);
                    var encodedString = Convert.ToBase64String(bytes);

                    entity.PathCV = encodedString;

                    using (var stream = new FileStream(Path.Combine(path, filename + extension), FileMode.Create))
                    {
                        await CV.CopyToAsync(stream);
                    }
                }
            }
            else
            {
                entity.PathCV = null;
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Oglas", new { note = "Prijava poslana!" }));
        }