// GET: KYC/Details/id="1003"
        public ActionResult Details(string agentid = "")
        {
            KYCCommon kycCommon = new KYCCommon();

            KYCModelDetail kycModel = new KYCModelDetail();
            var            ID       = agentid.DecryptParameter();

            if (String.IsNullOrEmpty(ID))
            {
                return(RedirectToAction("Index", ControllerName));
            }

            if (!String.IsNullOrEmpty(ID))
            {
                kycCommon = _kyc.AgentKycInfo(ID);
            }
            //kycCommon.AgentId = ID.ToString();
            kycModel             = kycCommon.MapObject <KYCModelDetail>();
            kycModel.Country     = string.IsNullOrEmpty(kycModel.Country) ? "Nepal" : kycModel.Country;
            kycModel.Nationality = string.IsNullOrEmpty(kycModel.Nationality) ? "Nepali" : kycModel.Nationality;
            var pprovince = LoadDropdownList("province") as Dictionary <string, string>;

            kycModel.PProvince = pprovince.ContainsKey(kycModel.PProvince)
                ? pprovince.FirstOrDefault(x => x.Key == kycModel.PProvince).Value : kycModel.PProvince;
            kycModel.TProvince = pprovince.ContainsKey(kycModel.TProvince)
                ? pprovince.FirstOrDefault(x => x.Key == kycModel.TProvince).Value : kycModel.TProvince;
            ViewBag.AgentId = ID;
            KYCModel kyc = new KYCModel();

            kyc = kycModel.MapObject <KYCModel>();
            ViewBag.RemarksList = ApplicationUtilities.SetDDLValue(LoadDropdownList("remarks") as Dictionary <string, string>, kycModel.Remarks, "--Remarks--");

            //LoadDropDownList(kyc);
            #region FileLocation

            string FileLocation;
            string usertype = kycModel.AgentType;
            if (usertype.ToLower() == "distributor")
            {
                FileLocation = "/Content/userupload/Distributor/kyc/";
            }
            else if (usertype.ToLower() == "sub-distributor")
            {
                FileLocation = "/Content/userupload/SubDistributor/kyc/";
            }
            else if (usertype.ToLower() == "walletuser")
            {
                FileLocation = "/Content/userupload/Walletuser/kyc/";
            }
            else if (usertype.ToLower() == "merchant")
            {
                FileLocation = "/Content/userupload/Merchant/kyc/";
            }
            else if (usertype.ToLower() == "agent")
            {
                FileLocation = "/Content/userupload/Agent/kyc/";
            }
            else if (usertype.ToLower() == "sub-agent")
            {
                FileLocation = "/Content/userupload/SubAgent/kyc/";
            }
            else
            {
                FileLocation = "/Content/userupload/";
            }

            ViewBag.FileLocation = FileLocation;
            #endregion
            return(View(kycModel));
        }
        public ActionResult Details(KYCModelDetail kycModel, string submitbutton, string OthersRemarks = "")
        {
            if (submitbutton.ToUpper() == "GOBACK")
            {
                return(RedirectToAction("Index", ControllerName));
            }
            KYCModel kyc = new KYCModel();

            kyc = kycModel.MapObject <KYCModel>();
            LoadDropDownList(kyc);
            #region FileLocation

            string FileLocation;
            string usertype = kycModel.AgentType;
            if (usertype.ToLower() == "distributor")
            {
                FileLocation = "/Content/userupload/Distributor/kyc/";
            }
            else if (usertype.ToLower() == "sub-distributor")
            {
                FileLocation = "/Content/userupload/SubDistributor/kyc/";
            }
            else if (usertype.ToLower() == "walletuser")
            {
                FileLocation = "/Content/userupload/Walletuser/kyc/";
            }
            else if (usertype.ToLower() == "merchant")
            {
                FileLocation = "/Content/userupload/Merchant/kyc/";
            }
            else if (usertype.ToLower() == "agent")
            {
                FileLocation = "/Content/userupload/Agent/kyc/";
            }
            else if (usertype.ToLower() == "sub-agent")
            {
                FileLocation = "/Content/userupload/SubAgent/kyc/";
            }
            else
            {
                FileLocation = "/Content/userupload/";
            }

            ViewBag.FileLocation = FileLocation;
            #endregion
            if (String.IsNullOrEmpty(kycModel.AgentId))
            {
                return(RedirectToAction("Index", ControllerName));
            }
            string status = "";
            if (submitbutton.ToUpper() == "REJECT")
            {
                status = "r";
                if (kycModel.Remarks.ToUpper().Equals("OTHERS"))
                {
                    if (OthersRemarks == "")
                    {
                        ModelState.AddModelError("OtherRemarks", "Other Remarks is Required");
                        return(View(kycModel));
                    }
                    else
                    {
                        kycModel.Remarks = "Others::" + OthersRemarks;
                    }
                }
                RejectValidation();
            }
            else if (submitbutton.ToUpper() == "APPROVE")
            {
                status = "a";
                ModelState.Remove(("Remarks"));
            }

            else
            {
                return(RedirectToAction("Index", ControllerName));
            }

            kycModel.ActionUser = Session["UserName"].ToString();
            kycModel.AgentId    = kycModel.AgentId.DecryptParameter();
            KYCCommon        kycCommon  = kycModel.MapObject <KYCCommon>();
            CommonDbResponse dbResponse = _kyc.UpadateKycDetails(kycCommon, status);
            dbResponse.SetMessageInTempData(this);
            return(RedirectToAction("Index"));
        }
        public ActionResult Kyc(KYCModel clientkyc, HttpPostedFileBase PPImageFile, HttpPostedFileBase Id_DocumentFrontFile, HttpPostedFileBase Id_DocumentBackFile)
        {
            LoadDropDownList(clientkyc);
            string status = "u";

            ModelState.Remove(("Remarks"));
            #region FileLocation

            string FileLocation;
            string usertype = Session["UserType"].ToString();
            if (usertype.ToLower() == "distributor")
            {
                FileLocation = "/Content/userupload/Distributor/kyc/";
            }
            else if (usertype.ToLower() == "sub-distributor")
            {
                FileLocation = "/Content/userupload/SubDistributor/kyc/";
            }
            else if (usertype.ToLower() == "walletuser")
            {
                FileLocation = "/Content/userupload/Walletuser/kyc/";
            }
            else if (usertype.ToLower() == "merchant")
            {
                FileLocation = "/Content/userupload/Merchant/kyc/";
            }
            else if (usertype.ToLower() == "agent")
            {
                FileLocation = "/Content/userupload/Agent/kyc/";
            }
            else if (usertype.ToLower() == "sub-agent")
            {
                FileLocation = "/Content/userupload/SubAgent/kyc/";
            }
            else
            {
                FileLocation = "/Content/userupload/";
            }

            ViewBag.FileLocation = FileLocation;
            #endregion

            if ((Id_DocumentFrontFile == null && string.IsNullOrEmpty(clientkyc.Id_DocumentFront)) ||
                (PPImageFile == null && string.IsNullOrEmpty(clientkyc.PPImage)) ||
                (Id_DocumentBackFile == null && string.IsNullOrEmpty(clientkyc.Id_DocumentBack) && clientkyc.Id_type.ToUpper() == "CITIZENSHIP"))
            {
                if (Id_DocumentFrontFile == null && string.IsNullOrEmpty(clientkyc.Id_DocumentFront))
                {
                    ModelState.AddModelError("Id_DocumentFront", "Document Front Image is Required");
                }
                if (PPImageFile == null && string.IsNullOrEmpty(clientkyc.PPImage))
                {
                    ModelState.AddModelError("PPImage", "Profile Image is Required");
                }
                if ((Id_DocumentBackFile == null && string.IsNullOrEmpty(clientkyc.Id_DocumentBack) && clientkyc.Id_type.ToUpper() == "CITIZENSHIP"))
                {
                    ModelState.AddModelError("Id_DocumentBack", "Document Front Image is Required");
                }
                return(View(clientkyc));
            }

            if (clientkyc.Id_type.ToUpper() == "CITIZENSHIP")
            {
                //if (Id_DocumentBackFile == null && string.IsNullOrEmpty(clientkyc.Id_DocumentBack))
                //{
                //    ModelState.AddModelError("Id_DocumentBack", "Document Front Image is Required");
                //    return View(clientkyc);
                //}
                ModelState.Remove(("Id_ExpiryDateAD"));
                ModelState.Remove(("Id_ExpiryDateBS"));
            }

            var PPImagePath          = "";
            var Id_DocumentFrontPath = "";
            var Id_DocumentBackPath  = "";

            string temp_address = clientkyc.SameAsPermanentAddress.ToString();
            if (temp_address == "True")
            {
                clientkyc.TProvince  = clientkyc.PProvince;
                clientkyc.TDistrict  = clientkyc.PDistrict;
                clientkyc.TLocalBody = clientkyc.PLocalBody;
                clientkyc.TWardNo    = clientkyc.PWardNo;
                clientkyc.TAddress   = clientkyc.PAddress;
            }

            if (ModelState.IsValid)
            {
                //clientkyc.Remarks = String.IsNullOrEmpty(clientkyc.Remarks) ? "" :
                //  clientkyc.Remarks.ToUpper().Equals("OTHERS") ? OthersRemarks : clientkyc.Remarks;

                clientkyc.ActionUser = Session["UserName"].ToString();

                #region "PPImage"
                if (PPImageFile != null && status.ToUpper() == "U")
                {
                    var    allowedExtensions = new[] { ".jpg", ".png", ".jpeg" };
                    var    fileName          = Path.GetFileName(PPImageFile.FileName);
                    String timeStamp         = DateTime.Now.ToString();
                    var    ext = Path.GetExtension(PPImageFile.FileName);
                    if (PPImageFile.ContentLength > 1 * 1024 * 1024)//1 MB
                    {
                        return(RedirectToAction("Kyc", ControllerName));
                    }
                    if (allowedExtensions.Contains(ext.ToLower()))
                    {
                        string datet      = timeStamp.Replace('/', '-').Replace(':', '-');
                        string myfilename = clientkyc.MobileNo + "-PPImage-" + datet + ext;
                        PPImagePath       = Path.Combine(Server.MapPath(FileLocation), myfilename);
                        clientkyc.PPImage = FileLocation + myfilename;
                        //PPImageFile.SaveAs(PPImagePath);
                    }
                    else
                    {
                        return(RedirectToAction("Kyc", ControllerName));
                    }
                }
                #endregion
                #region "Id_DocumentFront"
                if (Id_DocumentFrontFile != null && status.ToUpper() == "U")
                {
                    var    allowedExtensions = new[] { ".jpg", ".png", ".jpeg" };
                    var    fileName          = Path.GetFileName(Id_DocumentFrontFile.FileName);
                    String timeStamp         = DateTime.Now.ToString();
                    var    ext = Path.GetExtension(Id_DocumentFrontFile.FileName);
                    if (Id_DocumentFrontFile.ContentLength > 1 * 1024 * 1024)//1 MB
                    {
                        return(RedirectToAction("Kyc", ControllerName));
                    }
                    if (allowedExtensions.Contains(ext.ToLower()))
                    {
                        string datet      = timeStamp.Replace('/', '-').Replace(':', '-');
                        string myfilename = clientkyc.MobileNo + "-Id_DocumentFront-" + datet + ext;
                        Id_DocumentFrontPath       = Path.Combine(Server.MapPath(FileLocation), myfilename);
                        clientkyc.Id_DocumentFront = FileLocation + myfilename;
                        //Id_DocumentFrontFile.SaveAs(Id_DocumentFrontPath);
                    }
                    else
                    {
                        return(RedirectToAction("Kyc", ControllerName));
                    }
                }
                #endregion
                #region "Id_DocumentBack"
                if (Id_DocumentBackFile != null && status.ToUpper() == "U")
                {
                    var    allowedExtensions = new[] { ".jpg", ".png", ".jpeg" };
                    var    fileName          = Path.GetFileName(Id_DocumentBackFile.FileName);
                    String timeStamp         = DateTime.Now.ToString();
                    var    ext = Path.GetExtension(Id_DocumentBackFile.FileName);
                    if (Id_DocumentBackFile.ContentLength > 1 * 1024 * 1024)//1 MB
                    {
                        return(RedirectToAction("Kyc", ControllerName));
                    }
                    if (allowedExtensions.Contains(ext.ToLower()))
                    {
                        string datet      = timeStamp.Replace('/', '-').Replace(':', '-');
                        string myfilename = clientkyc.MobileNo + "-Id_DocumentBack-" + datet + ext;
                        Id_DocumentBackPath       = Path.Combine(Server.MapPath(FileLocation), myfilename);
                        clientkyc.Id_DocumentBack = FileLocation + myfilename;
                        //Id_DocumentBackFile.SaveAs(Id_DocumentBackPath);
                    }
                    else
                    {
                        return(RedirectToAction("Kyc", ControllerName));
                    }
                }
                #endregion
                KYCCommon        kycCommon  = clientkyc.MapObject <KYCCommon>();
                CommonDbResponse dbResponse = _kyc.UpadateKycDetails(kycCommon, status);
                if (dbResponse.Code == 0)
                {
                    //SaveImages On Success
                    if (PPImagePath != "")
                    {
                        PPImageFile.SaveAs(PPImagePath);
                    }
                    if (Id_DocumentFrontPath != "")
                    {
                        Id_DocumentFrontFile.SaveAs(Id_DocumentFrontPath);
                    }
                    if (Id_DocumentBackPath != "")
                    {
                        Id_DocumentBackFile.SaveAs(Id_DocumentBackPath);
                    }
                    //Ends SaveImages
                }
                dbResponse.SetMessageInTempData(this);
                return(RedirectToAction("Profile"));
            }
            return(View(clientkyc));
        }