diff --git a/RMuseum/Services/IPoetPhotoSuggestionService.cs b/RMuseum/Services/IPoetPhotoSuggestionService.cs index c7e7bd7b..3ed4d7df 100644 --- a/RMuseum/Services/IPoetPhotoSuggestionService.cs +++ b/RMuseum/Services/IPoetPhotoSuggestionService.cs @@ -41,7 +41,22 @@ namespace RMuseum.Services /// unpublished suggested photos count for poets /// /// - Task> GetNextUnmoderatedPoetSuggestedSpecLinesCountAsync(); + Task> GetNextUnmoderatedPoetSuggestedPhotosCountAsync(); + + /// + /// modify a suggested photo for poets + /// + /// + /// + Task> ModifyPoetSuggestedPhotoAsync(GanjoorPoetSuggestedPictureViewModel model); + + /// + /// delete a suggested photo for poets + /// + /// + /// + /// + Task> DeletePoetSuggestedPhotoAsync(int id, Guid deleteUserId); } diff --git a/RMuseum/Services/Implementation/PoetPhotoSuggestionService.cs b/RMuseum/Services/Implementation/PoetPhotoSuggestionService.cs index 2aa97e7b..ab66f33c 100644 --- a/RMuseum/Services/Implementation/PoetPhotoSuggestionService.cs +++ b/RMuseum/Services/Implementation/PoetPhotoSuggestionService.cs @@ -175,7 +175,7 @@ namespace RMuseum.Services.Implementation /// unpublished suggested photos count for poets /// /// - public async Task> GetNextUnmoderatedPoetSuggestedSpecLinesCountAsync() + public async Task> GetNextUnmoderatedPoetSuggestedPhotosCountAsync() { try { @@ -195,6 +195,78 @@ namespace RMuseum.Services.Implementation } } + /// + /// modify a suggested photo for poets + /// + /// + /// + public async Task> ModifyPoetSuggestedPhotoAsync(GanjoorPoetSuggestedPictureViewModel model) + { + try + { + + var dbModel = await _context.GanjoorPoetSuggestedPictures.Include(p => p.Picture).Where(s => s.Id == model.Id).SingleAsync(); + bool publishIsChanged = model.Published != dbModel.Published; + dbModel.PicOrder = model.PicOrder; + dbModel.Picture.Title = model.Title; + dbModel.Picture.Description = model.Description; + dbModel.ChosenOne = model.ChosenOne; + dbModel.Published = model.Published; + _context.Update(dbModel); + await _context.SaveChangesAsync(); + + if (publishIsChanged && model.Published && dbModel.SuggestedById != null) + { + var userRes = await _appUserService.GetUserInformation((Guid)dbModel.SuggestedById); + var poet = await _context.GanjoorPoets.AsNoTracking().Where(p => p.Id == dbModel.PoetId).SingleAsync(); + await _notificationService.PushNotification((Guid)dbModel.SuggestedById, + $"انتشار تصویر پیشنهادی شما برای {poet.Nickname}", + $"با سپاس! پیشنهاد شما برای تصویر {poet.Nickname} در فهرست تصاویر قابل انتخاب برای شاعر قابل مشاهده است." + ); + } + + return new RServiceResult(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + + /// + /// delete a suggested photo for poets + /// + /// + /// + /// + public async Task> DeletePoetSuggestedPhotoAsync(int id, Guid deleteUserId) + { + try + { + var dbModel = await _context.GanjoorPoetSuggestedPictures.Where(s => s.Id == id).SingleAsync(); + + + if (!dbModel.Published && dbModel.SuggestedById != null && deleteUserId != dbModel.SuggestedById) + { + var userRes = await _appUserService.GetUserInformation((Guid)dbModel.SuggestedById); + var poet = await _context.GanjoorPoets.AsNoTracking().Where(p => p.Id == dbModel.PoetId).SingleAsync(); + await _notificationService.PushNotification((Guid)dbModel.SuggestedById, + $"عدم پذیرش تصویر ارسالی شما برای {poet.Nickname}", + $"متأسفانه تصویر پیشنهادی شما برای مشخصات {poet.Nickname} مورد پذیرش قرار نگرفت" + ); + } + + _context.Remove(dbModel); + await _context.SaveChangesAsync(); + + return new RServiceResult(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + /// /// Database Context