public IActionResult AddRecenzija(int id) { if (!_context.Rad.Any(r => r.Id == id)) { return(RedirectToAction("EditRadRecenzent", new { @id = id })); } //id - id knjige var recenzentid = _userManager.GetUserId(User); var model = new AddRecenzijaVM { EKnjigaId = id, RecenzentId = recenzentid }; return(View(model)); }
public async Task <IActionResult> AddRecenzija(AddRecenzijaVM model) { if (ModelState.IsValid) { if (Path.GetExtension(model.File.FileName).Equals(".pdf")) { var currentUser = await _userManager.GetUserAsync(User); var recenzija = new Recenzija { EKnjigaId = model.EKnjigaId, ReviewerId = model.RecenzentId, FileName = model.File.FileName, Version = "0" }; var naslovKnjige = _context.EKnjiga.Include(e => e.Rad).FirstOrDefault(e => e.EKnjigaId == model.EKnjigaId).Rad.Naslov; string folderPath = Path.Combine(_environment.WebRootPath, "Uploads", currentUser.UserName, "Recenzije", naslovKnjige); System.IO.DirectoryInfo di = new DirectoryInfo(folderPath); if (!di.Exists) { Directory.CreateDirectory(folderPath); } foreach (FileInfo file in di.GetFiles()) { file.Delete(); //remove all files from the directory } var filePath = Path.Combine(folderPath, model.File.FileName); using (var stream = new FileStream(filePath, FileMode.Create)) { await model.File.CopyToAsync(stream); } } } return(RedirectToAction("EditRadRecenzent", new { @id = model.EKnjigaId })); }