public void AddSystemMail(string title, string message, string toUserName, string fromUserName)
        {
            const string systemUserName = "******";
            var          mail           = new InternalMail
            {
                UserName   = systemUserName,
                PersonName = systemUserName,
                Title      = title,
                Body       = $"<h3>{message}</h3>",
                SendTime   = DateTime.Now,
                MailType   = MailType.系统,
                CreateUser = fromUserName,
                UpdateUser = fromUserName,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
                LastAction = "发送",
                Tos        = new List <InternalMailTo>
                {
                    new InternalMailTo
                    {
                        UserName   = toUserName,
                        PersonName = toUserName,
                        CreateUser = fromUserName,
                        UpdateUser = fromUserName,
                        CreateTime = DateTime.Now,
                        UpdateTime = DateTime.Now,
                        LastAction = "发送"
                    }
                }
            };

            _internalMailRepository.Add(mail);
        }
        public async Task <IHttpActionResult> Post(JObject obj)
        {
            var mail          = obj["mail"].ToObject <InternalMailViewModel>();
            var toUserNames   = obj["tos"].ToObject <List <string> >();
            var attachmentVms = obj["attachments"].ToObject <List <UploadedFileViewModel> >();

            var newMailModel = Mapper.Map <InternalMailViewModel, InternalMail>(mail);

            newMailModel.UserName   = UserName;
            newMailModel.SendTime   = Now;
            newMailModel.CreateUser = newMailModel.UpdateUser = User.Identity.Name;
            newMailModel.LastAction = "发送消息";
            var tos = toUserNames.Select(x => new InternalMailTo
            {
                UserName   = x,
                CreateTime = Now,
                CreateUser = UserName,
                UpdateTime = Now,
                UpdateUser = UserName,
                LastAction = "发送消息"
            }).ToList();
            var attachments = attachmentVms.Select(x => new InternalMailAttachment
            {
                FileId     = x.FileId,
                FileName   = x.FileName,
                Size       = x.Size,
                Path       = x.Path,
                CreateTime = Now,
                CreateUser = UserName,
                UpdateTime = Now,
                UpdateUser = UserName,
                LastAction = "发送消息"
            }).ToList();

            newMailModel.Tos         = tos;
            newMailModel.Attachments = attachments;
            _internalMailRepository.Add(newMailModel);
            await UnitOfWork.SaveChangesAsync();

            return(RedirectToRoute("", new { controller = "InternalMail", id = newMailModel.Id }));
        }