Exemplo n.º 1
0
        private Task <string> UploadDocuments(ReviewDocumentCommand command)
        {
            List <string> files      = new List <string>();
            string        folderPath = GetFolderPath(command.Code);

            if (command.Files != null && command.Files.Any())
            {
                foreach (HttpFile file in command.Files)
                {
                    string filePath = $"{folderPath}/{file.FileName}";
                    command.FolderName = folderPath.Replace(UploadFolderPath, string.Empty);
                    command.LinkFile   = $"/downloadfile/viewfile?sourcedoc={folderPath.Replace(UploadFolderPath, string.Empty)}/{file.FileName}";
                    files.Add(file.FileName);
                    SaveAs(filePath, file);
                }
            }

            if (command.AppendiceFiles != null && command.AppendiceFiles.Any())
            {
                foreach (HttpFile file in command.AppendiceFiles)
                {
                    string filePath = $"{folderPath}/{file.FileName}";
                    SaveAs(filePath, file);
                    Application.Documents.Commands.AppendiceDto appendice = command.Appendices?.FirstOrDefault(a => a.FileName == file.FileName);
                    if (appendice != null)
                    {
                        appendice.LinkFile = $"/downloadfile/viewfile?sourcedoc={folderPath.Replace(UploadFolderPath, string.Empty)}/{file.FileName}";
                    }
                }
            }
            return(Task.FromResult(string.Join(";", files)));
        }
Exemplo n.º 2
0
        public async Task <int> Review([FromBody] ReviewDocumentCommand reviewDocumentCommand)
        {
            reviewDocumentCommand.CreatedBy = User.Identity.GetUserName();
            reviewDocumentCommand.CreatedOn = DateTime.Now;
            reviewDocumentCommand.Deleted   = false;
            reviewDocumentCommand.FileName  = await UploadDocuments(reviewDocumentCommand);

            return(await Mediator.Send(reviewDocumentCommand));
        }
Exemplo n.º 3
0
        public async Task <int> ReviewAndRelease([FromBody] ReviewDocumentCommand reviewDocumentCommand)
        {
            reviewDocumentCommand.CreatedBy = User.Identity.GetUserName();
            reviewDocumentCommand.CreatedOn = DateTime.Now;
            reviewDocumentCommand.Deleted   = false;
            reviewDocumentCommand.FileName  = await UploadDocuments(reviewDocumentCommand);

            int id = await Mediator.Send(reviewDocumentCommand);

            if (id > 0)
            {
                await SendMailReviewDocument(reviewDocumentCommand);
            }
            return(id);
        }
Exemplo n.º 4
0
        protected async Task <int> SendMailReviewDocument(ReviewDocumentCommand command)
        {
            string host         = ConfigurationManager.AppSettings["Host"].ToString();
            string mailTemplate = GetMailTemplate("ReleaseDocument.html");

            ClaimsPrincipal user  = User as ClaimsPrincipal;
            string          token = user.FindFirst("access_token").Value;
            Func <Task <IEnumerable <dynamic> > > users = async() => await CallApi(new Uri($"{MasterDataEndpoint}/api/v1/masterdatas/getallusers"), token);

            IEnumerable <dynamic> result = await AppCache.GetOrAddAsync(CacheKeys.UserCacheKey, users);

            Func <Task <IEnumerable <dynamic> > > groupsFunc = async() => await CallApi(new Uri($"{MasterDataEndpoint}/api/v1/masterdatas/getalldepartments"), token);

            IEnumerable <dynamic> groups = await AppCache.GetOrAddAsync(CacheKeys.DepartmentCacheKey, groupsFunc);

            List <string> groupEmails = new List <string>();

            string[] deployments = command.ScopeOfDeloyment.Split(";");

            if (deployments != null && deployments.Any())
            {
                foreach (string deployment in deployments)
                {
                    /*var group = groups.FirstOrDefault(g => g.code == deployment);
                     * if (group != null)
                     * {
                     *  string email = group.email;
                     *  groupEmails.Add(email.Replace(";", ","));
                     * }*/

                    IEnumerable <dynamic> userGroups = result.Where(u => u.departmentName == deployment);
                    if (userGroups != null)
                    {
                        foreach (dynamic userGroup in userGroups)
                        {
                            string email = userGroup.email;
                            if (!email.IsNullOrEmpty())
                            {
                                groupEmails.Add(email);
                            }
                        }
                    }
                }
            }

            string draterFullName = GetUserFullName(command.Drafter, result);

            string auditorFullName = GetUserFullName(command.Auditor, result);

            string approverFullName = GetUserFullName(command.Approver, result);

            string createdEmail = User.Identity.GetUserEmail();

            if (!createdEmail.IsNullOrEmpty())
            {
                groupEmails.Add(createdEmail);
            }

            if (!mailTemplate.IsNullOrEmpty())
            {
                string effectiveDateString = string.Empty;
                if (command.EffectiveDate.HasValue)
                {
                    effectiveDateString = $"{command.EffectiveDate.Value.ToString("dd/MM/yyyy", CultureInfo.CurrentCulture)}";
                }

                string reviewDateString = string.Empty;
                if (command.ReviewDate.HasValue)
                {
                    reviewDateString = $"{command.ReviewDate.Value.ToString("dd/MM/yyyy", CultureInfo.CurrentCulture)}";
                }

                string     linkFile   = $"<a href=\"{host}/downloadfile/viewfile?sourceDoc={command.FolderName}/{command.FileName}\">{command.FileName}</a>";
                MailHelper mailHelper = new MailHelper
                {
                    Sender      = MailSender,
                    Recipient   = string.Join(",", new string[] { createdEmail }),
                    RecipientCC = string.Join(",", groupEmails.ToArray()),
                    Subject     = $"DCC - Thay đổi tài liệu",
                    Body        = string.Format(mailTemplate,
                                                $"DCC - Thay đổi tài liệu;#{command.DepartmentName} : {command.FileName}",
                                                "Thay đổi tài liệu",
                                                command.Name,
                                                command.ScopeOfApplication.Replace("\n", "<br>"),
                                                effectiveDateString,
                                                command.Description.Replace("\n", "<br>"),
                                                command.ScopeOfDeloyment,
                                                command.DocumentNumber,
                                                command.ReviewNumber,
                                                reviewDateString,
                                                draterFullName,
                                                auditorFullName,
                                                approverFullName,
                                                linkFile,
                                                $"<a href=\"{host}/operationdata/detail?code={command.Code}\">{host}/operationdata/detail?code={command.Code}</a>",
                                                $"<a href=\"{host}/operationdata/list?code={command.DocumentType}\">{host}/operationdata/list?code={command.DocumentType}</a>"
                                                )
                };
                mailHelper.Send();
            }

            return(1);
        }
Exemplo n.º 5
0
 public static Document ToDocument(this ReviewDocumentCommand command)
 {
     return(command.MapTo <ReviewDocumentCommand, Document>());
 }