Home
Home
Helpers;
using CCXWebServerSearch.Models;
using ICSharpCode.SharpZipLib.Zip;
using Nexsus.Cryptography;
using Nexsus.MessageLog;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.Hosting;
using System.Web.Mvc;
using System.Web.Security;
namespace CCXWebServerSearch.Controllers
{
public class HomeController : Controller
{
public static MessageLogger Log = new
MessageLogger(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "Log"));
public static string DBConnections = "Data Source=NEXSUS-DV62\\SQLEXPRESS;
Initial Catalog=CallConfineXWin; uid=sa; password=ccntspl@123";
SqlConnection con = new SqlConnection(DBConnections);
public static List<int> Permissions = new List<int>();
public static List<string> userpermissions = new List<string>();
CallDetails objCalldetails = new CallDetails();
MediaConverter objMediaConverter = new MediaConverter();
//static string constring =
getDBConnection.DecryptedConnectionString(DBConnections);
public static bool permission = false;
public static bool download = false;
private static bool checkConnection()
{
bool isConnected = false;
SqlConnection con = new SqlConnection(DBConnections);
try
{
Log.LogMessage(MessageLogger.MessageType.Info, "Attempting to
connect to database");
con.Open();
Log.LogMessage(MessageLogger.MessageType.Info, "Database connected
successfully.");
isConnected = true;
}
catch (Exception ex)
{
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
return isConnected;
[HttpGet]
public ActionResult Login()
{
Session.Clear();
Session.Abandon();
return View("Login");
}
[HttpPost]
public ActionResult Login(string uname, string pwd)
{
permission = false;
download = false;
try
{
if (String.IsNullOrEmpty(uname) || String.IsNullOrEmpty(pwd))
{
TempData["ErrorMessage"] = "Enter Username/Password";
return RedirectToAction("Login");
}
else
{
DBConnections = "Data Source=NEXSUS-DV62\\SQLEXPRESS; Initial
Catalog=CallConfineXWin; uid=sa; password=ccntspl@123";
if (checkConnection())
{
//string s =
ConfigurationManager.ConnectionStrings["dbconnstr"].ConnectionString;
//Session["UserID"] = uname;
//Log.LogMessage(MessageLogger.MessageType.Info, "Login
Successfully.");
//return RedirectToAction("Index");
conn.Open();
string query = "Select UserId from tblUserDetails where
UserName = @uname AND UserPwd = @pwd";
//conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
//Login Successfull
if(reader.Read())
{
string userId =
reader["UserID"].ToString();
Session["UserID"] = userId;
GetUserPermissions(Convert.ToInt32(Session["UserID"]));
return RedirectToAction("Index");
}
else
{
TempData["ErrorMessage"] = "Invalid Username or
Password";
}
}
}
//else
//{
// TempData["ErrorMessage"] = "Invalid
Username/Password";
// return RedirectToAction("Login");
//}
}
else
{
TempData["ErrorMessage"] = "Try After Some Time";
return RedirectToAction("Login");
}
}
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error, "In Login :" +
ex.Message);
TempData["Error"] = "ErrorOccured";
}
return View();
}
//============================EDITED===============================================
===//
public List<string> GetUserPermissions(int userId)
{
sqlconn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string permissionName =
reader["PermissionName"].ToString();
userpermissions.Add(permissionName);
}
}
}
return userpermissions;
}
//===========================================EDITED================================
=//
public ActionResult Index()
{
if (Session["UserID"] == null)
{
Session.Clear();
Session.Abandon();
return RedirectToAction("Login");
}
else
{
string userId = Convert.ToString(Session["UserID"]);
if (String.IsNullOrEmpty(userId))
{
Session.Clear();
Session.Abandon();
return RedirectToAction("Login");
}
else
{
string query2 = "Select PermissionID from tblUserProfile where
UserID=@userid";
using (SqlCommand cmd2 = new SqlCommand(query2, con))
{
cmd2.Parameters.AddWithValue("@userid",
Convert.ToInt32(Session["UserID"]));
con.Open();
SqlDataReader dr = cmd2.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Permissions.Add(Convert.ToInt32(dr[0]));
}
Log.LogMessage(MessageLogger.MessageType.Info,
"Permissions added successfully !!.");
}
else
{
Log.LogMessage(MessageLogger.MessageType.Info, "There
is no permissions for current user !!.");
}
con.Close();
}
ViewBag.field1 = null;
ViewBag.field2 = null;
Session["Field1"] =
Convert.ToString(ConfigurationManager.AppSettings["Field1"]);
Session["Field2"] =
Convert.ToString(ConfigurationManager.AppSettings["Field2"]);
SqlConnection sqlconn = new SqlConnection(DBConnections);
SqlCommand cmd = new SqlCommand("select APDesc from
tblAppParameter where APDetail2 IN ('Field1','Field2') ", sqlconn);
cmd.CommandTimeout = 1000;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet dsfields = new DataSet();
sda.Fill(dsfields);
DataTable fields = dsfields.Tables[0];
if (details.ExtensFrom != "")
{
extenFrom = Convert.ToInt32(details.ExtensFrom);
}
if (details.ExtensTo != "")
{
extenTo = Convert.ToInt32(details.ExtensTo);
}
if (details.CallerID != "")
{
searchQuery += "CallerID like '%" + details.CallerID + "%' AND ";
}
switch (details.CallType)
{
case "0": // all
searchQuery += " CallType >= 0 AND ";
break;
case "1": // In
searchQuery += " CallType = 1 AND ";
break;
case "2": //out
searchQuery += " CallType = 0 AND "; //0
break;
case "3": //miss
searchQuery += " CallType = 2 AND "; // 2
break;
case "4": //unknown
searchQuery += " CallType = 3 AND "; // 3
break;
long durationFrom = 0;
if (details.CallDurStr != "")
{
string[] splitFrom = details.CallDurStr.Split(':');
durationFrom = Convert.ToInt32(splitFrom[0]) * 60 * 60 +
Convert.ToInt32(splitFrom[1]) * 60 + Convert.ToInt32(splitFrom[2]);
//durationFrom = Convert.ToInt32(txtDurationGrt.Text);
}
long durationTo = 0;
if (details.CallDurEnd != "")
{
string[] splitTo = details.CallDurEnd.Split(':');
durationTo = Convert.ToInt32(splitTo[0]) * 60 * 60 +
Convert.ToInt32(splitTo[1]) * 60 + Convert.ToInt32(splitTo[2]);
//durationTo = Convert.ToInt32(txtDurationLess.Text);
}
if (durationFrom != 0)
searchQuery += " Seconds >= " + durationFrom + " AND ";
if (durationTo != 0)
searchQuery += " Seconds <= " + durationTo + " AND ";
if (details.TransType != "All")
searchQuery += " TransType like '%" + details.TransType + "%' AND
";
if (details.CustID != "")
searchQuery += " CustID like '%" + details.CustID + "%' AND ";
if (details.AgentName != "")
searchQuery += " AgentMaster.AgentName like '%" +
details.AgentName + "%' AND ";
if (details.CallerName != "")
searchQuery += " (FirstName +' ' + MiddleName + ' ' + LastName)
like '%" + details.CallerName + "%' AND ";
if (details.IsRegistered != "All")
searchQuery += " CallDetails.IsRegistered = '" +
details.IsRegistered + "' AND ";
if (details.ClientCode != "")
searchQuery += " CallDetails.ClientCode = '" + details.ClientCode +
"' AND ";
if (details.UserName != "") //Field2
searchQuery += " CallDetails.Field2 like '%" + details.UserName +
"%' AND ";
if (details.Comment != "")
searchQuery += " Comment like '%" + details.Comment + "%' AND ";
if (details.AgentID != 0)
searchQuery += " CallDetails.AgentID = " + details.AgentID + " AND
";
if (details.Producttype != "") //Field1
searchQuery += " CallDetails.Field1 = '" + details.Producttype +
"' AND ";
return searchQuery;
}
public JsonResult GetCallDetails()
{
try
{
if (userpermissions.Contains("View Call Log"))
{
objCalldetails.ExtensFrom =
Convert.ToString(Request.Form["ExtensFrom"]);
objCalldetails.ExtensTo =
Convert.ToString(Request.Form["ExtensTo"]);
objCalldetails.CallerID =
Convert.ToString(Request.Form["CallerID"]);
objCalldetails.FromDate =
Convert.ToString(Request.Form["FromDate"]);
objCalldetails.ToDate =
Convert.ToString(Request.Form["ToDate"]);
objCalldetails.CallType =
Convert.ToString(Request.Form["CallType"]);
objCalldetails.FromTime =
Convert.ToString(Request.Form["FromTime"]);
objCalldetails.ToTime =
Convert.ToString(Request.Form["ToTime"]);
objCalldetails.CallDurStr =
Convert.ToString(Request.Form["CallDurStr"]);
objCalldetails.CallDurEnd =
Convert.ToString(Request.Form["CallDurEnd"]);
objCalldetails.TransType =
Convert.ToString(Request.Form["TransType"]);
objCalldetails.CustID =
Convert.ToString(Request.Form["CustID"]);
objCalldetails.AgentName =
Convert.ToString(Request.Form["AgentName"]);
objCalldetails.CallerName =
Convert.ToString(Request.Form["CallerName"]);
objCalldetails.IsRegistered =
Convert.ToString(Request.Form["IsRegistered"]);
objCalldetails.ClientCode =
Convert.ToString(Request.Form["ClientCode"]);
objCalldetails.Comment =
Convert.ToString(Request.Form["Comment"]);
objCalldetails.CallID =
Convert.ToString(Request.Form["CallID"]);
objCalldetails.UserName =
Convert.ToString(Request.Form["Field2"]); //Field2
if (Request.Form["AgentID"] == "")
objCalldetails.AgentID = 0;
else
objCalldetails.AgentID =
Convert.ToInt32(Request.Form["AgentID"]);
objCalldetails.Producttype =
Convert.ToString(Request.Form["Field1"]); //Field1
if (objCalldetails.CallID != "")
{
// stringBuilderQuery.Append(" CallDetails.CallID = '" +
CallID + "' AND ");
if (objCalldetails.CallID != "")
searchQuery += " CallDetails.CallID = '" +
objCalldetails.CallID + "' AND ";
searchQuery += GetCallDetailsStringQuery(objCalldetails);
string role = "";
if (Permissions.Count() == 39)
{
role = "Admin";
}
if (role == "Admin")
{
}
else
{
string userName = Convert.ToString(Session["UserID"]);
if (userName != null)
{
string userid = Session["UserID"].ToString();
//int count = CheckAllExtensionAssigned(userid);
//if (count == 0)
//{
switch (GetGroupByValue())
{
case 0:
break;
case 1:
searchQuery += " dbo.CallDetails.Extension
in (select AssignedExtension from AssignedExtension where UserID = '" + userid +
"') AND";
break;
}
//}
}
}
}
else
{
searchQuery += GetCallDetailsStringQuery(objCalldetails);
//string role = Session["UserRole"].ToString();
string role = "";
if (Permissions.Count() == 39)
{
role = "Admin";
}
if (role == "Admin")
{
}
else
{
//// Populate the "Play" column with HTML for play button
//foreach (DataRow row in callDetails.Rows)
//{
// // Assuming CallerID is a unique identifier for the call
details
// string callerId = row["CallerID"].ToString(); // Replace
"CallerID" with your unique identifier column
// row["Play"] = "<span id=\"" + callerId + "\" ><img
src=\"../Content/images/play_1A.png\" id=\"" + callerId + "\"
onclick=\"ShowAudioPlayer(this)\" /></span>";
//}
if (userpermissions.Contains("Play Calls"))
{
callDetails.Columns.Add("Play", typeof(string));
row["Play"] = playButtonHtml;
}
}
if (userpermissions.Contains("Send To"))
{
callDetails.Columns.Add("Download", typeof(string)); // Add
Download column
string totalCallDetails =
Convert.ToString(callDetails.Rows.Count);
Session["CallDetails"] = callDetails;
return Json(
new
{
Status = "1",
Message = "",
TheadContent = theadContent,
ColBindData = columnBindData,
totalCallDetails = totalCallDetails
});
}
else
{
return Json(RedirectToAction("Index"));
}
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error, "Error in
GetCalldetails()." + ex.Message);
return Json(
new
{
Status = "0",
Message = ex.Message,
TheadContent = "",
ColBindData = ""
});
}
}
/*Changes*/
public ActionResult DownloadFileAudio(string fileName)
{
string[] parts = fileName.Split(new[] { ' ' },
StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 1)
{
// Extract the date part from the filename
string datePart = parts[1]; // "02-15-2022"
string[] dateComponents = datePart.Split('-'); // ["02", "15",
"2022"]
if (dateComponents.Length == 3)
{
string month = dateComponents[0]; // "02"
string day = dateComponents[1]; // "15"
string year = dateComponents[2]; // "2022"
/*Changes*/
[HttpPost]
public void PlayRecordedCall(string FileName)
{
System.Media.SoundPlayer wavPlayer = new System.Media.SoundPlayer();
wavPlayer.SoundLocation = FileName;
wavPlayer.Play();
}
[HttpPost]
public ActionResult LoadData(string DataCategory, bool isIevalue)
{
List<string> userPermissions =
GetUserPermissions(Convert.ToInt32(Session["UserID"]));
try
{
if (DataCategory != null)
{
string searchText = "", draw = "", start = "", length = "",
sortColumnDir = "", className = "";
int sortColumnPos;
draw = Request.Form.GetValues("draw").FirstOrDefault();
start = Request.Form.GetValues("start").FirstOrDefault();
length = Request.Form.GetValues("length").FirstOrDefault();
sortColumnPos =
Convert.ToInt16(Request.Form.GetValues("order[0][column]").FirstOrDefault());
sortColumnDir = Request.Form.GetValues("order[0]
[dir]").FirstOrDefault();
searchText =
Request.Form.GetValues("search[value]").FirstOrDefault();
if (DataCategory.ToUpper() == "RECONCILED")
{
if (Session["FinalOutput"] != null)
{
dt = Session["FinalOutput"] as DataTable;
className = "ReconData";
}
else
{
Session.Clear();
Session.Abandon();
return Json(new { draw = 0, recordsFiltered = 0,
recordsTotal = 0, data = "", statusFlag = "failed", redirectUrl = "/Home/Login" },
JsonRequestBehavior.AllowGet);
}
}
else if (DataCategory.ToUpper() == "CALLDETAILS")
{
if (Session["CallDetails"] != null)
{
dt = Session["CallDetails"] as DataTable;
className = "CallDetailsData";
}
else
{
Session.Clear();
Session.Abandon();
return Json(new { draw = 0, recordsFiltered = 0,
recordsTotal = 0, data = "", statusFlag = "failed", redirectUrl = "/Home/Login" },
JsonRequestBehavior.AllowGet);
}
}
else
{
dt = new DataTable();
className = "NA";
Log.LogMessage(MessageLogger.MessageType.Error, "Invalid
DataCategory of Grid data.");
return Json(new { draw = 0, recordsFiltered = 0,
recordsTotal = 0, data = "", statusFlag = "error" }, JsonRequestBehavior.AllowGet);
}
if (className == "ReconData")
{
}
else if (className == "CallDetailsData")
{
if (columnName == "Select")
{
string callerid =
dataRow[columnName].ToString();
property.SetValue(objClass, "<input
type=\"checkbox\" class=\"chkCheckBoxId\" id=\"" + callerid + "\" name=\"ID\"
value=\"" + callerid + "\">");
}
//else if (columnName == "Play")
//{
// //string userrole =
Session["UserRole"].ToString();
// //bool ispermission =
PlayPermission(userrole);
// if (userPermissions.Contains("Play Calls"))
// {
// string callerid =
dataRow[columnName].ToString();
// property.SetValue(objClass, "<span id=\""
+ callerid + "\" ><img src=\"../Content/images/play_1A.png\" id=\"" + callerid +
"\" onclick=\"ShowAudioPlayer(this)\" /></span>");
// }
// else
// {
// string callerid =
dataRow[columnName].ToString();
// //property.SetValue(objClass, "<span
id=\"" + callerid + "\" class=\"glyphicon glyphicon-play\" style=\"font-
size:20px;\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"You Don't
have Permission to Play Calls.\" ></span>");
// property.SetValue(objClass, "<span id=\""
+ callerid + "\" ><img src=\"../Content/images/Play_2.png\" id=\"" + callerid + "\"
data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"You Don't have Permission
to Play Calls.\" /></span>");
// }
//}
//else if (columnName == "Download")
//{
// string userrole =
Session["UserRole"].ToString();
// bool ispermission =
DownloadPermission(userrole);
// if (ispermission)
// {
// string callerid =
dataRow[columnName].ToString();
// string a =
Convert.ToString(Request.Url.GetLeftPart(UriPartial.Authority) +
Request.ApplicationPath);
// //property.SetValue(objClass, "<span
id=\"" + dataRow[columnName].ToString() + "\" class=\"glyphicon glyphicon-play\"
style=\"font-size:20px;\" onclick=\"ShowAudioPlayer(this)\"></span>");
// property.SetValue(objClass, "<span id=\""
+ callerid + "\" ><img src=\"../Content/images/download-(1A).png\" id=\"" +
callerid + "\" onclick=\"GetByID(id)\" /></span>");
// //property.SetValue(objClass, " <a id=\""
+ callerid + "\" class=\"glyphicon glyphicon-download-alt\" style=\"font-
size:20px;\" onclick=\"GetByID(id)\" ></a>");
// }
// else
// {
// string callerid =
dataRow[columnName].ToString();
// //property.SetValue(objClass, "<span
id=\"" + callerid + "\" class=\"glyphicon glyphicon-download-alt\" style=\"font-
size:20px;\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"You Don't
have Permission to Download Calls.\" ></span>");
// property.SetValue(objClass, "<span id=\""
+ callerid + "\" ><img src=\"../Content/images/download_1.png\" id=\"" + callerid +
"\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"You Don't have
Permission to Download Calls.\" /></span>");
// }
//}
else
{
property.SetValue(objClass,
dataRow[columnName].ToString());
}
}
else
{
property.SetValue(objClass,
dataRow[columnName].ToString());
}
i++;
}
lstClassData.Add(objClass);
}
List<object> lstReconObj =
lstClassData.Cast<object>().ToList<object>();
recordsTotal = lstReconObj.Count;
var data = lstReconObj.Skip(skip).Take(pageSize).ToList();
[HttpPost]
public ActionResult PlayAudioFile(string callID)
{
string FinalPath = @"D:\UlogFolder\NexsusCIL\2022\FEBRUARY\15"; // New
path
string file = "";
string fileName = "";
string OutputFileName = "";
string filepath = "";
string PlayPath = "";
string Final = "";
try
{
if (!callID.Contains(':'))
{
if (!string.IsNullOrEmpty(callID))
{
string userName = Convert.ToString(Session["UserID"]);
if (userName != null)
{
string userid = Session["UserID"].ToString();
file = callID;
if (fileName.StartsWith("S"))
{
string ip = GetIpAddress().ToString();
OutputFileName =
Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "tempvoicefile", userid,
ip);
if (!Directory.Exists(OutputFileName))
{
Directory.CreateDirectory(OutputFileName);
}
filepath = Path.Combine(OutputFileName,
fileName);
if (!System.IO.File.Exists(filepath))
{
client.
UploadFile(FinalPath, filepath);
}
if (System.IO.File.Exists(filepath))
{
PlayPath =
Convert.ToString(Request.Url.GetLeftPart(UriPartial.Authority) +
Request.ApplicationPath + "/tempvoicefile/" + userid + "/" + ip + "/" + fileName);
Final = PlayPath;
}
}
}
}
else
{
return RedirectToAction("Login");
}
}
}
else
{
file = callID;
FileInfo f = new FileInfo(file);
fileName = FinalPath.Split('/').Last();
if (fileName.StartsWith("S"))
{
string userName = Convert.ToString(Session["UserID"]);
if (userName != null)
{
string userid = Session["UserID"].ToString();
string ip = GetIpAddress().ToString();
OutputFileName =
Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "tempvoicefile", userid,
ip);
if (!Directory.Exists(OutputFileName))
{
Directory.CreateDirectory(OutputFileName);
}
fileName = FinalPath.Split('/').Last();
FinalPath =
Convert.ToString(Request.Url.GetLeftPart(UriPartial.Authority) +
Request.ApplicationPath + "/tempvoicefile/mp3/" + fileName);
Final = FinalPath;
}
else
{
FinalPath =
Convert.ToString(Request.Url.GetLeftPart(UriPartial.Authority) + playFile);
Final = FinalPath;
}
}
}
}
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error, "Play
File(Exception): " + ex.Message + " Play File Path: " + Final);
}
//This Method is created to Check Whether the user have Permission to play
call or not.
public bool PlayPermission(string uname)
{
int a = 0;
DBConnections =
ConfigurationManager.ConnectionStrings["dbconnstr"].ConnectionString;
//if (checkConnection())
//{
SqlConnection sqlconn = new SqlConnection(DBConnections);
SqlCommand cmd = new SqlCommand("GetRoles", sqlconn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
cmd.Parameters.AddWithValue("@Roles", uname);
cmd.Parameters.AddWithValue("@Permission", "Play Calls");
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable RoleDetails;
public void GetUserRole(string uname)
{
DBConnections =
ConfigurationManager.ConnectionStrings["dbconnstr"].ConnectionString;
//if (checkConnection())
//{
//SqlConnection sqlconn = new SqlConnection(DBConnections);
//SqlCommand cmd = new SqlCommand("GetUserRole_CCXWebSearch", sqlconn);
//cmd.CommandType = CommandType.StoredProcedure;
//cmd.CommandTimeout = 0;
//cmd.Parameters.AddWithValue("@Username", uname);
//SqlDataAdapter sda = new SqlDataAdapter(cmd);
//DataSet ds = new DataSet();
//sda.Fill(ds);
//RoleDetails = ds.Tables[0];
//}
}
[HttpPost]
public ActionResult GetById(object[] ID)
{
try
{
//int count = 0;
string FinalPath = "";
string file = "";
string fileName = "";
string path = ID[0].ToString();
string[] a = path.Split(',');
//int TotalCount = a.Count();
string OutputFileName = "";
string filepath = "";
//string DownloadPath = "";
//string Final = "";
string decryptedfilepath = "";
if (a.Count() > 1)
{
try
{
StringBuilder s = new StringBuilder();
for (int i = 0; i < a.Length; i++)
{
try
{
file = a[i];
string strFile = file.Replace(@"\", @"/");
string downloadFile = playFileInView(file);
if (downloadFile.StartsWith("//"))
FinalPath = downloadFile;
else
FinalPath = file;
if (fileName.StartsWith("S"))
{
OutputFileName =
Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "Downloadvoicefile");
if (!Directory.Exists(OutputFileName))
Directory.CreateDirectory(OutputFileName);
filepath = Path.Combine(OutputFileName,
fileName);
bool isDecrypted =
Cryptography.DecryptFile(file, decryptedfilepath);
if (isDecrypted)
{
s.Append(decryptedfilepath + ",");
}
else
{
if (System.IO.File.Exists(file))
{
string audiourl = file.ToString();
string audiofilechang =
audiourl.Replace(@"\", @"/");
string audiofile =
audiofilechang.Split('/').Last();
FileInfo f = new FileInfo(audiofile);
if (f.Extension == ".awb" || f.Extension ==
".amr")
{
OutputFileName =
Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "Downloadvoicefile");
if (!Directory.Exists(OutputFileName))
Directory.CreateDirectory(OutputFileName);
//filepath =
Path.Combine(OutputFileName, audiofile);
string finalfilename =
audiofile.Substring(0, audiofile.Length - 4) + ".mp3";
decryptedfilepath = OutputFileName +
@"\" + finalfilename;
bool isDecrypted =
Convertawbtomp3(file, decryptedfilepath);
if (isDecrypted)
{
s.Append(decryptedfilepath + ",");
}
}
else
{
s.Append(file + ",");
}
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error,
"Downloading File:" + file);
}
}
else
{
OutputFileName = "";
FinalPath = "";
filepath = "";
file = ID[0].ToString();
//filepath = Path.Combine(OutputFileName,
audiofile);
string finalfilename = audiofile.Substring(0,
audiofile.Length - 4) + ".mp3";
decryptedfilepath = OutputFileName + @"\" +
finalfilename;
bool isDecrypted =
Cryptography.DecryptFile(file, decryptedfilepath);
if (isDecrypted)
{
return Json(new { Success = "success", Path
= decryptedfilepath, Downloadtype = "single" }, JsonRequestBehavior.AllowGet);
}
}
else
{
Log.LogMessage(MessageLogger.MessageType.Info,
"Download File Path: " + ID);
}
}
else
{
if (System.IO.File.Exists(file))
{
OutputFileName =
Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "Downloadvoicefile");
if (!Directory.Exists(OutputFileName))
Directory.CreateDirectory(OutputFileName);
//filepath = Path.Combine(OutputFileName,
audiofile);
string finalfilename = audiofile.Substring(0,
audiofile.Length - 4) + ".mp3";
decryptedfilepath = OutputFileName + @"\" +
finalfilename;
}
else
{
Log.LogMessage(MessageLogger.MessageType.Info,
"Download File Path: " + ID);
}
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error,
"Download File Path: " + ID);
}
}
else
{
try
{
string strFile = file.Replace(@"\", @"/");
string downloadFile = playFileInView(file);
FileInfo f1 = new FileInfo(file);
if (f1.Extension == ".729")
{
if (System.IO.File.Exists(downloadFile))
{
return Json(new { Success = "success", Path =
downloadFile, Downloadtype = "single" }, JsonRequestBehavior.AllowGet);
}
}
if (downloadFile.StartsWith("//"))
FinalPath = downloadFile;
else
FinalPath = downloadFile;
filepath = Path.Combine(OutputFileName,
audiofile);
}
else
{
Log.LogMessage(MessageLogger.MessageType.Info,
"Download File Path: " + ID);
}
}
else
{
//OutputFileName =
Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "Downloadvoicefile");
//if (!Directory.Exists(OutputFileName))
// Directory.CreateDirectory(OutputFileName);
//filepath = Path.Combine(OutputFileName,
audiofile);
//filepath = Path.Combine(OutputFileName,
fileName);
}
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error,
"Download File Path: " + ID);
}
if (!
System.IO.Directory.Exists(Path.Combine(HostingEnvironment.ApplicationPhysicalPath
+ "TempZipFile")))
{
System.IO.Directory.CreateDirectory(Path.Combine(HostingEnvironment.ApplicationPhys
icalPath + "TempZipFile"));
}
// the path on the server where the temp file will be created!
tempFileName =
Path.Combine(HostingEnvironment.ApplicationPhysicalPath + "TempZipFile" + "\\
MyZip.zip");
filePath = filesCol[i];
string files = filesCol[i].Replace(@"\", @"/");
fileName = files.Split('/').Last();
}
countFiles++;
Log.LogMessage(MessageLogger.MessageType.Info, "Filepath:"
+ filePath);
}
else
{
Log.LogMessage(MessageLogger.MessageType.Info, "File not
Found : " + filePath);
}
}
zipOutputStream.Finish();
zipOutputStream.Close();
Response.ContentType = "application/x-zip-compressed";
//Response.AppendHeader("Content-Disposition", "attachment;
filename=" + DateTime.Now.ToString("MM/dd/yyyy HH:mm") + ".zip");
Response.AddHeader("Content-Disposition", "attachment; filename=" +
DateTime.Now.ToString("MM/dd/yyyy HH:mm") + ".zip");
Int64 fileSizeInBytes = new FileInfo(tempFileName).Length;
Response.AddHeader("Content-Length", fileSizeInBytes.ToString());
Response.WriteFile(tempFileName);
Response.Flush();
Response.Close();
Log.LogMessage(MessageLogger.MessageType.Info, "Sucessfully
Downloaded Zip File");
if (System.IO.File.Exists(tempFileName))
System.IO.File.Delete(tempFileName);
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error, ex.ToString());
}
[HttpPost]
public ActionResult GetPath(string FileCategory)
{
try
{
if (FileCategory.ToUpper() == "RECONCILED")
{
return Json(new { Success = "failed", FileName =
"/Home/Login" }, JsonRequestBehavior.AllowGet);
}
else if (FileCategory.ToUpper() == "CALLDETAILS")
{
DataTable dtCallDetails = Session["CallDetails"] as DataTable;
ExportToExcel(dtCallDetails, DateTime.Now.ToString("dd-MM-
yyyy"), "CallDetails");
if (Session["CallDetailsExcelPath"] != null)
{
string fileSavePath =
Session["CallDetailsExcelPath"].ToString();
return Json(new { Success = "success", FileName =
fileSavePath }, JsonRequestBehavior.AllowGet);
}
else
{
Session.Clear();
Session.Abandon();
Log.LogMessage(MessageLogger.MessageType.Error, "Error
while getting filePath of CALLDETAILS from Session in GetPath().");
return Json(new { Success = "failed", FileName =
"/Home/Login" }, JsonRequestBehavior.AllowGet);
}
}
else
{
Log.LogMessage(MessageLogger.MessageType.Error, "Incorrect file
requested.");
return Json(new { Success = "error" },
JsonRequestBehavior.AllowGet);
}
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error, "Error occured in
GetPath()." + ex.Message);
return Json(new { Success = "error" },
JsonRequestBehavior.AllowGet);
}
}
if (!Directory.Exists(info))
{
Directory.CreateDirectory(info);
}
if (DataCategory.ToUpper() == "RECONCILED")
{
Session["ReconExcelPath"] = fileSavePath;
}
else if (DataCategory.ToUpper() == "CALLDETAILS")
{
Session["CallDetailsExcelPath"] = fileSavePath;
}
try
{
StreamWriter wr = new StreamWriter(fileSavePath, false,
Encoding.Default);
if (DataCategory.ToUpper() == "CALLDETAILS")
{
// Only remove columns if they exist
if (dtToExcel.Columns.Contains("Select"))
dtToExcel.Columns.Remove("Select");
if (dtToExcel.Columns.Contains("Play"))
dtToExcel.Columns.Remove("Play");
if (dtToExcel.Columns.Contains("Download"))
dtToExcel.Columns.Remove("Download");
}
// Close file
wr.Close();
}
catch (IOException ex)
{
Log.LogMessage(MessageLogger.MessageType.Error, "Error occurred
while saving file to server in ExportToExcel(). " + ex.Message);
Session["ReconExcelPath"] = "";
Session["CallDetailsExcelPath"] = "";
TempData["CustomError"] = "Please close the file before
uploading.";
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error, "Error in
ExportToExcel()." + ex.Message);
Session["ReconExcelPath"] = "";
Session["CallDetailsExcelPath"] = "";
}
}
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error, "Error in
Convertawbtomp3()." + ex.Message);
return false;
}
}
public void DeleteTempFolder()
{
try
{
string userName = Convert.ToString(Session["UserID"]);
if (userName != null || userName != "")
{
string userid = Session["UserID"].ToString();
string OutputFileName = "";
string ip = GetIpAddress().ToString();
OutputFileName =
Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "tempvoicefile", userid,
ip);
string path = OutputFileName + @"\";
if (Directory.Exists(path))
{
Directory.Delete(OutputFileName, true);
//Log.LogMessage(MessageLogger.MessageType.Info, "File
Deleted Successfully :" + OutputFileName);
}
}
}
catch (Exception ex)
{
Log.LogMessage(MessageLogger.MessageType.Error, "Error in
DeleteTempFolder()." + ex.Message);
}
// Log.LogMessage(MessageLogger.MessageType.Error, "GetUserId();" +
ex.ToString());
// return userid;
// }
//}
}
}