diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index dda8416a..14c48f9f 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -13091,6 +13091,13 @@ poet photo suggestion service + + + return list of suggested photos for a poet + + + + suggest a new photo for a poet @@ -13127,12 +13134,24 @@ picture file service - + + + Messaging service + + + + + IAppUserService instance + + + constructor + + @@ -13728,9 +13747,16 @@ - poet photo suggestion service + poet photo suggestion service; + + + return list of suggested photos for a poet + + + + suggest a new photo for a poet diff --git a/RMuseum/Services/IPoetPhotoSuggestionService.cs b/RMuseum/Services/IPoetPhotoSuggestionService.cs index 3084d284..c7e7bd7b 100644 --- a/RMuseum/Services/IPoetPhotoSuggestionService.cs +++ b/RMuseum/Services/IPoetPhotoSuggestionService.cs @@ -7,10 +7,16 @@ using System.Threading.Tasks; namespace RMuseum.Services { /// - /// poet photo suggestion service + /// poet photo suggestion service; /// public interface IPoetPhotoSuggestionService { + /// + /// return list of suggested photos for a poet + /// + /// + /// + Task> GetPoetSuggestedPhotosAsync(int poetId); /// /// suggest a new photo for a poet /// diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PhotosProject.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PhotosProject.cs index c46ce1c5..3ea60d0b 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PhotosProject.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PhotosProject.cs @@ -27,7 +27,7 @@ namespace RMuseum.Services.Implementation { return new RServiceResult ( - await _context.GanjoorPoetSuggestedSpecLines + await _context.GanjoorPoetSuggestedSpecLines.AsNoTracking() .Where ( r => r.PoetId == poetId @@ -63,7 +63,7 @@ namespace RMuseum.Services.Implementation return new RServiceResult ( - await _context.GanjoorPoetSuggestedSpecLines + await _context.GanjoorPoetSuggestedSpecLines.AsNoTracking() .Where ( r => r.Id == id @@ -99,7 +99,7 @@ namespace RMuseum.Services.Implementation { return new RServiceResult ( - await _context.GanjoorPoetSuggestedSpecLines + await _context.GanjoorPoetSuggestedSpecLines.AsNoTracking() .Where ( r => r.Published == false @@ -181,7 +181,7 @@ namespace RMuseum.Services.Implementation ( (Guid)moderator.Id, "ثبت مشخصات جدید برای شاعر", - $"درخواستی برای ثبت مشخصات جدید برای «{poet.Nickname}» ثبت شده است. در صورت تمایل به بررسی، بخش مربوط به شاعر را اینجا ببینید.{ Environment.NewLine}" + + $"درخواستی برای ثبت مشخصات جدید برای «{poet.Nickname}» ثبت شده است. در صورت تمایل به بررسی، بخش مربوط به شاعر را اینجا ببینید.{ Environment.NewLine}" + $"توجه فرمایید که اگر کاربر دیگری که دارای مجوز بررسی مشخصات است پیش از شما به آن رسیدگی کرده باشد آن را در صف نخواهید دید." ); } diff --git a/RMuseum/Services/Implementation/PoetPhotoSuggestionService.cs b/RMuseum/Services/Implementation/PoetPhotoSuggestionService.cs index 1b8f230b..2aa97e7b 100644 --- a/RMuseum/Services/Implementation/PoetPhotoSuggestionService.cs +++ b/RMuseum/Services/Implementation/PoetPhotoSuggestionService.cs @@ -1,9 +1,11 @@ using Microsoft.EntityFrameworkCore; using RMuseum.DbContext; using RMuseum.Models.Artifact; +using RMuseum.Models.Auth.Memory; using RMuseum.Models.Ganjoor; using RMuseum.Models.Ganjoor.ViewModels; using RSecurityBackend.Models.Generic; +using RSecurityBackend.Services; using System; using System.IO; using System.Linq; @@ -16,6 +18,41 @@ namespace RMuseum.Services.Implementation /// public class PoetPhotoSuggestionService : IPoetPhotoSuggestionService { + /// + /// return list of suggested photos for a poet + /// + /// + /// + public async Task> GetPoetSuggestedPhotosAsync(int poetId) + { + return new RServiceResult + ( + await _context.GanjoorPoetSuggestedPictures.AsNoTracking().Include(r => r.Picture) + .Where + ( + r => r.Published == true && r.PoetId == poetId + ) + .OrderBy(r => r.PicOrder) + .Select + ( + r => new GanjoorPoetSuggestedPictureViewModel() + { + Id = r.Id, + PoetId = r.PoetId, + Title = r.Picture.Title, + Description = r.Picture.Description, + PicOrder = r.PicOrder, + Published = r.Published, + ChosenOne = r.ChosenOne, + SuggestedById = r.SuggestedById, + ImageUrl = $"api/rimages/{r.PictureId}.jpg" + } + ) + .ToArrayAsync() + ); + } + + /// /// suggest a new photo for a poet /// @@ -55,6 +92,22 @@ namespace RMuseum.Services.Implementation _context.GanjoorPoetSuggestedPictures.Add(picture); await _context.SaveChangesAsync(); + var moderators = await _appUserService.GetUsersHavingPermission(RMuseumSecurableItem.GanjoorEntityShortName, RMuseumSecurableItem.ModeratePoetPhotos); + if (string.IsNullOrEmpty(moderators.ExceptionString)) //if not, do nothing! + { + var poet = await _context.GanjoorPoets.AsNoTracking().Where(p => p.Id == poetId).SingleAsync(); + foreach (var moderator in moderators.Result) + { + await _notificationService.PushNotification + ( + (Guid)moderator.Id, + "ثبت تصویر پیشنهادی جدید برای شاعر", + $"درخواستی برای ثبت تصویر پیشنهادی جدیدی برای «{poet.Nickname}» ثبت شده است. در صورت تمایل به بررسی، بخش مربوط به شاعر را اینجا ببینید.{ Environment.NewLine}" + + $"توجه فرمایید که اگر کاربر دیگری که دارای مجوز بررسی تصاویر است پیش از شما به آن رسیدگی کرده باشد آن را در صف نخواهید دید." + ); + } + } + return new RServiceResult ( @@ -89,7 +142,7 @@ namespace RMuseum.Services.Implementation { return new RServiceResult ( - await _context.GanjoorPoetSuggestedPictures.Include(r => r.Picture) + await _context.GanjoorPoetSuggestedPictures.AsNoTracking().Include(r => r.Picture) .Where ( r => r.Published == false @@ -152,17 +205,31 @@ namespace RMuseum.Services.Implementation /// picture file service /// - protected IPictureFileService _pictureFileService; + protected readonly IPictureFileService _pictureFileService; + + /// + /// Messaging service + /// + protected readonly IRNotificationService _notificationService; + + /// + /// IAppUserService instance + /// + protected readonly IAppUserService _appUserService; /// /// constructor /// /// /// - public PoetPhotoSuggestionService(RMuseumDbContext context, IPictureFileService pictureFileService) + /// + /// + public PoetPhotoSuggestionService(RMuseumDbContext context, IPictureFileService pictureFileService, IRNotificationService notificationService, IAppUserService appUserService) { _context = context; _pictureFileService = pictureFileService; + _notificationService = notificationService; + _appUserService = appUserService; } } }