Esempio n. 1
0
        async Task <string> InsertFile(string name, string container, byte[] file)
        {
            dynamic dynamicAttachment = new ExpandoObject();

            dynamicAttachment.File      = file;
            dynamicAttachment.Container = container;
            dynamicAttachment.Name      = name;
            dynamicAttachment.Route     = "";
            dynamicAttachment.FileUrl   = "";
            var result = await StorageHelperAzure.UploadFileToAzure(dynamicAttachment
                                                                    , Constants.AzureStorage.DefaultConnectionString);

            dynamicAttachment.FileUrl = result.FileUrl;
            return(dynamicAttachment.FileUrl);
        }
Esempio n. 2
0
        public async Task <dynamic> GenerateAct(BE.ReportBE.Report report, int type)
        {
            var assignment  = _assignmentRepository.GetReportSupervisor(report.AssignmentId);
            var users       = _assignmentRepository.GetByPersonnelIdAssignment(report.AssignmentId).ToList();
            var usersClient = _assignmentRepository.GetContactByAssignemtnId(report.AssignmentId).ToList();

            var supervisor = users.Where(x => x.UserType == 1).FirstOrDefault();
            var technician = users.Where(x => x.UserType == 2).FirstOrDefault();
            var client     = usersClient.Where(x => x.Id == report.ContactId).FirstOrDefault();

            var sValue     = ConvertNumberToString(report.Value) + "\"";
            var pdfContent = string.Empty;

            if (type == 1)
            {
                pdfContent = Resources.Template.ActString.ToString();
            }
            else if (type == 2)
            {
                pdfContent = Resources.Template.ExeString.ToString();
            }

            CultureInfo ci = new CultureInfo("es-PE");

            var colorStyle = sValue + " " + strFill.Replace("@@strcolor", strColor);

            pdfContent = pdfContent
                         .Replace("@SocialName", assignment.CompanyName)
                         .Replace("@RUC", assignment.RUC)
                         .Replace("@Branch", assignment.CorpId)
                         .Replace("@Description", assignment.Description)

                         .Replace("@OT", assignment.WorkOrderNumber)
                         .Replace("@Brand", assignment.Machine.Brand)
                         .Replace("@Model", assignment.Machine.Model)
                         .Replace("@Technical", technician?.Name)
                         .Replace("@Horometro", assignment.Machine.TotalHoursFunction.ToString())
                         .Replace("@NumberSerie", assignment.Machine.SerialNumber)
                         .Replace("@DateDelivery", report.Date.ToString("dd-MM-yyyy", ci))
                         .Replace("@DateService", assignment.RequestDate.ToString("dd-MM-yyyy", ci))

                         .Replace("@Antecedent", report.Antecedent)
                         .Replace("@Work", report.Work)
                         .Replace("@Observations", report.Observation)
                         .Replace("@Recommendations", report.Replacement)
                         .Replace("@Client", client?.Name + " " + client?.LastName)
                         .Replace("@SignAct", report.UrlSign)
                         .Replace(sValue.ToString(), colorStyle)
                         //EXE
                         .Replace("@Supervisor", supervisor?.Name)
                         .Replace("@SPhone", supervisor?.Phone)
                         .Replace("@SMail", supervisor?.Email);

            var converter = new HtmlToPdfConverter();
            var pdfFile   = converter.GeneratePdf(pdfContent);
            var path      = System.IO.Path.GetTempPath();

            dynamic dynamicAttachment = new ExpandoObject();

            string pdfString = ""; string nameFile = "";

            nameFile = report.Id + ".pdf";
            if (type == 1)
            {
                pdfString = nameFile;
            }
            else if (type == 2)
            {
                pdfString = $"{path}\\" + nameFile;
                dynamicAttachment.Route = pdfString;
                System.IO.File.WriteAllBytes(pdfString, pdfFile);
            }

            string container = "act";

            dynamicAttachment.File      = pdfFile;
            dynamicAttachment.Container = container;
            dynamicAttachment.Name      = nameFile;
            dynamicAttachment.Route     = pdfString;
            dynamicAttachment.FileUrl   = "";

            var result = await StorageHelperAzure.UploadFileToAzure(dynamicAttachment
                                                                    , Constants.AzureStorage.DefaultConnectionString);

            dynamicAttachment.FileUrl = result.FileUrl;
            return(dynamicAttachment);
        }