using Business.Configuration; using Business.Customer; using Common.Helper; using Common.Model.CustomerModel; using Common.Utility; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace JMEAgentSystem.WebPages.AddIdPicture { public partial class Manage : System.Web.UI.Page { private readonly ICustomerServices _customerServices = AutoFacContainer.Resolve(); protected void Page_Load(object sender, EventArgs e) { } protected void upload_Click(object sender, EventArgs e) { try { //checked file extention HttpFileCollection fileCollectionNew = Request.Files; string documentExtension = GetStatic.ReadWebConfig("customerDocFileExtension", ""); for (int i = 0; i < fileCollectionNew.AllKeys.Length; i++) { HttpPostedFile file = fileCollectionNew[i]; string fileExtension = new FileInfo(file.FileName).Extension; if (!documentExtension.ToLower().Contains(fileExtension.ToLower())) { GetStatic.AlertMessage(this, "Invalid File Extenstion"); return; } } DbResult response = saveCustomerDocument(); GetStatic.AlertMessage(this.Page, response.Msg); } catch (Exception ex) { GetStatic.AlertMessage(this.Page, ex.Message); } } private DbResult saveCustomerDocument() { HttpFileCollection fileCollection = Request.Files; DbResult res = new DbResult(); for (int i = 0; i < fileCollection.AllKeys.Length; i++) { HttpPostedFile file = fileCollection[i]; if (file != null) { string documentTypeName = ""; string documentType = ""; string fileType = ""; if (i == 0) { documentTypeName = "Alien Registration Card(Front)"; documentType = "11054"; } else { documentTypeName = "Alien Registration Card(Back)"; documentType = "11055"; } string fileName = (!string.IsNullOrWhiteSpace(file.FileName) ? UploadDocument(file, GetStatic.GetUser(), documentTypeName, out fileType) : UploadDocument(file, GetStatic.GetUser(), documentTypeName, out fileType)); CustomerDocument cm = new CustomerDocument(); cm.customerId = ""; cm.fileDescription = ""; cm.documentType = documentType; cm.fileUrl = fileName; cm.fileType = fileType; res = _customerServices.UpdateCustomerDocument("", "0", fileName, documentType, "image/png", documentType, GetStatic.GetUser()); } } return res; } private string UploadDocument(HttpPostedFile doc, string user, string documentTypeName, out string fileType) { fileType = ""; string fName = ""; try { fileType = doc.ContentType; string fileExtension = new FileInfo(doc.FileName).Extension; string documentExtension = GetStatic.ReadWebConfig("customerDocFileExtension", ""); if (documentExtension.ToLower().Contains(fileExtension.ToLower())) { string fileName = user + "_" + documentTypeName + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString() + fileExtension; string path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + "ID Collection\\" + user; if (!Directory.Exists(path)) Directory.CreateDirectory(path); doc.SaveAs(path + "/" + fileName); fName = fileName; } else { fName = "notValid"; } } catch (Exception ex) { fName = ""; } return fName; } } }