예제 #1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Audio = await _context.Audio.FindAsync(id);

            if (Audio != null)
            {
                var message = await _context.Message.FindAsync(Audio.MessageId);

                _context.Audio.Remove(Audio);
                if (message != null)
                {
                    message.AudioId = null;
                    _context.Message.Update(message);
                    await _context.SaveChangesAsync();

                    return(RedirectToPage("/Messages/Edit", new { id = message.Id }));
                }
                await _context.SaveChangesAsync();

                _logger.LogCritical($"User '{User.Identity.Name}' deleted '{Audio.ToString()}'.");
            }

            return(RedirectToPage("/Messages/Index"));
        }
예제 #2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Playlist = await _context.Playlist.FindAsync(id);

            if (Playlist != null)
            {
                var series = await _context.Series.FindAsync(Playlist.SeriesId);

                _context.Playlist.Remove(Playlist);

                if (series != null)
                {
                    series.PlaylistId = null;
                    _context.Series.Update(series);
                    await _context.SaveChangesAsync();

                    return(RedirectToPage("/Series/Edit", new { id = series.Id }));
                }
                await _context.SaveChangesAsync();

                _logger.LogCritical($"User '{User.Identity.Name}' deleted '{Playlist.ToString()}'.");
            }

            return(RedirectToPage("/Series/Index"));
        }
예제 #3
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var message = await _context.Message.FindAsync(Audio.MessageId);

            if (message == null)
            {
                Console.Error.WriteLine("Unexpected null message with ID: " + Audio.MessageId);
                return(Page());
            }

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

            // Update the message's audio reference
            message.AudioId = Audio.Id;
            _context.Message.Update(message);
            await _context.SaveChangesAsync();

            _logger.LogCritical($"User '{User.Identity.Name}' created '{Audio.ToString()}'.");

            return(RedirectToPage("/Messages/Edit", new { id = message.Id }));
        }
예제 #4
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var series = await _context.Series.FindAsync(Playlist.SeriesId);

            if (series == null)
            {
                Console.Error.WriteLine("Unexpected null series with ID: " + Playlist.SeriesId);
                return(Page());
            }

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

            // Update the series' playlist reference
            series.PlaylistId = Playlist.Id;
            _context.Series.Update(series);
            await _context.SaveChangesAsync();

            _logger.LogCritical($"User '{User.Identity.Name}' created '{Playlist.ToString()}'.");

            return(RedirectToPage("/Series/Edit", new { id = series.Id }));
        }
예제 #5
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Update(Series);

            try
            {
                await _context.SaveChangesAsync();

                _logger.LogCritical($"User '{User.Identity.Name}' edited object with new values'{Series.ToString()}'.");
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SeriesExists(Series.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Series = await _context.Series.Include(s => s.Messages).FirstOrDefaultAsync(s => s.Id == id);

            if (Series != null)
            {
                foreach (var message in Series.Messages)
                {
                    if (message != null)
                    {
                        message.SeriesId = null;
                        _context.Message.Update(message);
                    }
                }

                _context.Series.Remove(Series);
                await _context.SaveChangesAsync();

                _logger.LogCritical($"User '{User.Identity.Name}' deleted '{Series.ToString()}'.");
            }

            return(RedirectToPage("./Index"));
        }
예제 #7
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Message.Add(Message);
            await _context.SaveChangesAsync(); // Save message before linking references

            _context.BibleReferences.AddRange(Message.BibleReferences);
            await _context.SaveChangesAsync();

            _logger.LogCritical($"User '{User.Identity.Name}' created '{Message.ToString()}'.");

            return(RedirectToPage("./Edit", new { id = Message.Id }));
        }
예제 #8
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var message = await _context.Message.FindAsync(Video.MessageId);

            if (message == null)
            {
                Console.Error.WriteLine("Unexpected null message with ID: " + Video.MessageId);
                return(Page());
            }

            // Unlink the original message if linking to a new message
            if (OriginalMessageId != null)
            {
                var originalMessage = await _context.Message.FindAsync(OriginalMessageId);

                if (originalMessage != null &&
                    originalMessage.VideoId != message.VideoId)
                {
                    originalMessage.VideoId = null;
                    _context.Update(originalMessage);
                }
            }

            message.VideoId = Video.Id;
            _context.Update(Video);
            _context.Update(message);

            try
            {
                await _context.SaveChangesAsync();

                _logger.LogCritical($"User '{User.Identity.Name}' edited object with new values'{Video.ToString()}'.");
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VideoExists(Video.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("/Messages/Details", new { id = Video.MessageId }));
        }
예제 #9
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var series = await _context.Series.FindAsync(Playlist.SeriesId);

            if (series == null)
            {
                Console.Error.WriteLine("Unexpected null message with ID: " + Playlist.SeriesId);
                return(Page());
            }

            // Unlink the original series if linking to a new series
            if (OriginalSeriesId != null)
            {
                var originalSeries = await _context.Series.FindAsync(OriginalSeriesId);

                if (originalSeries != null &&
                    originalSeries.PlaylistId != series.PlaylistId)
                {
                    originalSeries.PlaylistId = null;
                    _context.Update(originalSeries);
                }
            }

            series.PlaylistId = Playlist.Id;
            _context.Update(Playlist);
            _context.Update(series);

            try
            {
                await _context.SaveChangesAsync();

                _logger.LogCritical($"User '{User.Identity.Name}' edited object with new values'{Playlist.ToString()}'.");
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlaylistExists(Playlist.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Details", new { id = Playlist.Id }));
        }
예제 #10
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Message = await _context.Message.FindAsync(id);

            if (Message != null)
            {
                if (Message.Video != null)
                {
                    _context.Video.Remove(Message.Video);
                }

                if (Message.Audio != null)
                {
                    _context.Audio.Remove(Message.Audio);
                }

                if (Message.Notes != null)
                {
                    _context.Notes.Remove(Message.Notes);
                }

                var referencesToRemove = _context.BibleReferences.Where(x => x.MessageId == id);
                _context.BibleReferences.RemoveRange(referencesToRemove);

                _context.Message.Remove(Message);
                await _context.SaveChangesAsync();

                _logger.LogCritical($"User '{User.Identity.Name}' deleted '{Message.ToString()}'.");
            }

            return(RedirectToPage("./Index"));
        }
예제 #11
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Message).State = EntityState.Modified;

            try
            {
                // Bible reference handling
                {
                    var newReferences             = Message.BibleReferences.Where(x => x.Id == 0);
                    var existingMessageReferences = Message.BibleReferences.Where(x => x.Id != 0);
                    var existingDbReferences      = await _context.BibleReferences.Where(x => x.MessageId == Message.Id).ToListAsync();

                    // Remove references that are no longer present
                    foreach (var reference in existingDbReferences)
                    {
                        if (!newReferences.Any(x => ReferenceCompare(x, reference)))
                        {
                            Message.BibleReferences.RemoveAll(x => ReferenceCompare(x, reference));
                            _context.BibleReferences.RemoveRange(_context.BibleReferences.Where(x => x.Id == reference.Id));
                        }
                    }

                    // Add new references
                    var referencesToRemove = new List <BibleReferenceRange>();
                    foreach (var reference in newReferences)
                    {
                        if (existingMessageReferences.Any(x => ReferenceCompare(x, reference)))
                        {
                            referencesToRemove.Add(reference);
                        }
                        if (!existingDbReferences.Any(x => ReferenceCompare(x, reference)))
                        {
                            _context.BibleReferences.Add(reference);
                        }
                    }
                    foreach (var reference in referencesToRemove)
                    {
                        Message.BibleReferences.Remove(reference);
                    }
                }

                await _context.SaveChangesAsync();

                _logger.LogCritical($"User '{User.Identity.Name}' edited object with new values'{Message.ToString()}'.");
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MessageExists(Message.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }