public ActionResult Create(MessagerDto dto)
        {
            dto.Status   = (int)MessagerStatusFlag.UnRead;
            dto.SenderId = AuthorityHelper.OperatorId ?? 0;
            List <MessagerDto> listDto = new List <MessagerDto>();

            foreach (int id in dto.ReceiverIds)
            {
                MessagerDto entity = DeepClone(dto);
                entity.ReceiverId = id;
                listDto.Add(entity);
            }
            var result = _messagerContract.Insert(true, sendMessageAction, listDto.ToArray());

            if (result.ResultType == OperationResultType.Success)
            {
                SetCache(dto.ReceiverIds);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public ActionResult SendMsg(int senderId, int receiverId, string title, string content)
        {
            try
            {
                //校验接收者是否存在
                var entity = _adminContract.Administrators.FirstOrDefault(a => !a.IsDeleted && a.IsEnabled && a.Id == receiverId);
                if (entity == null)
                {
                    return(Json(new OperationResult(OperationResultType.Error, "接收者信息有误")));
                }

                //发送
                List <MessagerDto> listDto = new List <MessagerDto>()
                {
                    new MessagerDto()
                    {
                        MessageTitle = title,
                        Description  = content,
                        SenderId     = senderId,
                        ReceiverIds  = new List <int>()
                        {
                            receiverId
                        },
                        ReceiverId = receiverId,
                        Status     = (int)MessagerStatusFlag.UnRead,
                    }
                };

                var result = _messagerContract.Insert(sendMessageAction, listDto.ToArray());

                return(Json(result));
            }
            catch (Exception e)
            {
                return(Json(new OperationResult(OperationResultType.Error, "系统错误")));
            }
        }