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.
 
 
 
 
 

139 lines
5.4 KiB

using Business.Configuration;
using Business.Customer;
using Common.Helper;
using Common.Model.CustomerModel;
using Common.Utility;
using Newtonsoft.Json;
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<ICustomerServices>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string reqMethod = Request.Form["MethodName"];
switch (reqMethod)
{
case "SavePhotoFromAjaxCall":
SavePhotoFromAjaxCall();
break;
}
}
}
private void SavePhotoFromAjaxCall()
{
var jsonString = "";
var dbResult = new DbResult();
HttpFileCollection fileCollectionNew = HttpContext.Current.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()))
{
dbResult.ErrorCode = "1";
dbResult.Msg = "Invalid File Extension";
jsonString = JsonConvert.SerializeObject(dbResult);
Response.ContentType = "application/json";
Response.Write(jsonString);
Response.End();
}
}
DbResult response = saveCustomerDocument();
jsonString = JsonConvert.SerializeObject(response);
Response.ContentType = "application/json";
Response.Write(jsonString);
Response.End();
}
private DbResult saveCustomerDocument()
{
try
{
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 = "ID_Front";
documentType = "11054";
}
else
{
documentTypeName = "ID_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;
}
catch (Exception ex)
{
return new DbResult() { ErrorCode = "1", Msg = ex.InnerException.ToString() };
}
}
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 = documentTypeName + "_" + GetStatic.GetDateTimeStamp() + "_" + GetStatic.GetUser() + "_" + 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;
}
}
}