예제 #1
0
        public FileContentResult DownloadLink(string id)
        {
            Guid   guid          = new Guid(id);
            String stringGuid    = guid.ToString("D");
            Guid   formattedGuid = new Guid(stringGuid);

            CaseModel caseModel = client.GetCase(guid);

            if (caseModel.Status == CaseStatus.Sent)
            {
                var filnavn = DBController.HentDokument(id).Filnavn;

                var         receipt     = caseModel.Documents.Where(d => d.Type == DocumentType.Original).Single();
                List <byte> fileContent = new List <byte>();
                byte[]      returnedFile;

                using (Stream stream = client.GetDocumentData(formattedGuid, receipt.Id))
                {
                    StreamReader reader  = new StreamReader(stream);
                    string       payload = reader.ReadToEnd();
                    returnedFile = System.Text.Encoding.UTF8.GetBytes(payload);
                }
                //byte[] returnedFile2 = new byte[fileContent.Count()];
                //fileContent.CopyTo(returnedFile2);
                return(File(returnedFile, System.Net.Mime.MediaTypeNames.Application.Pdf, filnavn));
            }

            return(null);
        }
예제 #2
0
        private CreateAndSendCaseResponse CreateCaseFromTemplate()
        {
            CreateAndSendCaseResponse createAndSendCaseResponse = new CreateAndSendCaseResponse();


            if (!string.IsNullOrWhiteSpace(Name) && !string.IsNullOrWhiteSpace(Email))
            {
                try
                {
                    var client = new AssentlyClient(_configuration.GetConnectionString("WebURI"), _configuration.GetConnectionString("APIKey"), _configuration.GetConnectionString("APISecret"));

                    var newCaseID = Guid.NewGuid();
                    client.CreateCaseFromTemplate(Guid.Parse(_configuration["TemplateId"]), newCaseID);

                    var @case = client.GetCase(newCaseID);

                    @case.Name                            = $"{Name}/{newCaseID}";
                    @case.Parties[0].Name                 = Name;
                    @case.Parties[0].EmailAddress         = Email;
                    @case.Parties[0].MobilePhone          = PhoneNumber;
                    @case.Parties[0].SocialSecurityNumber = PersonalNumber;
                    @case.Documents[0].FormFields["ContractDescription"] = Description;


                    client.UpdateCase(@case);
                    client.SendCase(newCaseID);

                    createAndSendCaseResponse.URL = @case.Parties[0].PartyUrl;
                }
                catch (Exception ex)
                {
                    createAndSendCaseResponse.ErrorMessage = ex.Message;
                }
            }
            else
            {
                createAndSendCaseResponse.ErrorMessage = "Please enter your Name and Email, to create contract";
            }
            return(createAndSendCaseResponse);
        }