Beispiel #1
0
        public JsonResult AddMessageNew(string AcceptIDS, string Title, string Content)
        {
            AjaxResult result = new AjaxResult();
            Message    msg    = new Message();

            msg.Content = Content;
            msg.Title   = Title;
            try
            {
                MessageRule msgR = new MessageRule();
                if (string.IsNullOrEmpty(msg.ID))                //新增
                {
                    msg.ID         = Guid.NewGuid().ToString("N");
                    msg.OperatorID = MyTicket.CurrentTicket.UserID;
                    msg.CreateDate = DateTime.Now;
                    msgR.Add(msg);
                    //不选接收人,默认发送给所有人
                    if (string.IsNullOrEmpty(AcceptIDS))
                    {
                        List <Ajax.Model.Customer> acceptList = new CustomerRule().GetList("");
                        foreach (Ajax.Model.Customer c in acceptList)
                        {
                            AcceptIDS += c.OperatorID + ",";
                        }
                    }
                    string[] strAcceptIDs = AcceptIDS.Remove(AcceptIDS.Length - 1, 1).Split(',');                    //Request.Form["txtAcceptIDs"].Split(',');
                    //接收人
                    OperatorMsgRule    omsgR    = new OperatorMsgRule();
                    List <OperatorMsg> oMsgList = new List <OperatorMsg>();
                    foreach (string acceptID in strAcceptIDs)
                    {
                        if (string.IsNullOrEmpty(acceptID))
                        {
                            continue;
                        }
                        OperatorMsg omsg = new OperatorMsg();
                        omsg.ID         = Guid.NewGuid().ToString("N");
                        omsg.Status     = 0;                    //默认为未读
                        omsg.MsgID      = msg.ID;
                        omsg.OperatorID = acceptID;
                        oMsgList.Add(omsg);
                    }
                    omsgR.AddMul(oMsgList);
                    result.Success = true;
                    result.Message = "公告已经成功发出。";
                }
                else                //编辑
                {
                    result.Success = msgR.Update(msg);
                    result.Message = result.Success ? "公告已经成功修改。" : "公告修改失败!";
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = "操作失败:" + ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// CRUD operations for Inbox rules.
        /// </summary>
        /// <param name="exchangeService">Exchange service.</param>
        public static void CreateReadUpdateDeleteInboxRule(ExchangeService exchangeService)
        {
            MessageRule messageRule = new MessageRule(exchangeService);

            messageRule.IsEnabled = true;
            messageRule.Sequence  = 1;
            messageRule.Actions   = new MessageRuleActions()
            {
                Delete = true,
                StopProcessingRules = true
            };

            messageRule.Conditions = new MessageRulePredicates()
            {
                FromAddresses = new List <Recipient>()
                {
                    new Recipient()
                    {
                        EmailAddress = new EmailAddress()
                        {
                            Address = "*****@*****.**"
                        }
                    }
                }
            };
            IList <string> s = new ObservableCollection <string>();

            messageRule.DisplayName = "Test rule";

            Assert.IsNull(messageRule.Id);
            messageRule.Save();
            Assert.IsNotNull(messageRule.Id);

            Assert.IsNotNull(messageRule.Id);

            MessageRule getMessageRule = exchangeService.GetInboxRule(messageRule.Id);

            Assert.IsNotNull(getMessageRule);

            getMessageRule.IsEnabled = false;
            getMessageRule.Update();
            Assert.IsFalse(getMessageRule.IsEnabled);


            List <MessageRule> rules = exchangeService.GetInboxRules();

            Assert.IsTrue(rules.Count == 1);

            getMessageRule.Delete();
            rules = exchangeService.GetInboxRules();
            Assert.IsTrue(rules.Count == 0);
        }