You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.6 KiB

4 years ago
  1. using Business.Configuration;
  2. using Business.Customer;
  3. using Common.Helper;
  4. using Common.Model.CustomerModel;
  5. using Common.Utility;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Web;
  11. using System.Web.UI;
  12. using System.Web.UI.WebControls;
  13. namespace JMEAgentSystem.WebPages.AddIdPicture
  14. {
  15. public partial class Manage : System.Web.UI.Page
  16. {
  17. private readonly ICustomerServices _customerServices = AutoFacContainer.Resolve<ICustomerServices>();
  18. protected void Page_Load(object sender, EventArgs e)
  19. {
  20. }
  21. protected void upload_Click(object sender, EventArgs e)
  22. {
  23. try
  24. {
  25. //checked file extention
  26. HttpFileCollection fileCollectionNew = Request.Files;
  27. string documentExtension = GetStatic.ReadWebConfig("customerDocFileExtension", "");
  28. for (int i = 0; i < fileCollectionNew.AllKeys.Length; i++)
  29. {
  30. HttpPostedFile file = fileCollectionNew[i];
  31. string fileExtension = new FileInfo(file.FileName).Extension;
  32. if (!documentExtension.ToLower().Contains(fileExtension.ToLower()))
  33. {
  34. GetStatic.AlertMessage(this, "Invalid File Extenstion");
  35. return;
  36. }
  37. }
  38. DbResult response = saveCustomerDocument();
  39. GetStatic.AlertMessage(this.Page, response.Msg);
  40. }
  41. catch (Exception ex)
  42. {
  43. GetStatic.AlertMessage(this.Page, ex.Message);
  44. }
  45. }
  46. private DbResult saveCustomerDocument()
  47. {
  48. HttpFileCollection fileCollection = Request.Files;
  49. DbResult res = new DbResult();
  50. for (int i = 0; i < fileCollection.AllKeys.Length; i++)
  51. {
  52. HttpPostedFile file = fileCollection[i];
  53. if (file != null)
  54. {
  55. string documentTypeName = "";
  56. string documentType = "";
  57. string fileType = "";
  58. if (i == 0)
  59. {
  60. documentTypeName = "Alien Registration Card(Front)";
  61. documentType = "11054";
  62. }
  63. else
  64. {
  65. documentTypeName = "Alien Registration Card(Back)";
  66. documentType = "11055";
  67. }
  68. string fileName = (!string.IsNullOrWhiteSpace(file.FileName) ? UploadDocument(file, GetStatic.GetUser(), documentTypeName, out fileType) : UploadDocument(file, GetStatic.GetUser(), documentTypeName, out fileType));
  69. CustomerDocument cm = new CustomerDocument();
  70. cm.customerId = "";
  71. cm.fileDescription = "";
  72. cm.documentType = documentType;
  73. cm.fileUrl = fileName;
  74. cm.fileType = fileType;
  75. res = _customerServices.UpdateCustomerDocument("", "0", fileName, documentType, "image/png", documentType, GetStatic.GetUser());
  76. }
  77. }
  78. return res;
  79. }
  80. private string UploadDocument(HttpPostedFile doc, string user, string documentTypeName, out string fileType)
  81. {
  82. fileType = "";
  83. string fName = "";
  84. try
  85. {
  86. fileType = doc.ContentType;
  87. string fileExtension = new FileInfo(doc.FileName).Extension;
  88. string documentExtension = GetStatic.ReadWebConfig("customerDocFileExtension", "");
  89. if (documentExtension.ToLower().Contains(fileExtension.ToLower()))
  90. {
  91. string fileName = user + "_" + documentTypeName + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString() + fileExtension;
  92. string path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + "ID Collection\\" + user;
  93. if (!Directory.Exists(path))
  94. Directory.CreateDirectory(path);
  95. doc.SaveAs(path + "/" + fileName);
  96. fName = fileName;
  97. }
  98. else
  99. {
  100. fName = "notValid";
  101. }
  102. }
  103. catch (Exception ex)
  104. {
  105. fName = "";
  106. }
  107. return fName;
  108. }
  109. }
  110. }