Beispiel #1
0
        public ActionResult MarkAsReadNotification(string id, AddViewNotificationViewModel vModel)
        {
            string          message    = string.Empty;
            string          userId     = User.Identity.GetUserId();
            ApplicationUser authedUser = UserManager.FindById(userId);

            try
            {
                if (!string.IsNullOrWhiteSpace(id))
                {
                    IPlayerMessage notification = ConfigDataCache.Get <IPlayerMessage>(id);

                    if (notification != null)
                    {
                        notification.Read = true;
                        notification.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                    }
                }
                else
                {
                    message = "Invalid message.";
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex, LogChannels.SystemWarnings);
            }

            return(RedirectToAction("Notifications", new { Message = message }));
        }
Beispiel #2
0
        public ActionResult AddViewNotification(string id)
        {
            string userId = User.Identity.GetUserId();
            AddViewNotificationViewModel model = new AddViewNotificationViewModel
            {
                AuthedUser = UserManager.FindById(userId)
            };

            if (!string.IsNullOrWhiteSpace(id))
            {
                IPlayerMessage message = ConfigDataCache.Get <IPlayerMessage>(id);

                if (message != null)
                {
                    model.DataObject = message;
                    model.Body       = message.Body;
                    model.Recipient  = message.RecipientName;
                    model.Subject    = message.Subject;
                }
            }

            return(View(model));
        }
Beispiel #3
0
        public ActionResult AddViewNotification(AddViewNotificationViewModel vModel)
        {
            string          message    = string.Empty;
            string          userId     = User.Identity.GetUserId();
            ApplicationUser authedUser = UserManager.FindById(userId);

            try
            {
                if (string.IsNullOrWhiteSpace(vModel.Body) || string.IsNullOrWhiteSpace(vModel.Subject))
                {
                    message = "You must include a valid body and subject.";
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(vModel.RecipientAccount))
                    {
                        message = "You must include a valid recipient.";
                    }
                    else
                    {
                        IAccount recipient = Account.GetByHandle(vModel.RecipientAccount);

                        if (recipient == null || recipient.Config.Acquaintences.Any(acq => acq.IsFriend == false && acq.PersonHandle.Equals(authedUser.GameAccount.GlobalIdentityHandle)))
                        {
                            message = "You must include a valid recipient.";
                        }
                        else
                        {
                            PlayerMessage newMessage = new PlayerMessage
                            {
                                Body             = vModel.Body,
                                Subject          = vModel.Subject,
                                Sender           = authedUser.GameAccount,
                                RecipientAccount = recipient
                            };

                            IPlayerTemplate recipientCharacter = TemplateCache.GetByName <IPlayerTemplate>(vModel.Recipient);

                            if (recipientCharacter != null)
                            {
                                newMessage.Recipient = recipientCharacter;
                            }

                            //messages come from players always here
                            if (newMessage.Save(authedUser.GameAccount, StaffRank.Player))
                            {
                                message = "Successfully sent.";
                            }
                            else
                            {
                                LoggingUtility.Log("Message unsuccessful.", LogChannels.SystemWarnings);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex, LogChannels.SystemWarnings);
            }

            return(RedirectToAction("Notifications", new { Message = message }));
        }