public IActionResult Get(int notebookId) { var currentUser = User.Claims.Single(c => c.Type == ClaimTypes.Email).Value; if (!_notebookService.CanUserView(notebookId, currentUser)) { return(Forbid()); } return(Ok(_context.NotebookComment.Where(nc => nc.NotebookId == notebookId).ToList())); }
public IActionResult Post(NotebookCollectionViewModel notebookCollectionViewModel) { var notebook = _context.Notebook.SingleOrDefault(n => n.Id == notebookCollectionViewModel.NotebookId); var currentUser = User.Claims.Single(c => c.Type == ClaimTypes.Email).Value; if (notebook == null) { return(NotFound(new { message = "Notebook not found" })); } if (!_notebookService.CanUserView(notebookCollectionViewModel.NotebookId, currentUser)) { return(Forbid()); } _context.NotebookCollection.Add(new NotebookCollection { NotebookId = notebookCollectionViewModel.NotebookId, User = currentUser }); _context.SaveChanges(); var notebookCollection = _context.NotebookCollection.Single(ns => ns.NotebookId == notebookCollectionViewModel.NotebookId && ns.User == currentUser); return(Ok(notebookCollection)); }
public IActionResult Get(int id) { var currentUser = User.Claims.Single(c => c.Type == ClaimTypes.Email).Value; if (!_notebookService.CanUserView(id, currentUser)) { return(Forbid()); } var notebook = _context.Notebook.SingleOrDefault(b => b.Id == id); if (notebook == null) { return(NotFound()); } else { return(Ok(notebook)); } }
public IActionResult GetCurrentUserPermission(int notebookId) { var currentUser = User.Claims.Single(c => c.Type == ClaimTypes.Email).Value; if (!_notebookService.CanUserView(notebookId, currentUser)) { return(Forbid()); } else { var notebookShare = _context.NotebookShare.SingleOrDefault(ns => ns.NotebookId == notebookId && ns.User == currentUser); if (notebookShare == null) { return(NotFound()); } else { return(Ok(notebookShare)); } } }