Beispiel #1
0
        public async Task <FileModel> GetBytefromImageAsync(int EMP_CODE)
        {
            byte[] by   = new byte[0];
            var    data = _db.bd_emp.Where(x => x.EMP_CODE == EMP_CODE).FirstOrDefault();
            var    file = new FileModel();

            if (data != null)
            {
                string folder    = Path.Combine(pathViewHtml, "E_card.cshtml");
                string razorText = File.ReadAllText(folder);

                DateTime dt = (DateTime)data.BIRTH_DAY;

                ModelDetail detail = new ModelDetail
                {
                    BIRTH_DAY     = ((DateTime)data.BIRTH_DAY).ToString("d.MM.yyyy"),
                    FULLNAME      = data.FIRST_NAME + " " + data.LAST_NAME,
                    PHOTO_PATH_TO = getBase64FromFile(Path.Combine(Image, data.PHOTO_PATH)),
                    NICK_NAME     = data.NICK_NAME,
                    BGIMG         = getBase64FromFile(Path.Combine(Image, "bgECard.jpg")),
                };

                var result = Engine.Razor.RunCompile(razorText, "templateKey", null, detail);

                by = await CovertHtmlToImageAsync(result);

                file.FileName = data.NICK_NAME;
                file.File     = by;
            }
            return(file);
        }
Beispiel #2
0
        public async Task CallWedepxServiceAsync()
        {
            try
            {
                var date   = DateTime.Now.Date;
                var listBd = _db.bd_emp.Where(x => x.BIRTH_DAY == date).ToList();
                if (listBd.Count() > 0)
                {
                    string folder    = Path.Combine(pathViewHtml, "E_card.cshtml");
                    string razorText = File.ReadAllText(folder);


                    foreach (var data in listBd)
                    {
                        ModelDetail detail = new ModelDetail
                        {
                            BIRTH_DAY     = ((DateTime)data.BIRTH_DAY).ToString("d.MM.yyyy"),
                            FULLNAME      = data.FIRST_NAME + " " + data.LAST_NAME,
                            PHOTO_PATH_TO = getBase64FromFile(Path.Combine(Image, data.PHOTO_PATH)),
                            NICK_NAME     = data.NICK_NAME,
                            BGIMG         = getBase64FromFile(Path.Combine(Image, "bgECard.jpg")),
                        };

                        string folderImage = Path.Combine(outputImage, data.PHOTO_PATH + ".jpg");

                        var result = Engine.Razor.RunCompile(razorText, "templateKey", null, detail);



                        await CovertHtmlToImage(result, folderImage);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }