Пример #1
0
        private Stream CreateLetter(NewLetterModel info)
        {
            try
            {
                var distributor    = _distributorService.GetDistributorById(info.DistNumber);
                var sponsor        = _distributorService.GetDistributorById(info.SponsorNumber);
                var platium        = _distributorService.GetDistributorById(info.PlatiumNumber);
                var oldDistributor = _distributorService.GetDistributorById(info.OldDistNumber);
                var outputStream   = new MemoryStream();


                string filePath   = Server.MapPath(Url.Content("~/Template/LetterTemplate.docx"));
                DocX   document   = DocX.Load(filePath);
                Stream mainStream = new MemoryStream();
                document.SaveAs(mainStream);
                mainStream.Position = 0;
                mainStream          = CreateLetterTemplate(mainStream, distributor, sponsor, platium, oldDistributor);

                //TODO: Add contant for file name
                Stream distributorLetter = CreateLetterAddress(mainStream, distributor);
                //zip.AddEntry("Re-apps letter-Nguoi dang ky lai.docx", distributorLetter);


                Stream sponsorLetter = CreateLetterAddress(mainStream, sponsor);
                //zip.AddEntry("Re-apps letter -Tuyen tren cu.docx", sponsorLetter);

                DocX docx = DocX.Load(distributorLetter);
                docx.InsertSectionPageBreak();
                docx.InsertDocument(DocX.Load(sponsorLetter));

                if (info.SponsorNumber != info.PlatiumNumber)
                {
                    Stream platiumLetter = CreateLetterAddress(mainStream, platium);
                    //zip.AddEntry("Re-apps letter -Platinum cu.docx", platiumLetter);
                    docx.InsertSectionPageBreak();
                    docx.InsertDocument(DocX.Load(platiumLetter));
                }
                docx.SaveAs(outputStream);
                _distributorService.AddNewLetter(new DistributorLetter
                {
                    DistName           = info.DistName,
                    OldDistNumber      = info.OldDistNumber,
                    PlatiniumSponsorId = info.PlatiumNumber,
                    SponsorId          = info.SponsorNumber,
                    DistNumber         = info.DistNumber,
                    LetterDate         = DateTime.Now,
                    UserId             = _workContext.User.UserID,
                    WHId = _workContext.User.WarehouseId
                });


                outputStream.Position = 0;
                return(outputStream);
            }
            catch (Exception ex)
            {
                //TODO: Redirect to error Page
                return(null);
            }
        }
Пример #2
0
        public async Task <ActionResult> ExportLetter(NewLetterModel info)
        {
            Stream stream = CreateLetter(info);

            //TODO: redirect to error page
            if (stream == null)
            {
                return(Content("error message", MediaTypeNames.Text.Plain));
            }
            var fileName = info.DistNumber + "_ThuTaiGiaNhap.docx";

            return(File(stream, "application/zip", fileName));
        }
Пример #3
0
        public async Task <ActionResult> VerifyData(List <string> values)
        {
            NewLetterModel model = await GetDistributorsInformation(values);

            if (model != null)
            {
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Content("Không tìm thấy nhà phân phối hoặc bảo trợ", MediaTypeNames.Text.Plain));
            }
        }