Beispiel #1
0
        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)));
        }
Beispiel #2
0
        // 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 static bool UpdateFile(this VoiceNote voiceNote, File file)
        {
            if (voiceNote.Voice.Id == file.Id)
            {
                voiceNote.Voice = file;
                return(true);
            }

            return(false);
        }
        public static string GetDuration(this VoiceNote voiceNote)
        {
            var duration = TimeSpan.FromSeconds(voiceNote.Duration);

            if (duration.TotalHours >= 1)
            {
                return(duration.ToString("h\\:mm\\:ss"));
            }
            else
            {
                return(duration.ToString("mm\\:ss"));
            }
        }
Beispiel #5
0
        // 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));
        }
Beispiel #6
0
        public async Task <IActionResult> Download(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());
            }

            var path = Path.Combine(
                Directory.GetCurrentDirectory(),
                "wwwroot\\UserRecordings", voiceNote.FileName);

            if (!System.IO.File.Exists(path))
            {
                return(NotFound());
            }
            var memory = new MemoryStream();

            using (var stream = new FileStream(path, FileMode.Open))
            {
                await stream.CopyToAsync(memory);
            }
            memory.Position = 0;
            return(File(memory, GetContentType(path), voiceNote.Name + Path.GetExtension(path).ToLowerInvariant()));
        }
 public virtual int Update(VoiceNote dataSet)
 {
     return(this.Adapter.Update(dataSet, "VoiceNote"));
 }
Beispiel #8
0
        public async Task <IActionResult> Create(VoiceNoteCreateViewModel voiceNoteViewModel)
        {
            AppUser appUser = AuthExtender.GetLoggedInUser(this, _context);

            if (ModelState.IsValid)
            {
                AppUser newOwner = null;
                if (appUser.Id.Equals(voiceNoteViewModel.OwnerId))
                {
                    newOwner = appUser;
                }
                else
                {
                    AppUser probablyNewOwner = _context.Users.FirstOrDefault(p => p.Id.Equals(voiceNoteViewModel.OwnerId));
                    if (probablyNewOwner == null)
                    {
                        ModelState.AddModelError("OwnerId", "Hack attempt!");
                        ViewBag.UserList = MakeAllowedUsersList(appUser, null);
                        return(View(voiceNoteViewModel));
                    }

                    if (_context.SickWardenRelations.Any(p => p.Warden.Equals(appUser) && p.Sick.Equals(probablyNewOwner) && p.IsAccepted.Equals(true)))
                    {
                        newOwner = probablyNewOwner;
                    }
                    else
                    {
                        ModelState.AddModelError("OwnerId", "Hack attempt!");
                        ViewBag.UserList = MakeAllowedUsersList(appUser, null);
                        return(View(voiceNoteViewModel));
                    }
                }

                string newFileName = Guid.NewGuid().ToString() + Path.GetExtension(voiceNoteViewModel.File.FileName).ToLowerInvariant();
                if (voiceNoteViewModel != null && voiceNoteViewModel.File != null && voiceNoteViewModel.File.Length != 0)
                {
                    if (!Directory.Exists("wwwroot\\UserRecordings"))
                    {
                        Directory.CreateDirectory("wwwroot\\UserRecordings");
                    }

                    var path = Path.Combine(
                        Directory.GetCurrentDirectory(), "wwwroot\\UserRecordings",
                        newFileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await voiceNoteViewModel.File.CopyToAsync(stream);
                    }
                }
                else
                {
                    ModelState.AddModelError("File", "Invalid file!");
                    ViewBag.UserList = MakeAllowedUsersList(appUser, null);
                    return(View(voiceNoteViewModel));
                }

                VoiceNote voiceNote = new VoiceNote
                {
                    Id       = voiceNoteViewModel.Id,
                    Name     = voiceNoteViewModel.Name,
                    Comment  = voiceNoteViewModel.Comment,
                    Owner    = newOwner,
                    FileName = newFileName
                };

                _context.Add(voiceNote);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.UserList = MakeAllowedUsersList(appUser, null);
            return(View(voiceNoteViewModel));
        }
Beispiel #9
0
 public void UpdateWave(VoiceNote voiceNote)
 {
     UpdateSlide(voiceNote.Waveform);
 }
Beispiel #10
0
 public void UpdateWaveform(VoiceNote voiceNote)
 {
     UpdateWaveform(voiceNote.Waveform);
 }