public JsonResult GetSessionChartUsers(ChartLoadRequestObject reqObj) { DateTime startDate = string.IsNullOrEmpty(reqObj.StartDate) ? System.DateTime.Now.AddDays(-365) : DateTime.ParseExact(reqObj.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime endDate = string.IsNullOrEmpty(reqObj.EndDate) ? System.DateTime.Now : DateTime.ParseExact(reqObj.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); string connectionString = ConfigurationManager.ConnectionStrings["NHSConStr"].ConnectionString; DBEngine dBEngine = new DBEngine(connectionString); List <UserCount> users = dBEngine.GetActiveUsers(startDate, endDate, Convert.ToInt32(Session["LoginUserID"])); var userList = users.GroupBy(x => x.UserName) .Select(x => new UserInformation { Id = x.Key, UserName = x.Key }).ToList(); return(Json(userList, JsonRequestBehavior.AllowGet)); }
public JsonResult SessionChartResult(ChartLoadRequestObject reqObj) { DateTime startDate = string.IsNullOrEmpty(reqObj.StartDate) ? System.DateTime.Now.AddDays(-365) : DateTime.ParseExact(reqObj.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime endDate = string.IsNullOrEmpty(reqObj.EndDate) ? System.DateTime.Now : DateTime.ParseExact(reqObj.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); string connectionString = ConfigurationManager.ConnectionStrings["NHSConStr"].ConnectionString; DBEngine dBEngine = new DBEngine(connectionString); List <UserCount> users = dBEngine.GetActiveUsers(startDate, endDate, Convert.ToInt32(Session["LoginUserID"])); List <UserSessionCount> userSessionCount = dBEngine.GetUsersSessionCount(startDate, endDate, Convert.ToInt32(Session["LoginUserID"])); var filteredUserCount = users.GroupBy(x => x.UserName) .Select(x => new UserCount { UserName = x.Key, ActivityCount = x.Sum(y => y.ActivityCount) }).ToList(); var stringUserActivityCounter = new List <string>(); var stringUsers = new List <string>(); var userActivityInfo = new Dictionary <string, string>(); foreach (var user in filteredUserCount) { stringUsers.Add(user.UserName); stringUserActivityCounter.Add(user.ActivityCount.ToString()); userActivityInfo.Add(user.UserName, user.ActivityCount.ToString()); } var chartInfo = new List <ChartResponseInformation>(); var chartOptions = new ChartOptionInformation(); chartInfo = new List <ChartResponseInformation> { new ChartResponseInformation { name = "", data = stringUserActivityCounter.ToArray() } }; chartOptions = new ChartOptionInformation { X_axisCategoryType = "category", X_axisCategories = stringUsers.ToArray() }; var result = new ChartResultResponse(); if (reqObj.FilterByUserId != null && reqObj.FilterByUserId.Length > 0) { var seriesDataArray = new List <string>(); var categoriesDataArray = new List <string>(); foreach (var userId in reqObj.FilterByUserId) { if (!string.IsNullOrEmpty(userId)) { seriesDataArray.Add(userActivityInfo.FirstOrDefault(x => x.Key == userId).Value); categoriesDataArray.Add(userId); } } result = new ChartResultResponse() { ChartInfo = chartInfo.Select(x => new ChartResponseInformation { name = x.name, titile = x.titile, data = seriesDataArray.ToArray() }), ChartOptions = new ChartOptionInformation() { X_axisCategoryType = chartOptions.X_axisCategoryType, X_axisCategories = categoriesDataArray.ToArray() } }; } else { result = new ChartResultResponse() { ChartInfo = chartInfo, ChartOptions = chartOptions, UserSessionCountInformation = userSessionCount }; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult SessionTimeChartResult(ChartLoadRequestObject reqObj) { DateTime startDate = string.IsNullOrEmpty(reqObj.StartDate) ? System.DateTime.Now.AddDays(-365) : DateTime.ParseExact(reqObj.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime endDate = string.IsNullOrEmpty(reqObj.EndDate) ? System.DateTime.Now : DateTime.ParseExact(reqObj.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); string connectionString = ConfigurationManager.ConnectionStrings["NHSConStr"].ConnectionString; DBEngine dBEngine = new DBEngine(connectionString); List <UserCount> users = dBEngine.GetActiveUsers(startDate, endDate, Convert.ToInt32(Session["LoginUserID"])); List <UserModuleDetails> userModuleDetails = dBEngine.GetUserModuleDetails(startDate, endDate, Convert.ToInt32(Session["LoginUserID"])); var chartInfo = new List <ChartResponseInformation>(); var filteredResult = new List <UserCount>(); var chartOptions = new ChartOptionInformation(); if (reqObj.RequestType == DataTypeEnum.yearly.ToString()) { filteredResult = users.GroupBy(x => x.DistinctYear).Select(y => new UserCount { DistinctYear = y.Key, ActivityCount = y.Sum(z => z.ActivityCount) }).ToList(); } if (reqObj.RequestType == DataTypeEnum.monthly.ToString()) { filteredResult = users.GroupBy(x => x.Month).Select(y => new UserCount { Month = y.Key, ActivityCount = y.Sum(z => z.ActivityCount) }).ToList(); } if (reqObj.RequestType == DataTypeEnum.weekly.ToString()) { filteredResult = users.GroupBy(x => x.Week).Select(y => new UserCount { Week = y.Key, ActivityCount = y.Sum(z => z.ActivityCount) }).ToList(); } if (reqObj.RequestType == DataTypeEnum.daily.ToString()) { filteredResult = users.GroupBy(x => x.Day).Select(y => new UserCount { Day = y.Key, ActivityCount = y.Sum(z => z.ActivityCount) }).ToList(); } var seriesData = new List <string>(); var xAxisData = new List <string>(); foreach (var userCountInfo in filteredResult) { seriesData.Add(userCountInfo.ActivityCount.ToString()); xAxisData.Add(reqObj.RequestType == DataTypeEnum.yearly.ToString() ? userCountInfo.DistinctYear : reqObj.RequestType == DataTypeEnum.monthly.ToString() ? userCountInfo.Month : reqObj.RequestType == DataTypeEnum.weekly.ToString() ? userCountInfo.Week : userCountInfo.Day); } #region Static Data Area chartInfo = new List <ChartResponseInformation> { new ChartResponseInformation() { name = "Session", data = seriesData.ToArray() } }; chartOptions = new ChartOptionInformation() { X_axisCategoryType = "category", X_axisCategories = xAxisData.ToArray() }; #endregion var result = new ChartResultResponse() { ChartInfo = chartInfo, ChartOptions = chartOptions, UserModuleTimeSpanInformation = userModuleDetails }; return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult UserOverTimeChartResult(ChartLoadRequestObject reqObj) { DateTime startDate = string.IsNullOrEmpty(reqObj.StartDate) ? System.DateTime.Now.AddDays(-365) : DateTime.ParseExact(reqObj.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime endDate = string.IsNullOrEmpty(reqObj.EndDate) ? System.DateTime.Now : DateTime.ParseExact(reqObj.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); string connectionString = ConfigurationManager.ConnectionStrings["NHSConStr"].ConnectionString; DBEngine dBEngine = new DBEngine(connectionString); List <UserCount> users = dBEngine.GetActiveUsers(startDate, endDate, Convert.ToInt32(Session["LoginUserID"])); List <UserCount> usersActivity = dBEngine.GetActiveUsersActivity(startDate, endDate, Convert.ToInt32(Session["LoginUserID"])); var filteredUserCount = new List <UserCount>(); if (reqObj.RequestType == DataTypeEnum.yearly.ToString()) { filteredUserCount = users.GroupBy(x => new { x.DistinctYear }) .Select(y => new UserCount { DistinctYear = y.Key.DistinctYear, ActivityCount = y.GroupBy(z => z.UserName).Count(), //UserName = y.Key.UserName }).ToList(); } else if (reqObj.RequestType == DataTypeEnum.monthly.ToString()) { filteredUserCount = users.GroupBy(x => new { x.Month }) .Select(y => new UserCount { Month = y.Key.Month, ActivityCount = y.GroupBy(z => z.UserName).Count(), //UserName = y.Key.UserName }).ToList(); } else if (reqObj.RequestType == DataTypeEnum.weekly.ToString()) { filteredUserCount = users.GroupBy(x => new { x.Week }) .Select(y => new UserCount { Week = y.Key.Week, ActivityCount = y.GroupBy(z => z.UserName).Count(), //UserName = y.Key.UserName }).ToList(); } else if (reqObj.RequestType == DataTypeEnum.daily.ToString()) { filteredUserCount = users.GroupBy(x => new { x.Day }) .Select(y => new UserCount { Day = y.Key.Day, ActivityCount = y.GroupBy(z => z.UserName).Count(), //UserName = y.Key.UserName }).ToList(); } else { filteredUserCount = users; } var userCounter = new List <string>(); var chartInfo = new List <ChartResponseInformation>(); var chartOptions = new ChartOptionInformation(); var years = new List <string>(); var months = new List <string>(); var weeks = new List <string>(); var days = new List <string>(); foreach (var row in filteredUserCount) { userCounter.Add(row.ActivityCount.ToString()); if (reqObj.RequestType == DataTypeEnum.yearly.ToString()) { years.Add(row.DistinctYear); } if (reqObj.RequestType == DataTypeEnum.monthly.ToString()) { months.Add(row.Month); } if (reqObj.RequestType == DataTypeEnum.weekly.ToString()) { weeks.Add(row.Week); } if (reqObj.RequestType == DataTypeEnum.daily.ToString()) { days.Add(row.Day); } } #region Static Data area chartInfo = new List <ChartResponseInformation> { new ChartResponseInformation() { name = "Active Users", data = userCounter.ToArray() } }; chartOptions = new ChartOptionInformation() { X_axisCategoryType = "category", X_axisCategories = reqObj.RequestType == DataTypeEnum.yearly.ToString() ? years.ToArray() : reqObj.RequestType == DataTypeEnum.monthly.ToString() ? months.ToArray() : reqObj.RequestType == DataTypeEnum.weekly.ToString() ? weeks.ToArray() : reqObj.RequestType == DataTypeEnum.daily.ToString() ? days.ToArray() : years.ToArray() }; #endregion var result = new ChartResultResponse() { ChartInfo = chartInfo, ChartOptions = chartOptions, UsersCountInformation = usersActivity }; return(Json(result, JsonRequestBehavior.AllowGet)); }