コード例 #1
0
        protected void Notify(UserAccount existingUser, Group existingGroup, string Message)
        {
            var NotificationBox = _notificationBox.GetNotificationBoxByUserId(existingUser.UserId);

            _notificationBox.SendNotifcation(new Notification()
            {
                NotificationBoxId = NotificationBox.Id,
                RecieverUsername  = existingUser.Username,
                NotificationDate  = DateTime.Now,
                Message           = Message
            });
            _context.SaveChanges();
        }
コード例 #2
0
 public IActionResult GrantAdminAccess(AccountDTO accountDTO)
 {
     try
     {
         var existingAccount = _userStore.GetById(accountDTO.Id);
         _userStore.GrantAdmin(existingAccount);
         var Notification = new Notification()
         {
             Message           = "You have been granted Admin access ",
             NotificationBoxId = _notificationBox.GetNotificationBoxByUserId(existingAccount.UserId).Id,
             RecieverUsername  = _userStore.GetByIdentityUserId(existingAccount.UserId).Username,
             NotificationDate  = DateTime.Now
         };
         _notificationBox.SendNotifcation(Notification);
         _context.SaveChanges();
         return(RedirectToAction("AdminPortal"));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(RedirectToAction(ActionName.ServerError));
     }
 }
コード例 #3
0
        public IActionResult Delete(Post Post)
        {
            try
            {
                var CurrentUser     = _context.Users.Find(userManager.GetUserId(User));
                var existingAccount = _userStore.GetByIdentityUserId(CurrentUser.Id);

                if (existingAccount.AccountStatus.Equals(Status.Suspended))
                {
                    signInManager.SignOutAsync();
                }

                var existingPost = _postStore.GetById(Post.Id);


                if (existingPost.UserId != CurrentUser.Id)
                {
                    var Notification = new Notification()
                    {
                        Message           = $"Your post '{existingPost.Content}' was deleted," + " " + "It may have violated community guidlines.",
                        NotificationBoxId = _notificationBox.GetNotificationBoxByUserId(existingPost.UserId).Id,
                        RecieverUsername  = _userStore.GetByIdentityUserId(existingPost.UserId).Username,
                        NotificationDate  = DateTime.Now
                    };
                    _notificationBox.SendNotifcation(Notification);
                    _context.SaveChanges();
                }
                _postStore.DeletePost(existingPost);
                return(RedirectToAction("AllPosts"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(RedirectToAction(ActionName.ServerError, ControllerName.Accounts));
            }
        }