161 lines
6.2 KiB
C#
161 lines
6.2 KiB
C#
//using System.Web.Mvc;
|
|
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Configuration;
|
|
//using System.Data;
|
|
//using System.Reflection;
|
|
//using System.Web.Mvc;
|
|
//using GODATA.Models.AuditLog;
|
|
//using Kendo.Mvc.Extensions;
|
|
//using Kendo.Mvc.UI;
|
|
////using CsvHelper;
|
|
////using ExportToExcel;
|
|
|
|
//namespace GODATA.Controllers
|
|
//{
|
|
// public class AuditLogController : Controller
|
|
// {
|
|
// #region Global References
|
|
// /// <summary>
|
|
// /// Global variable for Audit log repository
|
|
// /// </summary>
|
|
// private AuditLogRepository oAuditlog = null;
|
|
|
|
// /// <summary>
|
|
// /// Global variable for connection string.
|
|
// /// </summary>
|
|
// private static string _connString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
|
|
|
|
// /// <summary>
|
|
// /// Default page size for reports grid.
|
|
// /// </summary>
|
|
// private static int _pageSize = int.Parse(ConfigurationManager.AppSettings["pageSize"]);
|
|
|
|
// /// <summary>
|
|
// /// Absolute Path on server in which csv files are saved.
|
|
// /// </summary>
|
|
// private static string _csvExportPathOnServer = ConfigurationManager.AppSettings["csvExportPathOnServer"].ToString();
|
|
// //private static string _csvExportLocation = ConfigurationManager.AppSettings["csvExportPath"].ToString();
|
|
|
|
// /// <summary>
|
|
// /// Absolute Path on local in which csv files are saved.
|
|
// /// </summary>
|
|
// private static string _exportLocation = ConfigurationManager.AppSettings["csvExportPath"].ToString();
|
|
// #endregion
|
|
|
|
// /// <summary>
|
|
// /// Show Audit log page with filter (Date).
|
|
// /// GET: /AuditLog/
|
|
// /// </summary>
|
|
// /// <returns>Audit Log View</returns>
|
|
// [AuditRepository]
|
|
// public ActionResult AuditLog()
|
|
// {
|
|
// return View();
|
|
// }
|
|
|
|
// /// <summary>
|
|
// /// This function fetch Audit Log Data from repository.
|
|
// /// POST :// AuditLog/showAuditLog
|
|
// /// </summary>
|
|
// /// <param name="startDate">Start date e.g. 01 Jan 2014</param>
|
|
// /// <param name="endDate">End date e.g. 31 Mar 2014</param>
|
|
// /// <returns>Action result.</returns>
|
|
// [HttpPost]
|
|
// [AuditRepository]
|
|
// public ActionResult ShowAuditLog(string startDate, string endDate)
|
|
// {
|
|
// try
|
|
// {
|
|
// oAuditlog = new AuditLogRepository();
|
|
// List<AuditModel> model = oAuditlog.GetAuditDetailDateWise(Convert.ToDateTime(startDate), Convert.ToDateTime(endDate), _pageSize, 0);
|
|
|
|
// // Stored data in viewbag for paging.
|
|
// ViewBag.StartDate = startDate;
|
|
// ViewBag.EndDate = endDate;
|
|
// ViewBag.total = oAuditlog.GetCountAuditDetail(Convert.ToDateTime(startDate), Convert.ToDateTime(endDate));
|
|
// ViewBag.pageSize = _pageSize;
|
|
// return PartialView(model);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// throw ex;
|
|
// }
|
|
// }
|
|
|
|
// /// <summary>
|
|
// /// Returns page wise data to grid.
|
|
// /// </summary>
|
|
// /// <param name="request">Datasource</param>
|
|
// /// <param name="startDate">selected date</param>
|
|
// /// <param name="endDate">end date</param>
|
|
// /// <param name="total">Total numbers of records</param>
|
|
// /// <returns>Action Result</returns>
|
|
// public ActionResult ShowAuditLogPager([DataSourceRequest]DataSourceRequest request, string startDate, string endDate, int total)
|
|
// {
|
|
// try
|
|
// {
|
|
// oAuditlog = new AuditLogRepository();
|
|
// List<AuditModel> model = oAuditlog.GetAuditDetailDateWise(Convert.ToDateTime(startDate), Convert.ToDateTime(endDate), request.PageSize, request.PageSize * (request.Page - 1));
|
|
// DataSourceResult result = model.ToDataSourceResult(request);
|
|
// result.Total = total;
|
|
// result.Data = model;
|
|
// return Json(result);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// throw ex;
|
|
// }
|
|
// }
|
|
|
|
// /// <summary>
|
|
// /// Export Audit log report to Excel with dynamic column generation
|
|
// /// </summary>
|
|
// /// <param name="startDate">selected date</param>
|
|
// /// <param name="endDate">end date</param>
|
|
// /// <returns>true if excel exported, else false</returns>
|
|
// [HttpPost]
|
|
// [AuditRepository]
|
|
// public string ExportXlsAuditLog(string startDate, string endDate)
|
|
// {
|
|
// try
|
|
// {
|
|
// oAuditlog = new AuditLogRepository();
|
|
|
|
// DataSet ds = oAuditlog.GetAuditDetailDataset(Convert.ToDateTime(startDate), Convert.ToDateTime(endDate));
|
|
|
|
// // Remove columns which are not required
|
|
// ds.Tables[0].Columns.Remove("auditid");
|
|
// ds.Tables[0].Columns.Remove("sessionid");
|
|
|
|
// ds.Tables[0].Columns[0].ColumnName = "User Name";
|
|
// ds.Tables[0].Columns[1].ColumnName = "IP-Address";
|
|
// ds.Tables[0].Columns[2].ColumnName = "Url Accessed";
|
|
// ds.Tables[0].Columns[3].ColumnName = "Time Accessed";
|
|
// ds.Tables[0].Columns[4].ColumnName = "Controller Name";
|
|
// ds.Tables[0].Columns[5].ColumnName = "Method Name";
|
|
// ds.Tables[0].Columns[6].ColumnName = "Input Parameters";
|
|
|
|
// //==========================Excel Section==========================//
|
|
|
|
// string fileName = "AuditLog_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".xlsx";
|
|
// string SaveCsvAs = Server.MapPath(_csvExportPathOnServer + fileName);
|
|
|
|
// bool isCreated = CreateExcelFile.CreateExcelDocument(ds, SaveCsvAs);
|
|
// if (isCreated == true) { return _exportLocation + fileName; }
|
|
// else { return "error"; }
|
|
|
|
// //========================Excel Section end========================//
|
|
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// return "error";
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
//}
|