Пример #1
0
        public async Task <HttpResponseMessage> GetCustomerWithCustomerId()
        {
            //
            // The Scope claim tells you what permissions the client application has in the service.
            // In this case we look for a scope value of user_impersonation, or full access to the service as the user.
            //
            if (ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value != "user_impersonation")
            {
                throw new HttpResponseException(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, ReasonPhrase = "The Scope claim does not contain 'user_impersonation' or scope claim not found"
                });
            }

            Claim subject = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier);

            Customer customer = await ProcessClientData();

            Customer localcustomer = SqlDBRepository.GetCustomer(customer.CustomerId);

            //CloudBlobContainer container = GetContainer(localcustomer);
            ////AzureDocumentResponse docResponse = new AzureDocumentResponse();

            //for (int i = 0; i < localcustomer.LegalDocuments.Count; i++)
            //{
            //    localcustomer.LegalDocuments[i].DocumentData = GetBlob(container, customer.CaseId);
            //}

            return(Request.CreateResponse(HttpStatusCode.OK, localcustomer));
        }
Пример #2
0
        public async Task <IHttpActionResult> DownloadFile()
        {
            if (ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value != "user_impersonation")
            {
                throw new HttpResponseException(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, ReasonPhrase = "The Scope claim does not contain 'user_impersonation' or scope claim not found"
                });
            }

            Claim subject = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier);

            CustomerFile custFile = await ProcessCustomerFileData();

            CloudBlobContainer container = GetContainer();

            custFile = SqlDBRepository.GetLegalDocumentData(custFile.Id);

            CloudBlobDirectory caseDirectory = container.GetDirectoryReference("case" + custFile.CaseId.ToString().ToLower());
            CloudBlockBlob     blockBlob     = caseDirectory.GetBlockBlobReference(custFile.Id.ToString() + "_" + custFile.DocumentType);

            blockBlob.FetchAttributes();
            byte[] byteData = new byte[blockBlob.Properties.Length];
            blockBlob.DownloadToByteArray(byteData, 0);

            custFile.DocumentData = byteData;

            return(Ok(custFile));
        }
Пример #3
0
        public async Task <HttpResponseMessage> DeleteFile()
        {
            if (ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value != "user_impersonation")
            {
                throw new HttpResponseException(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, ReasonPhrase = "The Scope claim does not contain 'user_impersonation' or scope claim not found"
                });
            }

            Claim subject = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier);

            CustomerFile custFile = await ProcessCustomerFileData();

            CloudBlobContainer container = GetContainer();

            custFile = SqlDBRepository.GetLegalDocumentData(custFile.Id);
            // Delete customer case directory from container for broker.

            CloudBlobDirectory caseDirectory = container.GetDirectoryReference("case" + custFile.CaseId.ToString().ToLower());
            CloudBlockBlob     blockBlob     = caseDirectory.GetBlockBlobReference(custFile.Id.ToString() + "_" + custFile.DocumentType);

            blockBlob.DeleteIfExists();

            bool status = SqlDBRepository.DeleteLegalDocument(custFile);

            return(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK
            });
        }
Пример #4
0
        public async Task <HttpResponseMessage> DeleteCustomer()
        {
            if (ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value != "user_impersonation")
            {
                throw new HttpResponseException(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, ReasonPhrase = "The Scope claim does not contain 'user_impersonation' or scope claim not found"
                });
            }

            Claim subject = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier);

            Customer customer = await ProcessClientData();

            CloudBlobContainer container = GetContainer();

            // Delete customer case directory from container for broker.

            foreach (IListBlobItem blob in container.GetDirectoryReference("case" + customer.CaseId.ToString().ToLower()).ListBlobs(true))
            {
                if (blob.GetType() == typeof(CloudBlob) || blob.GetType().BaseType == typeof(CloudBlob))
                {
                    ((CloudBlob)blob).DeleteIfExists();
                }
            }

            bool status = SqlDBRepository.DeleteCustomer(customer);

            return(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK
            });
        }
Пример #5
0
        public IHttpActionResult GetCustomers()
        {
            if (ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value != "user_impersonation")
            {
                throw new HttpResponseException(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, ReasonPhrase = "The Scope claim does not contain 'user_impersonation' or scope claim not found"
                });
            }

            Claim subject = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier);
            IEnumerable <Customer> customers = SqlDBRepository.GetCustomers();

            return(Ok(customers));
        }
Пример #6
0
        public async Task <HttpResponseMessage> CreateCustomerWithDocumentUpload()
        {
            ////
            // The Scope claim tells you what permissions the client application has in the service.
            // In this case we look for a scope value of user_impersonation, or full access to the service as the user.
            //
            if (ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value != "user_impersonation")
            {
                throw new HttpResponseException(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, ReasonPhrase = "The Scope claim does not contain 'user_impersonation' or scope claim not found"
                });
            }

            Claim subject = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier);

            Customer customer = await ProcessClientData();

            CloudBlobContainer container = GetContainer();

            //container.CreateIfNotExists();

            // Retrieve a case directory created for broker.
            //CloudBlobDirectory caseDirectory = container.GetDirectoryReference("case" + customer.CaseId.ToString().ToLower());


            //foreach (var item in customer.LegalDocuments)
            //{
            //    item.StoragePath = UploadBlob(caseDirectory, item);
            //}

            foreach (var item in customer.LegalDocuments)
            {
                item.StoragePath = UploadBlob(container, item, customer.CaseId);
            }

            bool status = SqlDBRepository.InsertCustomer(customer);

            return(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK
            });
        }