// GET: VoiceNotes/Delete/5 public async Task <IActionResult> Delete(long?id) { AppUser appUser = AuthExtender.GetLoggedInUser(this, _context); if (id == null) { return(NotFound()); } VoiceNote voiceNote = await _context.VoiceNotes .FirstOrDefaultAsync(m => m.Id == id); if (voiceNote == null) { return(NotFound()); } await _context.Entry(voiceNote).Reference(p => p.Owner).LoadAsync(); if (!voiceNote.Owner.Equals(appUser) & !_context.SickWardenRelations.Any(p => p.Warden.Equals(appUser) && p.Sick.Equals(voiceNote.Owner) && p.IsAccepted.Equals(true))) { return(NotFound()); } VoiceNoteIndexViewModel voiceNoteIndexViewModel = new VoiceNoteIndexViewModel { Id = voiceNote.Id, Name = voiceNote.Name, Comment = voiceNote.Comment, Owner = voiceNote.Owner.FullName }; return(View(voiceNoteIndexViewModel)); }
public async Task <IActionResult> DeleteConfirmed(long id) { AppUser appUser = AuthExtender.GetLoggedInUser(this, _context); VoiceNote voiceNote = await _context.VoiceNotes.FindAsync(id); await _context.Entry(voiceNote).Reference(p => p.Owner).LoadAsync(); if (!voiceNote.Owner.Equals(appUser) & !_context.SickWardenRelations.Any(p => p.Warden.Equals(appUser) && p.Sick.Equals(voiceNote.Owner) && p.IsAccepted.Equals(true))) { return(NotFound()); } VoiceNoteIndexViewModel voiceNoteIndexViewModel = new VoiceNoteIndexViewModel { Id = voiceNote.Id, Name = voiceNote.Name, Comment = voiceNote.Comment, Owner = voiceNote.Owner.FullName }; _context.VoiceNotes.Remove(voiceNote); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
// GET: VoiceNotes/Details/5 public async Task <IActionResult> Details(long?id) { AppUser appUser = AuthExtender.GetLoggedInUser(this, _context); if (id == null) { return(NotFound()); } VoiceNote voiceNote = await _context.VoiceNotes .FirstOrDefaultAsync(m => m.Id == id); if (voiceNote == null) { return(NotFound()); } await _context.Entry(voiceNote).Reference(p => p.Owner).LoadAsync(); if (!voiceNote.Owner.Equals(appUser) & !_context.SickWardenRelations.Any(p => p.Warden.Equals(appUser) && p.Sick.Equals(voiceNote.Owner) && p.IsAccepted.Equals(true))) { return(NotFound()); } String content = null; String fileName = voiceNote.FileName; if (fileName != null) { String type = GetTagType(fileName); String base64 = await GetRecordingBase64(fileName); if (base64 != null) { content = "data:" + type + ";base64," + base64; } } VoiceNoteIndexViewModel voiceNoteIndexViewModel = new VoiceNoteIndexViewModel { Id = voiceNote.Id, Name = voiceNote.Name, Comment = voiceNote.Comment, Owner = voiceNote.Owner.FullName, RecordingRawBase64 = content }; return(View(voiceNoteIndexViewModel)); }