public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (!(AllowedUsers is null)) { Document.AllowedUsers = AllowedUsers.Split(",").ToList().Select(a => a.Trim()).ToArray(); } var test = _context.DocumentAnnotations.AsNoTracking().SingleOrDefault(m => m.DocumentId == Document.DocumentId && m.UserId == User.FindFirst(ClaimTypes.NameIdentifier).Value); if (test is null) { return(NotFound()); } _context.Attach(Document).State = EntityState.Modified; await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Text).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TextExists(Text.TextId)) { return(NotFound()); } throw; } return(RedirectToPage("./Index")); }
public async Task <IActionResult> PostHighlights([FromBody] List <Highlight> highlights) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var annIds = highlights.Select(h => h.AnnotationId); var res = _context.Annotations.Where(a => annIds.Contains(a.AnnotationId)).All(a => a.Document.UserId == GetCurrentUser()); if (!res) { return(Unauthorized()); } _context.Highlights.AddRange(highlights); await _context.SaveChangesAsync(); return(CreatedAtAction("PostHighlights", highlights.Select(x => new { id = x.HighlightId }), highlights)); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Texts.Add(Text); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Document.LastLocation = new Location(0, 0); Document.User = await _userManager.GetUserAsync(User); _context.DocumentAnnotations.Add(Document); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Document = await _context.DocumentAnnotations.FindAsync(id); if (Document != null) { _context.DocumentAnnotations.Remove(Document); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } LinkShortener = await _context.LinkShorteners.FindAsync(id); if (LinkShortener != null) { _context.LinkShorteners.Remove(LinkShortener); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <ActionResult <Annotation> > PutAnnotation([FromRoute] int id, [FromBody] AnnotationPutDTO annotation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var ann = annotation.Annotation; if (id != ann.AnnotationId) { return(BadRequest()); } var docAnn = _context.DocumentAnnotations.SingleOrDefault(d => d.DocumentId == ann.DocumentId); if (docAnn is null) { return(BadRequest()); } if (docAnn.UserId != GetCurrentUser()) { return(Unauthorized()); } foreach (var highlight in annotation.HighlightsToAdd) { if (highlight.AnnotationId != ann.AnnotationId) { return(BadRequest()); } highlight.AnnotationId = id; } foreach (var highlight in annotation.HighlightsToRemove) { if (highlight.AnnotationId != ann.AnnotationId) { return(BadRequest()); } } _context.Annotations.Update(ann); _context.Highlights.AddRange(annotation.HighlightsToAdd); _context.Highlights.RemoveRange(annotation.HighlightsToRemove); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnnotationExists(id)) { return(NotFound()); } else { throw; } } return(Ok(ann)); }