public async Task <IActionResult> Patch([FromBody] Tag value) { Tag Tag = await _context.Tag.FindAsync(value.ID); if (Tag == null) { return(NotFound()); } if (value.Category != null) { Tag.Category = value.Category; } if (value.TagName != null) { Tag.TagName = value.TagName; } _context.Attach(Tag).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(Conflict()); } return(Ok("{}")); }
public async Task <IActionResult> Patch([FromBody] Mini value) { Mini Mini = await _context.Mini .Include(m => m.MiniTags) .FirstOrDefaultAsync(m => m.ID == value.ID); if (Mini == null) { return(NotFound()); } if (value.Status == Status.Approved) { Mini.Status = Status.Approved; Mini.ApprovedTime = DateTime.Now; foreach (MiniTag mt in Mini.MiniTags) { if (mt.Status == Status.Pending) { mt.Status = Status.Approved; mt.ApprovedTime = DateTime.Now; mt.LastModifiedTime = DateTime.Now; _context.Attach(mt).State = EntityState.Modified; } } } else { Mini.Status = value.Status; } _context.Attach(Mini).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(Ok(Mini.ID)); }
public async Task <IActionResult> Patch([FromBody] MiniTag value) { MiniTag MiniTag = await _context.MiniTag.FindAsync(value.MiniID, value.TagID); if (MiniTag == null) { return(NotFound()); } MiniTag.Status = value.Status; MiniTag.LastModifiedTime = DateTime.Now; _context.Attach(MiniTag).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(Conflict()); } return(Ok("{}")); }
public async Task <Mini> Handle(MiniSubmissionRequest request, CancellationToken cancellationToken) { //TODO - This should look at MiniSourceSite, not m.Link. Mini mini = await _context.Mini.TagWith("MiniSubmissionHandler.cs 1").FirstOrDefaultAsync(m => m.Link == request.Url.ToString(), cancellationToken); IParser parser = _parsers.FirstOrDefault(p => p.CanParse(request.Url)); if (parser is null) { //valid URL, but not currently supported //TODO: log when this happens? return(null); } if (mini != null) { if (request.JustThumbnail) { Mini updatedMini = await parser.ParseFromUrl(request.Url); mini.Thumbnail = updatedMini.Thumbnail; _context.Attach(mini).State = EntityState.Modified; await UploadThumbnail(mini); } return(mini); } mini = await parser.ParseFromUrl(request.Url); //TODO - This should look at MiniSourceSite, not m.Link. //Now that we've parsed it, check if the parsed URL is different from the original URL and if we have that. Mini checkDupe = await _context.Mini.FirstOrDefaultAsync(m => m.Link == mini.Link, cancellationToken); if (checkDupe != null) { if (request.JustThumbnail) { checkDupe.Thumbnail = mini.Thumbnail; _context.Attach(mini).State = EntityState.Modified; await UploadThumbnail(checkDupe); } return(checkDupe); } if (!request.JustThumbnail) { mini.User = request.User; mini.Status = Status.Unindexed; _context.Add(mini); await CorrectMiniCreator(mini, cancellationToken); //TODO - Another dupe check here based on name and creator await _context.SaveChangesAsync(); } await UploadThumbnail(mini); return(mini); }