Example #1
0
        public ActionResult Manage(DistributorCommon DModel, HttpPostedFileBase Agent_Logo, HttpPostedFileBase Pan_Certiticate, HttpPostedFileBase Registration_Certificate)
        {
            string DistId                       = "";
            var    Agent_LogoPath               = "";
            var    Pan_CertiticatePath          = "";
            var    Registration_CertificatePath = "";
            string op_type                      = DModel.AgentOperationType;

            //string temp_address = DModel..ToString();
            DistId = DModel.AgentID;
            if (!string.IsNullOrEmpty(DModel.AgentID))
            {
                RemoveUpdateValidation(DModel);
                ModelState.Remove("ContactPersonIDExpiryDate");
                ModelState.Remove("ContactPersonIDExpiryDate_BS");
            }
            if (DModel.AgentOperationType == "Individual")
            {
                RemoveContactPersonValidation(DModel);
            }
            LoadDropDownList(DModel);
            if (ModelState.IsValid)
            {
                string username = Session["UserName"].ToString();
                if (!string.IsNullOrEmpty(DModel.AgentID))
                {
                    if (string.IsNullOrEmpty(DModel.AgentID.DecryptParameter()))
                    {
                        return(View("Manage", DModel));
                    }
                    DModel.AgentID = DModel.AgentID.DecryptParameter();
                }

                DModel.ActionUser = Session["username"].ToString();
                DModel.IpAddress  = ApplicationUtilities.GetIP();


                if (Pan_Certiticate != null)
                {
                    var    allowedExtensions = new[] { ".jpg", ".png", ".jpeg" };
                    var    fileName          = Path.GetFileName(Pan_Certiticate.FileName);
                    String timeStamp         = DateTime.Now.ToString();
                    var    ext = Path.GetExtension(Pan_Certiticate.FileName);
                    if (Pan_Certiticate.ContentLength > 1 * 1024 * 1024)//1 MB
                    {
                        this.ShowPopup(1, "Image Size must be less than 1MB");
                        return(View(DModel));
                    }
                    if (allowedExtensions.Contains(ext.ToLower()))
                    {
                        string datet      = DateTime.Now.ToString().Replace('/', ' ').Replace(':', ' ');
                        string myfilename = "logo " + datet + "." + Pan_Certiticate.FileName;
                        Pan_CertiticatePath        = Path.Combine(Server.MapPath("~/Content/assets/images/distributor_image"), myfilename);
                        DModel.AgentPanCertificate = myfilename;
                    }
                    else
                    {
                        this.ShowPopup(1, "File Must be .jpg,.png,.jpeg");
                        return(View(DModel));
                    }
                }

                if (Registration_Certificate != null)
                {
                    var    allowedExtensions = new[] { ".jpg", ".png", ".jpeg" };
                    var    fileName          = Path.GetFileName(Registration_Certificate.FileName);
                    String timeStamp         = DateTime.Now.ToString();
                    var    ext = Path.GetExtension(Registration_Certificate.FileName);
                    if (Registration_Certificate.ContentLength > 1 * 1024 * 1024)//1 MB
                    {
                        this.ShowPopup(1, "Image Size must be less than 1MB");
                        return(View(DModel));
                    }
                    if (allowedExtensions.Contains(ext.ToLower()))
                    {
                        string datet      = DateTime.Now.ToString().Replace('/', ' ').Replace(':', ' ');
                        string myfilename = "logo " + datet + "." + Registration_Certificate.FileName;
                        Registration_CertificatePath        = Path.Combine(Server.MapPath("~/Content/assets/images/distributor_image"), myfilename);
                        DModel.AgentRegistrationCertificate = myfilename;
                        //Registration_Certificate.SaveAs(path);
                    }
                    else
                    {
                        this.ShowPopup(1, "File Must be .jpg,.png,.jpeg");
                        return(View(DModel));
                    }
                }

                if (Agent_Logo != null)
                {
                    var    allowedExtensions = new[] { ".jpg", ".png", ".jpeg" };
                    var    fileName          = Path.GetFileName(Agent_Logo.FileName);
                    String timeStamp         = DateTime.Now.ToString();
                    var    ext = Path.GetExtension(Agent_Logo.FileName);
                    if (Agent_Logo.ContentLength > 1 * 1024 * 1024)//1 MB
                    {
                        this.ShowPopup(1, "Image Size must be less than 1MB");
                        return(View(DModel));
                    }
                    if (allowedExtensions.Contains(ext.ToLower()))
                    {
                        string datet      = DateTime.Now.ToString().Replace('/', ' ').Replace(':', ' ');
                        string myfilename = "logo " + datet + "." + Agent_Logo.FileName;
                        Agent_LogoPath   = Path.Combine(Server.MapPath("~/Content/assets/images/distributor_image"), myfilename);
                        DModel.AgentLogo = myfilename;
                    }
                    else
                    {
                        this.ShowPopup(1, "File Must be .jpg,.png,.jpeg");
                        return(View(DModel));
                    }
                }
                //DModel.DistributorId = DModel.DistributorId.DecryptParameter();
                CommonDbResponse dbresp = _distributor.ManageDistributor(DModel, username);

                if (dbresp.Code == 0)
                // if (dbresp.Code == shared.Models.ResponseCode.Success)
                {
                    if (!string.IsNullOrEmpty(Agent_LogoPath))
                    {
                        Agent_Logo.SaveAs(Agent_LogoPath);
                    }
                    if (!string.IsNullOrEmpty(Registration_CertificatePath))
                    {
                        Registration_Certificate.SaveAs(Registration_CertificatePath);
                    }
                    if (!string.IsNullOrEmpty(Pan_CertiticatePath))
                    {
                        Pan_Certiticate.SaveAs(Pan_CertiticatePath);
                    }
                    //SaveImages On Success
                    //Ends SaveImages
                    this.ShowPopup(0, "Saved Succesfully");
                    return(RedirectToAction("Index"));
                }
            }
            this.ShowPopup(1, "Please fill out all the field stating * (Mandatory)");
            return(View(DModel));
        }