Пример #1
0
        public IHttpActionResult SendCorrespondentEmail(int id, CorrespondentEmailDO email)
        {
            using (var transaction = this.unitOfWork.BeginTransaction())
            {
                UnitUser unitUser = this.unitOfWork.DbContext.Set<UnitUser>().FirstOrDefault(e => e.UserId == this.userContext.UserId);

                ClassificationPermission sendEmailPermission = this.classificationRepository.GetByAlias("SendMail");
                ClassificationPermission readPermission = this.classificationRepository.GetByAlias("Read");

                bool hasSendEmailPermission =
                    this.classificationRepository.HasPermission(unitUser.UnitId, id, sendEmailPermission.ClassificationPermissionId) &&
                    this.classificationRepository.HasPermission(unitUser.UnitId, id, readPermission.ClassificationPermissionId);

                if (!hasSendEmailPermission)
                {
                    return BadRequest("Not enough permissions!");
                }

                Email correspondentEmail = this.emailRepository.CreateCorrespondentEmail(email);

                this.unitOfWork.DbContext.Set<Email>().Add(correspondentEmail);

                this.unitOfWork.Save();

                transaction.Commit();

                return Ok();
            }
        }
Пример #2
0
        public IHttpActionResult GetCorrespondentEmail(int id)
        {
            Doc doc = this.docRepository.Find(id,
                e => e.DocCorrespondents.Select(dc => dc.Correspondent),
                e => e.DocStatus,
                e => e.DocFiles.Select(k => k.DocFileKind),
                e => e.DocFiles.Select(k => k.DocFileOriginType));

            if (doc == null)
            {
                return NotFound();
            }

            Doc caseDoc = this.docRepository.Find(this.docRepository.GetCaseId(id));

            CorrespondentEmailDO email = new CorrespondentEmailDO();
            Correspondent correspondent = new Correspondent();

            foreach (var item in doc.DocCorrespondents)
            {
                NomDo corrNom = new NomDo();
                corrNom.NomValueId = item.Correspondent.CorrespondentId;
                corrNom.Name = item.Correspondent.DisplayName + " " + item.Correspondent.Email;
                corrNom.Alias = item.Correspondent.Alias;
                corrNom.IsActive = item.Correspondent.IsActive;

                email.EmailTo.Add(corrNom);
            }

            foreach (var item in doc.DocFiles.Where(e => e.DocFileKind.Alias == "PublicAttachedFile"))
            {
                email.PublicFiles.Add(new DocFileDO(item));
            }

            EmailType emailType = this.emailRepository.GetEmailTypeByAlias("CorrespondentEmail");

            email.EmailBcc = "";
            email.EmailTypeId = emailType.EmailTypeId;
            email.Subject = emailType.Subject
                .Replace("@@CaseNum", !string.IsNullOrEmpty(caseDoc.RegUri) ? caseDoc.RegUri : "[Няма номер на преписка]");
            email.Body = emailType.Body
                .Replace("@@CaseNum", !string.IsNullOrEmpty(caseDoc.RegUri) ? caseDoc.RegUri : "[Няма номер на преписка]")
                .Replace("@@DocViewUrl", EmailRepository.DocViewUrl)
                .Replace("@@CaseViewUrl", EmailRepository.CaseViewUrl)
                .Replace("@@AccessCode", caseDoc.AccessCode);

            return Ok(new
            {
                email = email
            });
        }