Example #1
0
        public IActionResult UploadKyc([FromServices] ICurrentUsers currentUsers, enmSaveStatus?_enmSaveStatus, enmMessage?_enmMessage)
        {
            mdlKyc mdl = new mdlKyc();

            if (_enmSaveStatus != null)
            {
                ViewBag.SaveStatus = (int)_enmSaveStatus.Value;
                ViewBag.Message    = _enmMessage?.GetDescription();
            }
            string filePath = _config["FileUpload:Kyc"];

            var path = Path.Combine(
                Directory.GetCurrentDirectory(),
                "wwwroot/" + filePath);
            var kycMaster = _context.tblKycMaster.Where(p => p.TcNid == currentUsers.TcNid && !p.Isdeleted).FirstOrDefault();

            if (kycMaster != null)
            {
                mdl.ApprovalRemarks = kycMaster.ApprovalRemarks;
                mdl.IsApproved      = kycMaster.IsApproved;
                mdl.IdProofType     = kycMaster.IdProofType;
                mdl.DocumentNo      = kycMaster.IdDocumentNo;
                mdl.Remarks         = kycMaster.Remarks;
                mdl.fileData        = new List <byte[]>();
                var files = kycMaster.IdDocumentName.Split(",");
                foreach (var file in files)
                {
                    mdl.fileData.Add(System.IO.File.ReadAllBytes(string.Concat(path, file)));
                }
            }
            return(View(mdl));
        }
Example #2
0
        public async Task <IActionResult> UploadKycAsync([FromServices] ICurrentUsers currentUsers, mdlKyc mdl)
        {
            string filePath = _config["FileUpload:Kyc"];

            var path = Path.Combine(
                Directory.GetCurrentDirectory(),
                "wwwroot/" + filePath);

            if (mdl.IDDocumentUpload == null || mdl.IDDocumentUpload.Count == 0 || mdl.IDDocumentUpload[0] == null || mdl.IDDocumentUpload[0].Length == 0)
            {
                ModelState.AddModelError("IDDocumentUpload", "Invalid Files");
                ViewBag.SaveStatus = enmSaveStatus.danger;
                ViewBag.Message    = enmMessage.InvalidData.GetDescription();
            }
            if (mdl.IdProofType == enmIdentityProof.Aadhar)
            {
                if (mdl.DocumentNo.Trim().Length != 12)
                {
                    ModelState.AddModelError("DocumentNo", "Invalid Aadhar Number");
                    ViewBag.SaveStatus = enmSaveStatus.danger;
                    ViewBag.Message    = enmMessage.InvalidData.GetDescription();
                }
                else if (!mdl.DocumentNo.All(char.IsDigit))
                {
                    ModelState.AddModelError("DocumentNo", "Invalid Aadhar Number");
                    ViewBag.SaveStatus = enmSaveStatus.danger;
                    ViewBag.Message    = enmMessage.InvalidData.GetDescription();
                }
            }
            if (ModelState.IsValid)
            {
                List <string> AllFileName = new List <string>();

                bool exists = System.IO.Directory.Exists(path);
                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                foreach (var file in mdl.IDDocumentUpload)
                {
                    var filename = Guid.NewGuid().ToString() + ".jpeg";
                    using (var stream = new FileStream(string.Concat(path, filename), FileMode.Create))
                    {
                        AllFileName.Add(filename);
                        await file.CopyToAsync(stream);
                    }
                }

                var ExistingData = _context.tblKycMaster.FirstOrDefault(p => !p.Isdeleted && p.TcNid == currentUsers.TcNid && p.IsApproved == enmApprovalType.Rejected);
                if (ExistingData != null)
                {
                    ExistingData.Isdeleted = true;
                    _context.tblKycMaster.Update(ExistingData);
                }
                if (_context.tblKycMaster.Any(p => p.TcNid == currentUsers.TcNid && !p.Isdeleted))
                {
                    ModelState.AddModelError("", "Request Already Submited");
                    ViewBag.SaveStatus = enmSaveStatus.warning;
                    ViewBag.Message    = enmMessage.AlreadyExists.GetDescription();
                }
                else
                {
                    _context.tblKycMaster.Add(new tblKycMaster
                    {
                        IdProofType     = mdl.IdProofType,
                        IdDocumentNo    = mdl.DocumentNo,
                        IdDocumentName  = string.Join <string>(",", AllFileName),
                        CreatedBy       = 0,
                        CreatedDt       = DateTime.Now,
                        Remarks         = mdl.Remarks,
                        IsApproved      = enmApprovalType.Pending,
                        Isdeleted       = false,
                        TcNid           = currentUsers.TcNid,
                        ApprovalRemarks = ""
                    });
                    _context.SaveChanges();
                    return(RedirectToAction("UploadKyc",
                                            new { _enmSaveStatus = enmSaveStatus.success, _enmMessage = enmMessage.UpdateSucessfully }));
                }
            }

            return(View(mdl));
        }