#421 geo tag moderation
This commit is contained in:
parent
42c4961c82
commit
de279b75fd
@ -31,7 +31,7 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
try
|
||||
{
|
||||
var dbCorrection = await _context.GanjoorPoemCorrections.Include(c => c.VerseOrderText).Include(c => c.User)
|
||||
var dbCorrection = await _context.GanjoorPoemCorrections.Include(c => c.VerseOrderText).Include(c => c.GeoDateTags).Include(c => c.User)
|
||||
.Where(c => c.Id == moderation.Id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
@ -661,6 +661,74 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
if (dbCorrection.GeoDateTags != null && dbCorrection.GeoDateTags.Any())
|
||||
{
|
||||
foreach (var dbGeoDateTag in dbCorrection.GeoDateTags)
|
||||
{
|
||||
var moderatedTag = moderation.GeoDateTags?.FirstOrDefault(g => g.Id == dbGeoDateTag.Id);
|
||||
if (moderatedTag == null || moderatedTag.Result == CorrectionReviewResult.NotReviewed)
|
||||
{
|
||||
return new RServiceResult<GanjoorPoemCorrectionViewModel>(null, "همهٔ برچسبهای جغرافیایی/تاریخی پیشنهادی باید بررسی شوند.");
|
||||
}
|
||||
|
||||
dbGeoDateTag.Result = moderatedTag.Result;
|
||||
dbGeoDateTag.ReviewNote = moderatedTag.ReviewNote;
|
||||
|
||||
if (moderatedTag.Result == CorrectionReviewResult.Approved)
|
||||
{
|
||||
dbCorrection.AffectedThePoem = true;
|
||||
|
||||
if (dbGeoDateTag.MarkForDelete)
|
||||
{
|
||||
// approving a delete-suggestion removes the existing, already-approved tag it targets
|
||||
if (dbGeoDateTag.ExistingTagId != null)
|
||||
{
|
||||
var existingTag = await _context.PoemGeoDateTags.Where(t => t.Id == dbGeoDateTag.ExistingTagId).SingleOrDefaultAsync();
|
||||
if (existingTag != null)
|
||||
{
|
||||
_context.PoemGeoDateTags.Remove(existingTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int? approvedLocationId = dbGeoDateTag.LocationId;
|
||||
if (approvedLocationId == null && !string.IsNullOrWhiteSpace(dbGeoDateTag.SuggestedLocationName)
|
||||
&& dbGeoDateTag.SuggestedLatitude != null && dbGeoDateTag.SuggestedLongitude != null)
|
||||
{
|
||||
// a brand new, not-yet-catalogued location - create it so the new PoemGeoDateTag can reference it
|
||||
var newLocation = new GanjoorGeoLocation()
|
||||
{
|
||||
Name = dbGeoDateTag.SuggestedLocationName.Trim(),
|
||||
Latitude = (double)dbGeoDateTag.SuggestedLatitude,
|
||||
Longitude = (double)dbGeoDateTag.SuggestedLongitude,
|
||||
};
|
||||
_context.GanjoorGeoLocations.Add(newLocation);
|
||||
await _context.SaveChangesAsync(); // need its Id below
|
||||
approvedLocationId = newLocation.Id;
|
||||
}
|
||||
|
||||
var newTag = new PoemGeoDateTag()
|
||||
{
|
||||
PoemId = dbCorrection.PoemId,
|
||||
// PoemGeoDateTag.CoupletIndex uses 0 for "whole poem", matching a null CoupletIndex here
|
||||
CoupletIndex = dbGeoDateTag.CoupletIndex ?? 0,
|
||||
LocationId = approvedLocationId,
|
||||
LunarYear = dbGeoDateTag.LunarYear,
|
||||
LunarMonth = dbGeoDateTag.LunarMonth,
|
||||
LunarDay = dbGeoDateTag.LunarDay,
|
||||
PersonId = dbGeoDateTag.PersonId,
|
||||
IgnoreInCategory = dbGeoDateTag.IgnoreInCategory,
|
||||
VerifiedDate = false,
|
||||
MachineGenerated = false,
|
||||
};
|
||||
newTag.LunarDateTotalNumber = _PrepareLunarDateTotalNumber(newTag);
|
||||
_context.PoemGeoDateTags.Add(newTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (updatePoem)
|
||||
{
|
||||
_context.Update(dbPoem);
|
||||
|
||||
@ -2330,7 +2330,7 @@ namespace RMuseum.Services.Implementation
|
||||
public async Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCorrectionViewModel[] Items)>> GetPoemEffectiveCorrections(int poemId, PagingParameterModel paging)
|
||||
{
|
||||
var source = from dbCorrection in
|
||||
_context.GanjoorPoemCorrections.AsNoTracking().Include(c => c.VerseOrderText)
|
||||
_context.GanjoorPoemCorrections.AsNoTracking().Include(c => c.VerseOrderText).Include(c => c.GeoDateTags)
|
||||
where
|
||||
dbCorrection.PoemId == poemId
|
||||
&&
|
||||
@ -2357,6 +2357,8 @@ namespace RMuseum.Services.Implementation
|
||||
||
|
||||
v.LanguageReviewResult == CorrectionReviewResult.Approved
|
||||
)
|
||||
||
|
||||
dbCorrection.GeoDateTags.Any(g => g.Result == CorrectionReviewResult.Approved)
|
||||
)
|
||||
orderby dbCorrection.Id descending
|
||||
select
|
||||
@ -2399,6 +2401,7 @@ namespace RMuseum.Services.Implementation
|
||||
PoemFormat = dbCorrection.PoemFormat,
|
||||
OriginalPoemFormat = dbCorrection.OriginalPoemFormat,
|
||||
PoemFormatReviewResult = dbCorrection.PoemFormatReviewResult,
|
||||
GeoDateTags = dbCorrection.GeoDateTags == null ? null : dbCorrection.GeoDateTags.ToArray(),
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -2414,7 +2417,7 @@ namespace RMuseum.Services.Implementation
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorPoemCorrectionViewModel>> GetCorrectionById(int id)
|
||||
{
|
||||
var dbCorrection = await _context.GanjoorPoemCorrections.AsNoTracking().Include(c => c.VerseOrderText).Include(c => c.User)
|
||||
var dbCorrection = await _context.GanjoorPoemCorrections.AsNoTracking().Include(c => c.VerseOrderText).Include(c => c.GeoDateTags).Include(c => c.User)
|
||||
.Where(c => c.Id == id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
@ -2454,6 +2457,7 @@ namespace RMuseum.Services.Implementation
|
||||
OriginalPoemFormat = dbCorrection.OriginalPoemFormat,
|
||||
PoemFormatReviewResult = dbCorrection.PoemFormatReviewResult,
|
||||
HideMyName = dbCorrection.HideMyName,
|
||||
GeoDateTags = dbCorrection.GeoDateTags == null ? null : dbCorrection.GeoDateTags.ToArray(),
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -2470,7 +2474,7 @@ namespace RMuseum.Services.Implementation
|
||||
var systemUser = await _appUserService.FindUserByEmail(systemEmail);
|
||||
var systemUserId = systemUser.Result == null ? Guid.Empty : (Guid)systemUser.Result.Id;
|
||||
|
||||
var dbCorrection = await _context.GanjoorPoemCorrections.AsNoTracking().Include(c => c.VerseOrderText).Include(c => c.User)
|
||||
var dbCorrection = await _context.GanjoorPoemCorrections.AsNoTracking().Include(c => c.VerseOrderText).Include(c => c.GeoDateTags).Include(c => c.User)
|
||||
.Where(c => c.Reviewed == false && (onlyUserCorrections == false || c.UserId != systemUserId))
|
||||
.OrderBy(c => c.Id)
|
||||
.Skip(skip)
|
||||
@ -2512,6 +2516,7 @@ namespace RMuseum.Services.Implementation
|
||||
OriginalPoemFormat = dbCorrection.OriginalPoemFormat,
|
||||
PoemFormatReviewResult = dbCorrection.PoemFormatReviewResult,
|
||||
HideMyName = dbCorrection.HideMyName,
|
||||
GeoDateTags = dbCorrection.GeoDateTags == null ? null : dbCorrection.GeoDateTags.ToArray(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user