Example #1
0
        async void ValidateSignatureAndUpload()
        {
            Dialog.ShowLoading("");

            if (Contract.SignImageSource != null)
            {
                PdfDocument duplicate = (PdfDocument)Contract.Document.Clone();


                var addPage = duplicate.Pages.Add();

                var width = addPage.GetClientSize().Width;

                PdfGraphics graphics = addPage.Graphics;

                PdfBitmap image = new PdfBitmap(new MemoryStream(contract.SignImageSource));

                graphics.DrawImage(image, new RectangleF(20, 40, width / 2, 60));


                MemoryStream m = new MemoryStream();

                duplicate.Save(m);

                var document = await StoreManager.DocumentStore.GetItemByContractId(Contract.Id, "saleContract");

                if (document == null)
                {
                    var documentItem = new Document()
                    {
                        Path = Contract.Id + '/' + "saleContract.pdf", Name = contract.Id + ".pdf", InternalName = "saleContract", ReferenceKind = "contract", ReferenceId = contract.Id, MimeType = "application/pdf"
                    };

                    var uploaded = await StoreManager.DocumentStore.InsertImage(m.ToArray(), documentItem);
                }
                else
                {
                    await PclStorage.SaveFileLocal(m.ToArray(), document.Id);

                    document.ToUpload = true;

                    await StoreManager.DocumentStore.UpdateAsync(document);

                    await StoreManager.DocumentStore.OfflineUploadSync();
                }

                Contract.ToSend = true;

                var isSent = await StoreManager.ContractStore.UpdateAsync(Contract);

                if (isSent)
                {
                    await CoreMethods.DisplayAlert(AppResources.Alert, AppResources.EmailSent, AppResources.Ok);

                    BackButton.Execute(null);
                }
            }

            Dialog.HideLoading();
        }
Example #2
0
        public async Task <IEnumerable <bool> > PullLatest(string KindId, string Kind)
        {
            await InitializeStore().ConfigureAwait(false);
            await PullLatestAsync().ConfigureAwait(false);

            var items = await GetItemsByKindAndReferenceIdAsync(KindId, Kind);

            List <bool> returnBool = new List <bool>();

            if (items != null)
            {
                foreach (var item in items)
                {
                    var fileName = item.InternalName + "." + item.Extension;
                    var IsExist  = await PclStorage.IsFileExistAsync(fileName, item.ReferenceKind, item.ReferenceId);

                    if (!IsExist && !string.IsNullOrEmpty(item.Path)) // Only download files who have some value in the path field.
                    {
                        var document = await DownLoadDocument(item.Id);

                        if (document != null)
                        {
                            var response = await PclStorage.SaveFileLocal(document, fileName, item.ReferenceKind, item.ReferenceId);

                            if (response == true)
                            {
                                returnBool.Add(true);
                            }
                            else
                            {
                                returnBool.Add(false);
                            }
                        }
                        else
                        {
                            returnBool.Add(false);
                        }
                    }
                    else
                    {
                        returnBool.Add(true);
                    }
                }
            }

            return(returnBool);
        }
Example #3
0
        private async Task PullLatest()
        {
            await InitializeStore().ConfigureAwait(false);

            var items = await GetItemsAsync(true);

            foreach (var item in items)
            {
                var IsExist = await PclStorage.IsFileExistAsync(item.Id);

                if (!IsExist)
                {
                    var document = await DownLoadDocument(item.Id);

                    if (document != null)
                    {
                        var response = await PclStorage.SaveFileLocal(document, item.Id);
                    }
                }
            }
        }
Example #4
0
        public async Task <bool> InsertImage(byte[] data, Document document)
        {
            if (data == null)
            {
                return(false);
            }

            document.ToUpload = true;

            var response = await PclStorage.SaveFileLocal(data, document.Id);

            var resp = await InsertAsync(document);

            var res = await UploadDocument(data, document);

            if (res)
            {
                document.ToUpload = false;
                await UpdateAsync(document);
            }

            return(res);
        }