Exemple #1
0
        public MailInfo GetMail(IConnectionHandler connectionHandler, Guid userId, Guid id)
        {
            var mailInfo = this.Get(connectionHandler, id);

            if (mailInfo == null)
            {
                return(null);
            }
            var inboxbox             = new MailBoxBO().GetUserInboxMail(connectionHandler, userId, id);
            var enterpriseNodeFacade = EnterpriseNodeComponent.Instance.EnterpriseNodeFacade;

            if (inboxbox != null)
            {
                foreach (var mailBox in inboxbox)
                {
                    if (!mailBox.Read)
                    {
                        mailBox.Read = true;
                        if (!new MailBoxBO().Update(connectionHandler, mailBox))
                        {
                            throw new Exception("خطایی در ویرایش ایمیل وجود دارد");
                        }
                    }
                }

                if (!string.IsNullOrEmpty(mailInfo.Bcc))
                {
                    foreach (var bccId in mailInfo.Bcc.Split(','))
                    {
                        if (string.IsNullOrEmpty(bccId))
                        {
                            continue;
                        }
                        if (!string.IsNullOrEmpty(mailInfo.BccNames))
                        {
                            mailInfo.BccNames += ",";
                        }
                        if (userId == bccId.ToGuid())
                        {
                            var user = enterpriseNodeFacade.Get(bccId.ToGuid());
                            if (user != null)
                            {
                                mailInfo.BccNames += user.Title();
                            }
                        }
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(mailInfo.Bcc))
                {
                    foreach (var bccId in mailInfo.Bcc.Split(','))
                    {
                        if (string.IsNullOrEmpty(bccId))
                        {
                            continue;
                        }
                        if (!string.IsNullOrEmpty(mailInfo.BccNames))
                        {
                            mailInfo.BccNames += ",";
                        }
                        var user = enterpriseNodeFacade.Get(bccId.ToGuid());
                        if (user != null)
                        {
                            mailInfo.BccNames += user.Title();
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(mailInfo.To))
            {
                foreach (var toId in mailInfo.To.Split(','))
                {
                    if (string.IsNullOrEmpty(toId))
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(mailInfo.ToNames))
                    {
                        mailInfo.ToNames += ",";
                    }
                    var user = enterpriseNodeFacade.Get(toId.ToGuid());
                    if (user != null)
                    {
                        mailInfo.ToNames += user.Title();
                    }
                }
            }
            if (!string.IsNullOrEmpty(mailInfo.Cc))
            {
                foreach (var ccId in mailInfo.Cc.Split(','))
                {
                    if (string.IsNullOrEmpty(ccId))
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(mailInfo.CcNames))
                    {
                        mailInfo.CcNames += ",";
                    }
                    var user = enterpriseNodeFacade.Get(ccId.ToGuid());
                    if (user != null)
                    {
                        mailInfo.CcNames += user.Title();
                    }
                }
            }
            var list = new MailAttachmentBO().Where(connectionHandler, x => x.MailId == id);

            foreach (var mailAttachment in list)
            {
                if (mailAttachment.AttachFile == null)
                {
                    continue;
                }
                var mailAttachmentModel = new MailAttachment
                {
                    AttachId   = mailAttachment.AttachId,
                    AttachFile = mailAttachment.AttachFile
                };
                mailInfo.Attachments.Add(mailAttachmentModel);
            }
            return(mailInfo);
        }
Exemple #2
0
        public bool SentMailInBo(IConnectionHandler connectionHandler, MailInfo mailInfo, List <Guid> file)
        {
            if (mailInfo.Id == Guid.Empty)
            {
                if (!new MailInfoBO().Insert(connectionHandler, mailInfo))
                {
                    throw new Exception(Resources.Message.ErrorInSaveMail);
                }
            }
            else
            {
                if (!new MailInfoBO().Update(connectionHandler, mailInfo))
                {
                    throw new Exception(Resources.Message.ErrorInSaveMail);
                }
            }

            if (file != null)
            {
                if (file.Select(attachId => new MailAttachment
                {
                    MailId = mailInfo.Id,
                    AttachId = attachId
                }).Any(mailAttachment => !new MailAttachmentBO().Insert(connectionHandler, mailAttachment)))
                {
                    throw new Exception(Resources.Message.ErrorInSaveEmailAttachment);
                }
            }
            if (!mailInfo.IsDraft)
            {
                var mailBoxBo = new MailBoxBO();
                if (string.IsNullOrEmpty(mailInfo.To))
                {
                    throw new Exception("لطفا اشخاص ارسالی را انتخاب کنید");
                }
                if (mailInfo.To.Split(',').Select(toId => new MailBox
                {
                    MailId = mailInfo.Id,
                    ToId = toId.ToGuid(),
                    FromId = mailInfo.FromId,
                }).Any(mailBox => !mailBoxBo.Insert(connectionHandler, mailBox)))
                {
                    throw new Exception(Resources.Message.ErrorInSaveMail);
                }
                if (!string.IsNullOrEmpty(mailInfo.Bcc))
                {
                    if (mailInfo.Bcc.Split(',').Select(toId => new MailBox
                    {
                        MailId = mailInfo.Id,
                        ToId = toId.ToGuid(),
                        FromId = mailInfo.FromId,
                    }).Any(mailBox => !mailBoxBo.Insert(connectionHandler, mailBox)))
                    {
                        throw new Exception(Resources.Message.ErrorInSaveMail);
                    }
                }
                if (!string.IsNullOrEmpty(mailInfo.Cc))
                {
                    if (mailInfo.Cc.Split(',').Select(toId => new MailBox
                    {
                        MailId = mailInfo.Id,
                        ToId = toId.ToGuid(),
                        FromId = mailInfo.FromId,
                    }).Any(mailBox => !mailBoxBo.Insert(connectionHandler, mailBox)))
                    {
                        throw new Exception(Resources.Message.ErrorInSaveMail);
                    }
                }
            }

            return(true);
        }