Beispiel #1
0
        public async Task <IActionResult> Index(CitationReceiptViewModel model)
        {
            verifiedFile lstVerified = new verifiedFile();

            if (ModelState.IsValid)
            {
                var receipt = _factoryCtx.GetAccountContext(model.AccountNumber);

                var commonAccount = _commonContext.CommonAccounts.Where(x => x.Number == model.AccountNumber).SingleOrDefault();
                if (commonAccount != null)
                {
                    var citation = receipt.CitationReceipts.Where(x => x.Citation.CitationNumber == model.CitationNumber && x.AccountId == commonAccount.Id).SingleOrDefault();
                    if (citation != null)
                    {
                        //JWT Token Method
                        model = await CitationReceipt(model, citation);
                    }
                    else
                    {
                        ModelState.AddModelError(nameof(model.CitationNumber), "Invalid Citation Number.");
                        return(View(model));
                    }
                }
                else
                {
                    ModelState.AddModelError(nameof(model.AccountNumber), "Invalid Account Number.");
                    return(View(model));
                }
            }

            return(View(model));
        }
Beispiel #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);
        }
Beispiel #3
0
        public IActionResult Index()
        {
            CitationReceiptViewModel model = new CitationReceiptViewModel();

            return(View(model));
        }