public IActionResult Index(UserNotifyQueryDto model, [FromQuery(Name = "direction")] string direction) { ModelState.Clear(); if (direction == "pre" && model.Paging.PageNo > 1) { model.Paging.PageNo -= 1; } if (direction == "next") { model.Paging.PageNo += 1; } var result = new UserNotifyRepo(db).QueryWithPaging(model.Id, model.Content, model.StatusId, model.StartDate, model.EndDate, model.Paging); if (result != null) { model.Paging.Count = new UserNotifyRepo(db).GetCount(model.Id, model.Content, model.StatusId, model.StartDate, model.EndDate); } else { model.Paging.Count = 0; } model.Statuses = new CommonCodeRepo(db).GetCodesByType("UserInstructStatus"); model.Results = result; return(View(model)); }
public string PostNotify(int id) { var currentRoleId = partnerManager.GetCurrentUserRole(this.HttpContext); var currentAccount = partnerManager.GetCurrentUserAccount(this.HttpContext); var permission = partnerActivity.GetPartAct("UserNotify.Post", currentRoleId); if (permission == null) { toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions { Title = "" }); //return Redirect(Request.Headers["Referer"].ToString()); } else { var result = new UserNotifyRepo(db).Post(id, permission.Scope.Id, currentAccount); if (result.Success) { toastNotification.AddSuccessToastMessage("تم ترحيل التعميم على كافة المستخدمين", new ToastrOptions { Title = "" }); return("suceess"); } } return("failed"); }
public string delete(int id) { var result = new UserNotifyRepo(db).Delete(id); if (result > 0) { return("suceess"); } return("failed"); }
public IActionResult Create(UserNotifyDto model) { var currentRoleId = partnerManager.GetCurrentUserRole(this.HttpContext); var permission = partnerActivity.GetPartAct("UserNotify.Create", currentRoleId); if (permission == null) { toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions { Title = "" }); return(Redirect(Request.Headers["Referer"].ToString())); } if (model.Id > 0) { toastNotification.AddErrorToastMessage("تم الحفظ مسبقا", new ToastrOptions { Title = "" }); return(Redirect(Request.Headers["Referer"].ToString())); } if (ModelState.IsValid) { var created = new UserNotify(); created.Content = model.Content; created.Subject = model.Subject; created.ExpireOn = model.ExpireOn; created.Priority.Id = model.PriorityId; created.CreatedBy.Id = partnerManager.GetCurrentUserId(this.HttpContext); created.CreatedBy.Account = partnerManager.GetCurrentUserAccount(this.HttpContext); if (!string.IsNullOrEmpty(model.SelectedRoles)) { var roles = model.SelectedRoles.Split(','); foreach (string item in roles) { var notifyTo = new UserNotifyTo(); notifyTo.Role.Id = int.Parse(item); created.NotifyToList.Add(notifyTo); } } var result = new UserNotifyRepo(db).Create(created); if (result.AffectedCount > 0) { toastNotification.AddSuccessToastMessage("تم اضافة التعميم بنجاح", new ToastrOptions { Title = "" }); ModelState.Clear(); model.Id = result.AffectedCount; } } model.Priorities = new CommonCodeRepo(db).GetCodesByType("priority"); model.Roles = new RoleRepo(db, partnerActivity).GetAuthorizedRoles("UserNotify.Create", currentRoleId); return(View(model)); }
public async Task NotifyUsers(IEnumerable <RequestedModel> modelChanged, string apiKey) { try { var plexUser = PlexApi.GetUsers(apiKey); var userAccount = PlexApi.GetAccount(apiKey); var adminUsername = userAccount.Username ?? string.Empty; var users = UserNotifyRepo.GetAll().ToList(); Log.Debug("Notifying Users Count {0}", users.Count); foreach (var model in modelChanged) { var selectedUsers = users.Select(x => x.Username).Intersect(model.RequestedUsers, StringComparer.CurrentCultureIgnoreCase); foreach (var user in selectedUsers) { Log.Info("Notifying user {0}", user); if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase)) { Log.Info("This user is the Plex server owner"); await PublishUserNotification(userAccount.Username, userAccount.Email, model.Title, model.PosterPath); return; } var email = plexUser.User.FirstOrDefault(x => x.Username.Equals(user, StringComparison.CurrentCultureIgnoreCase)); if (email == null) { Log.Info("There is no email address for this Plex user, cannot send notification"); // We do not have a plex user that requested this! continue; } Log.Info("Sending notification to: {0} at: {1}, for title: {2}", email.Username, email.Email, model.Title); await PublishUserNotification(email.Username, email.Email, model.Title, model.PosterPath); } } } catch (Exception e) { Log.Error(e); } }