Пример #1
0
        public async Task <IActionResult> Delete([FromBody] MiniTag value)
        {
            //TODO: Propagate deletion to paired tags. Possibly with a new state for "Autoadded"
            MiniTag MiniTag = await _context.MiniTag.FindAsync(value.Mini.ID, value.Tag.ID);

            if (User.IsInRole("Moderator"))
            {
                _context.Remove(MiniTag);
            }
            else
            {
                MiniTag.Status                 = Status.Deleted;
                MiniTag.LastModifiedTime       = DateTime.Now;
                _context.Attach(MiniTag).State = EntityState.Modified;
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Conflict());
            }
            return(Ok("{}"));
        }
        private async Task CorrectMiniCreator(Mini mini, CancellationToken cancellationToken)
        {
            MiniSourceSite currentSource = mini.Sources.Single();

            //Find a SourceSite that has both the same UserName and SiteName as the Mini's current
            SourceSite matchingSource = await _context.Set <SourceSite>().TagWith("MiniSubmissionHandler.cs 2")
                                        .Include(s => s.Creator).ThenInclude(c => c.Sites)
                                        .FirstOrDefaultAsync((s => s.CreatorUserName == currentSource.Site.CreatorUserName && s.SiteName == currentSource.Site.SiteName), cancellationToken);

            Creator foundCreator = matchingSource?.Creator;

            if (foundCreator != null)
            {
                _context.Remove(mini.Creator);
                mini.Creator = foundCreator;

                _context.Remove(currentSource.Site);
                currentSource.Site = matchingSource;

                return;
            }

            //If we didn't find a "perfect" match, try matching just off of the creator's names
            foundCreator = await _context.Set <Creator>().TagWith("MiniSubmissionHandler.cs 3")
                           .Include(c => c.Sites)
                           .FirstOrDefaultAsync(c => c.Name == mini.Creator.Name, cancellationToken);

            if (foundCreator != null)
            {
                mini.Creator = foundCreator;

                if (!foundCreator.Sites.Any(s => s.SiteName == currentSource.Site.SiteName))
                {
                    foundCreator.Sites.Add(currentSource.Site);
                }
            }
        }
Пример #3
0
        public async Task <IActionResult> Delete(int id)
        {
            //TODO: Delete MiniTags too? Maybe only work if there's no approved MiniTags
            Tag Tag = await _context.Tag.FindAsync(id);

            _context.Remove(Tag);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Conflict());
            }

            return(Ok("{}"));
        }