Ejemplo n.º 1
0
        public async Task <ServiceResponse <CitationReceipt> > CreateCitationReceipt(Guid accountId, Guid citationId, string DeviceReceipt, string DevicePublicKey, Guid createdById)
        {
            ServiceResponse <CitationReceipt> result = null;

            var receipt = new CitationReceipt
            {
                AccountId       = accountId,
                CitationId      = citationId,
                ReceiptPayload  = DeviceReceipt,
                DevicePublicKey = DevicePublicKey,
                CreateUserId    = createdById,
                UpdateUserId    = createdById
            };

            _accountCtx.CitationReceipts.Add(receipt);

            try
            {
                await _accountCtx.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Error creating receipt. AccountId:{accountId}, CitationId:{citationId}");
            }
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <CitationReceiptViewModel> CitationReceipt(CitationReceiptViewModel model, CitationReceipt citation)
        {
            var decodedJWTToken = Cryptography.DecodeJWTToken(citation.DevicePublicKey, citation.ReceiptPayload);
            CitationDeviceReceiptModel receiptModel = JsonConvert.DeserializeObject <CitationDeviceReceiptModel>(decodedJWTToken);

            model.Submitted = receiptModel.submittedUtc;
            model.Device    = receiptModel.device;
            model.Email     = receiptModel.useremail;
            model.Latitude  = receiptModel.latitude;
            model.Longitude = receiptModel.longitude;
            if (model.File != null)
            {
                foreach (var formFile in model.File)
                {
                    //Get current file extension
                    var name = formFile.FileName;

                    // Check uploaded file exists in receiptModel
                    var IsExists = receiptModel.files.Where(x => x.filename == name).Any();
                    if (IsExists)
                    {
                        foreach (var receiptfile in receiptModel.files)
                        {
                            if (receiptfile.filename == name)
                            {
                                var exists = receiptfile.filename;

                                using (var fileStream = formFile.OpenReadStream())
                                    using (var ms = new MemoryStream())
                                    {
                                        fileStream.CopyTo(ms);


                                        //    using (var ms = new MemoryStream())
                                        //{
                                        //convert image into Bytes
                                        var fileByte1s = ms.ToArray();

                                        var hashfile = Cryptography.Hashfile(fileByte1s, receiptModel.identifier);

                                        if (receiptfile.sha256hash == hashfile)
                                        {
                                            model.VerifiedFiles.Add(new verifiedFile {
                                                FileName = name, IsValid = true
                                            });
                                        }
                                        else
                                        {
                                            model.VerifiedFiles.Add(new verifiedFile {
                                                FileName = name, IsValid = false
                                            });
                                        }
                                    }
                            }
                            else
                            {
                                model.VerifiedFiles.Add(new verifiedFile {
                                    FileName = receiptfile.filename, IsValid = false, Hash = receiptfile.sha256hash
                                });
                            }
                        }
                    }
                    else
                    {
                        foreach (var receiptfile in receiptModel.files)
                        {
                            model.VerifiedFiles.Add(new verifiedFile {
                                FileName = receiptfile.filename, IsValid = false, Hash = receiptfile.sha256hash
                            });
                        }
                    }
                }
            }
            else
            {
                foreach (var receiptfile in receiptModel.files)
                {
                    model.VerifiedFiles.Add(new verifiedFile {
                        FileName = receiptfile.filename, IsValid = false, Hash = receiptfile.sha256hash
                    });
                }
            }

            return(model);
        }