public ActionResult Index(CustomerRegistration Cust, IEnumerable <HttpPostedFileBase> file) { if (ModelState.IsValid) { try { if (Request.Form["Submit"] != null) { string FirstName = "", LastName = "", Email = "", Phone1 = "", Phone2 = "", Phone3 = "", Password = "", TempPass = "", ZipCode = "", ProfilePhoto = "", HouseType = "", Address = "", IsCars = "", Occupation = "", CompanyName = "", Phone = "", FieldName1 = "", RenamedImageName = "", FileName2 = ""; int NoOfCars = 0, UserId; //bool IsHavingCars = false; List <spUpdateCustomerForWeb_Result> CustDetails = null; UserId = Convert.ToInt32(Session["UserId"].ToString()); if (Cust.FirstName != null) { FirstName = Cust.FirstName.ToString(); Session["FirstName"] = FirstName; } if (Cust.LastName != null) { LastName = Cust.LastName.ToString(); Session["LastName"] = LastName; } if (Cust.PhoneNo1 != null) { Phone1 = Cust.PhoneNo1.ToString(); } Phone = Phone1;//Change 29Dec16 if (Cust.ZipCode != null) { ZipCode = Cust.ZipCode.ToString(); } if (Cust.HouseType != null) { HouseType = Cust.HouseType.ToString(); } if (Cust.Address != null) { Address = Cust.Address.ToString(); } if (Cust.IsCars != null) { IsCars = Cust.IsCars.ToString(); } if (Cust.NumberofCars != null) { if (IsCars == "Yes") { NoOfCars = Convert.ToInt32(Cust.NumberofCars.ToString()); } else { NoOfCars = 0; } } if (Cust.Occupation != null) { if (Cust.Occupation.ToString() == "Business Owner") { Occupation = "Self Employed"; } else { Occupation = Cust.Occupation.ToString(); } } if (Cust.CompanyName != null) { CompanyName = Cust.CompanyName.ToString(); } //Save Details of Profile Picture if (Cust.IsProfilePhotoChanged == "Yes") { if (file == null) { } else { foreach (var f in file) { if (f != null) { if (f.ContentLength > 0) { int MaxContentLength = 1024 * 1024 * 4; //Size = 4 MB string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".pdf", ".jpe", ".jpeg" }; if (!AllowedFileExtensions.Contains (f.FileName.Substring(f.FileName.LastIndexOf('.')).ToLower())) { ModelState.AddModelError("File", "Please file of type: " + string.Join(", ", AllowedFileExtensions)); } else if (f.ContentLength > MaxContentLength) { ModelState.AddModelError("File", "Your file is too large, maximum allowed size is: " + MaxContentLength + " MB"); } else { var fileName = Path.GetFileName(f.FileName); //var Name = Path.GetFileNameWithoutExtension(f.FileName); var path = Path.Combine(Server.MapPath("~/UploadedDoc"), fileName); //Save file on server. //f.SaveAs(path); //Convert input file to Base 64 string byte[] binaryData; binaryData = new Byte[f.InputStream.Length]; long bytesRead = f.InputStream.Read(binaryData, 0, (int)f.InputStream.Length); f.InputStream.Close(); string base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length); string FileName1 = ""; string FieldName = ""; string ProfilePicFile = ""; string ProfilePic = Cust.ProfilePhoto.ToString().Replace("C:\\fakepath\\", ""); if (ProfilePic == fileName) { FileName1 = System.Web.HttpContext.Current.Server.MapPath("~/ProfilePicture/" + Cust.Email.ToString() + "_" + UserId + ".txt"); FieldName = "ProfilePicture"; FileName2 = Cust.Email.ToString() + "_" + UserId + ".txt"; ProfilePicFile = System.Web.HttpContext.Current.Server.MapPath("~/UploadedImages/ProfilePicture/" + Cust.Email.ToString() + "_" + UserId + ".png"); bool CheckFile1 = BrokerUtility.CheckFile(ProfilePicFile); byte[] imageBytes1 = Convert.FromBase64String(base64String); //MemoryStream ms1 = new MemoryStream(imageBytes1, 0, imageBytes1.Length); MemoryStream ms1 = new MemoryStream(binaryData, 0, binaryData.Length); //ms1.Write(imageBytes1, 0, imageBytes1.Length); ms1.Write(binaryData, 0, binaryData.Length); System.Drawing.Image image1 = System.Drawing.Image.FromStream(ms1, true); //image1.Save(System.Web.HttpContext.Current.Server.MapPath("~/UploadedImages/ProfilePicture/" + Cust.Email.ToString() + "_" + UserId + ".png"), System.Drawing.Imaging.ImageFormat.Png); System.Drawing.Image thumbnail = image1.GetThumbnailImage(200, 200, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); thumbnail.Save(System.Web.HttpContext.Current.Server.MapPath("~/UploadedImages/ProfilePicture/" + Cust.Email.ToString() + "_" + UserId + ".png"), System.Drawing.Imaging.ImageFormat.Png); FieldName1 = "ProfilePictureImg"; RenamedImageName = Cust.Email.ToString() + "_" + UserId + ".png"; //Check for the file already exist or not bool CheckFile = BrokerUtility.CheckFile(FileName1); if (CheckFile) { //Create a text file of Base 64 string bool result = BrokerUtility.WriteFile(FileName1, base64String); } } } } } } } } else { } //Save the Details of Customer CustDetails = BrokerWebDB.BrokerWebDB.SaveCustomerProfileDetails(FirstName, LastName, Phone, Address, ZipCode, HouseType, IsCars, NoOfCars, Occupation, CompanyName, FileName2, RenamedImageName, Cust.IsProfilePhotoChanged, UserId, "", "", ""); if (CustDetails.Count > 0) { //TempData["CustDetails"] = Cust; return(RedirectToAction("CustomerProfile", "Profile")); } else { return(View()); } //BrokerUtility.SaveCustomerBasicDetails(FirstName, LastName, Phone, Email, Address, ZipCode, TempPass, Encryptrandom, HouseType, IsCars, NoOfCars, Occupation, CompanyName); } else if (Request.Form["Cancel"] != null) { //TempData["CustDetails"] = Cust; return(RedirectToAction("CustomerProfile", "Profile")); //return View("","") } } catch (Exception Ex) { BrokerUtility.ErrorLog(Convert.ToInt32(Session["UserId"].ToString()), "Index_POST_Wesite", Ex.Message.ToString(), "CustomerRegistrationController.cs_Index_POST", BrokerUtility.GetIPAddress(Session["UserId"].ToString())); return(View()); } return(View()); } else { return(View()); } }
public ActionResult APSPCustomerSignUp(MeinekeCustomerSignUp Cust, IEnumerable <HttpPostedFileBase> file) { if (ModelState.IsValid) { try { string FirstName = "", LastName = "", Email = "", Phone1 = "", Phone2 = "", Phone3 = "", Password = "", TempPass = "", ZipCode = "", ProfilePhoto = "", HouseType = "", Address = "", IsCars = "", Occupation = "", CompanyName = "", Phone = "", FieldName1 = "", RenamedImageName = "", FileName2 = "", NoofEmployee = "", EstPremium = "", Website = ""; int NoOfCars = 0, UserId = 0; List <uspSaveCustomerBasicDetails_Result> User1 = null; //UserId = Convert.ToInt32(Session["UserId"].ToString()); if (Cust.FirstName != null) { FirstName = Cust.FirstName.ToString(); } if (Cust.LastName != null) { LastName = Cust.LastName.ToString(); } if (Cust.CompanyName != null) { CompanyName = Cust.CompanyName.ToString(); } if (Cust.Address != null) { Address = Cust.Address.ToString(); } if (Cust.EmailId != null) { Email = Cust.EmailId.ToString(); } if (Cust.PhoneNo != null) { Phone = Cust.PhoneNo.ToString(); } if (Cust.Website != null) { Website = Cust.Website.ToString(); } if (Cust.ZipCode != null) { ZipCode = Cust.ZipCode.ToString(); } if (Cust.NoofEmployees != null) { NoofEmployee = Cust.NoofEmployees.ToString(); } if (Cust.EstPremium != null) { EstPremium = Cust.EstPremium.ToString(); } string random = BrokerWSUtility.GetRandomNumber(); string Encryptrandom = BrokerUtility.EncryptURL(random); Session["random"] = Encryptrandom; User1 = BrokerUtility.SaveCustomerBasicDetails(FirstName, LastName, Phone, Email, Address, ZipCode, TempPass, Encryptrandom, HouseType, IsCars, NoOfCars, Occupation, CompanyName, NoofEmployee, EstPremium, Website, "APSP"); int Flag = 0; if (User1.Count > 0) { UserId = Convert.ToInt32(User1[0].UserId.ToString()); Session["UserId"] = UserId; Session["EmailId"] = User1[0].EmailId.ToString(); //////////////////// Access Profile Pic and Resume Files ////////////////////////// if (file == null) { } else { foreach (var f in file) { if (f != null) { if (f.ContentLength > 0) { int MaxContentLength = 1024 * 1024 * 4; //Size = 4 MB string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".pdf", ".jpe", ".jpeg" }; if (!AllowedFileExtensions.Contains (f.FileName.Substring(f.FileName.LastIndexOf('.')).ToLower())) { ModelState.AddModelError("File", "Please file of type: " + string.Join(", ", AllowedFileExtensions)); } else if (f.ContentLength > MaxContentLength) { ModelState.AddModelError("File", "Your file is too large, maximum allowed size is: " + MaxContentLength + " MB"); } else { var fileName = Path.GetFileName(f.FileName); //var Name = Path.GetFileNameWithoutExtension(f.FileName); var path = Path.Combine(Server.MapPath("~/UploadedDoc"), fileName); //Save file on server. //f.SaveAs(path); //Convert input file to Base 64 string byte[] binaryData; binaryData = new Byte[f.InputStream.Length]; long bytesRead = f.InputStream.Read(binaryData, 0, (int)f.InputStream.Length); f.InputStream.Close(); string base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length); string FileName1 = ""; // string FileName2 = ""; string FieldName = ""; string ProfilePic = Cust.ProfilePicture.ToString().Replace("C:\\fakepath\\", ""); if (ProfilePic == fileName) { FileName1 = System.Web.HttpContext.Current.Server.MapPath("~/ProfilePicture/" + Cust.EmailId.ToString() + "_" + UserId + ".txt"); FieldName = "ProfilePicture"; FileName2 = Cust.EmailId.ToString() + "_" + UserId + ".txt"; //Save Image on Server also. // Convert byte[] to Image byte[] imageBytes1 = Convert.FromBase64String(base64String); MemoryStream ms1 = new MemoryStream(imageBytes1, 0, imageBytes1.Length); ms1.Write(imageBytes1, 0, imageBytes1.Length); System.Drawing.Image image1 = System.Drawing.Image.FromStream(ms1, true); //image1.Save(System.Web.HttpContext.Current.Server.MapPath("~/UploadedImages/ProfilePicture/" + Email + "_" + UserId + ".png"), System.Drawing.Imaging.ImageFormat.Png); System.Drawing.Image thumbnail = image1.GetThumbnailImage(200, 200, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); thumbnail.Save(System.Web.HttpContext.Current.Server.MapPath("~/UploadedImages/ProfilePicture/" + Email + "_" + UserId + ".png"), System.Drawing.Imaging.ImageFormat.Png); FieldName1 = "ProfilePictureImg"; RenamedImageName = Cust.EmailId.ToString() + "_" + UserId + ".png"; } //Check for the file already exist or not bool CheckFile = BrokerUtility.CheckFile(FileName1); if (CheckFile) { //Create a text file of Base 64 string bool result = BrokerUtility.WriteFile(FileName1, base64String); if (result) { Flag = BrokerUtility.SaveBrokerFiles(FileName2, UserId, FieldName, FieldName1, RenamedImageName); } } } } } } } // Send Verification Link on Email Id //string random = BrokerWSUtility.GetRandomNumber(); bool EmailFlag = false; EmailFlag = BrokerWSUtility.SendRegistrationEmailFromWebSite(Session["EmailId"].ToString(), Session["random"].ToString(), Session["UserId"].ToString(), "Customer"); //EmailFlag = true; if (EmailFlag) { ViewBag.VerificationMessage = "You are registered successfully but yet not activated. "; ViewBag.VerificationMessage1 = "Please accept your verification email."; ViewBag.Company = "APSP"; return(View("CustomerSuccess")); } else { //If User registerd successfully, but verification link has not //been sent over EmailId //ViewBag.VerificationMessage = "You are registered successfully but yet not activated. <br/>Please accept your verification email."; ViewBag.Company = "APSP"; return(View("CustomerError")); } } } catch (Exception Ex) { BrokerUtility.ErrorLog(Convert.ToInt32(Session["UserId"].ToString()), "Index_POST_Wesite", Ex.Message.ToString(), "CustomerRegistrationController.cs_Index_POST", BrokerUtility.GetIPAddress(Session["UserId"].ToString())); return(View()); } return(View()); } return(View()); }