/// <summary> /// modify a suggestion for poets spec lines /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <RServiceResult <bool> > ModifyPoetSuggestedSpecLinesAsync(GanjoorPoetSuggestedSpecLineViewModel model) { try { var dbModel = await _context.GanjoorPoetSuggestedSpecLines.Where(s => s.Id == model.Id).SingleAsync(); bool publishIsChanged = model.Published != dbModel.Published; dbModel.LineOrder = model.LineOrder; dbModel.Contents = model.Contents; 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} مورد پذیرش قرار گرفت. پیشنها شما: {Environment.NewLine}" + $"{model.Contents}" ); } return(new RServiceResult <bool>(true)); } catch (Exception exp) { return(new RServiceResult <bool>(false, exp.ToString())); } }
public async Task <IActionResult> ModifyPoetSuggestedSpecLinesAsync([FromBody] GanjoorPoetSuggestedSpecLineViewModel spec) { var res = await _ganjoorService.ModifyPoetSuggestedSpecLinesAsync(spec); if (!string.IsNullOrEmpty(res.ExceptionString)) { return(BadRequest(res.ExceptionString)); } return(Ok(res.Result)); }
public async Task <IActionResult> AddPoetSuggestedSpecLinesAsync([FromBody] GanjoorPoetSuggestedSpecLineViewModel spec) { spec.SuggestedById = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); var res = await _ganjoorService.AddPoetSuggestedSpecLinesAsync(spec); if (!string.IsNullOrEmpty(res.ExceptionString)) { return(BadRequest(res.ExceptionString)); } return(Ok(res.Result)); }
/// <summary> /// add a suggestion for poets spec lines /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <RServiceResult <GanjoorPoetSuggestedSpecLineViewModel> > AddPoetSuggestedSpecLinesAsync(GanjoorPoetSuggestedSpecLineViewModel model) { try { var dbModel = new GanjoorPoetSuggestedSpecLine() { PoetId = model.PoetId, Contents = model.Contents, Published = false, SuggestedById = model.SuggestedById, }; dbModel.LineOrder = await _context.GanjoorPoetSuggestedSpecLines.Where(s => s.PoetId == model.PoetId).CountAsync() + 1; _context.Add(dbModel); await _context.SaveChangesAsync(); model.Published = false; model.Id = dbModel.Id; 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 == model.PoetId).SingleAsync(); foreach (var moderator in moderators.Result) { await _notificationService.PushNotification ( (Guid)moderator.Id, "ثبت مشخصات جدید برای شاعر", $"درخواستی برای ثبت مشخصات جدید برای «{poet.Nickname}» ثبت شده است. در صورت تمایل به بررسی، بخش مربوط به شاعر را <a href=\"/User/SuggestedPoetSpecLines\">اینجا</a> ببینید.{ Environment.NewLine}" + $"توجه فرمایید که اگر کاربر دیگری که دارای مجوز بررسی مشخصات است پیش از شما به آن رسیدگی کرده باشد آن را در صف نخواهید دید." ); } } return(new RServiceResult <GanjoorPoetSuggestedSpecLineViewModel>(model)); } catch (Exception exp) { return(new RServiceResult <GanjoorPoetSuggestedSpecLineViewModel>(null, exp.ToString())); } }