using framework_library;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using System.Runtime.Serialization;
namespace framework_business
{
///
/// Summary description for handler
///
public class handler
{
public handler()
{
//
// TODO: Add constructor logic here
//
}
///
/// Pick up routed page data
///
///
///
public static string GetRoutedData(string key)
{
string result = String.Empty;
try
{
if (HttpContext.Current.Request.RequestContext.RouteData.Values[key] != null && HttpContext.Current.Request.RequestContext.RouteData.Values[key].ToString() != String.Empty)
{
result = HttpContext.Current.Request.RequestContext.RouteData.Values[key].ToString();
}
}
catch (Exception ex)
{
exception.HandleException("handler:", MethodBase.GetCurrentMethod().Name, ex, HttpContext.Current.Session["user"]);
}
return result;
}
///
/// validate a canvas based on permisssions
///
///
///
public static bool validateCanvas(oCanvas _canvas)
{
bool result = false;
oUser user = new oUser();
try
{
if (utils.verifySession("user"))
user = (oUser)HttpContext.Current.Session["user"];
//CVH 2017-05-17 EVOL Admin users have access to all canvas pages by default
//GR 2017-06-06 this change is having undesired affects, I am commenting out for now
//CVH 2017-06-14 Enabling for only SBF again
if ((handler.ReturnSetup().code == "STUD-1" || handler.ReturnSetup().code == "DISA-1") && user.userType == pNums.UserType.AdminUser.GetHashCode() && user.customerCode == "EVOL-1")
{
result = true;
}
else if (ReturnSetup().code == "STUD-1" && user.userType == (int)pNums.UserType.CustomUser && user.mimicUserType == (int)pNums.UserType.AdminUser)
{
result = true;
}
else if (_canvas.isRestricted)
{
if(user.userType== pNums.UserType.CustomUser.GetHashCode())
{
if (_canvas.customUsers != string.Empty)
{
string[] customUsers = _canvas.customUsers.Split(char.Parse(","));
foreach (string customUserId in customUsers)
{
if (user.recId.ToString() == customUserId)
{
result = true;
break;
}
}
}
}
else if (_canvas.userTypes != String.Empty)
{
string[] userTypes = _canvas.userTypes.Split(char.Parse(","));
foreach (string userType in userTypes)
{
if (user.userType.ToString() == userType && user.userType != pNums.UserType.CustomUser.GetHashCode())
{
result = true;
break;
}
}
}
else
result = true;
}
else
result = true;
}
catch (Exception ex)
{
exception.HandleException("navigation:", MethodBase.GetCurrentMethod().Name, ex, HttpContext.Current.Session["user"]);
}
return result;
}
///
/// Return company Setup
///
///
public static oSetup ReturnSetup(bool refresh = false)
{
//CVH 2016-09-15 Sometimes need to force refresh of session
oSetup result = new oSetup();
if(HttpContext.Current == null) {
return (oSetup)(xData.GetTypedByCriteriaSpecific("recId", typeof(oSetup), "isActive", "1")[0]);
}
if (refresh || HttpContext.Current.Session["osetup"] == null)
HttpContext.Current.Session["osetup"] = (oSetup)(xData.GetTypedByCriteriaSpecific("recId", typeof(oSetup), "isActive", "1")[0]);
result = (oSetup)HttpContext.Current.Session["osetup"];
return result;
}
///
/// Return user
///
///
public static oUser ReturnUser()
{
oUser result = new oUser();
if (HttpContext.Current?.Session["user"] != null)
result = (oUser)HttpContext.Current.Session["user"];
return result;
}
///
/// Return app Setting
///
///
///
public static string ReturnConfigAppSetting(string key)
{
string result = String.Empty;
if (ConfigurationManager.AppSettings[key] != null)
result = ConfigurationManager.AppSettings[key];
return result;
}
///
/// bool to validate a Permission to a module
///
///
///
public static bool ValidatePermission(string pagePath)
{
bool result = false;
try
{
if (HttpContext.Current.Session["user"] != null)
{
oUser admin = (oUser)HttpContext.Current.Session["user"];
if (admin.recId > 0 && admin.userType == pNums.UserType.AdminUser.GetHashCode())//verify this admin allowed to access module
{
string[] permisssions = admin.modules.Split(char.Parse(","));
foreach (oModule mod in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "path", pagePath.Replace("~/", "")))
{
foreach (string p in permisssions)
{
if (p.Trim() == mod.recId.ToString())
{
result = true;
break;
}
}
}
}
else if (admin.recId == -1)
result = true;
}
}
catch (Exception ex)
{
exception.HandleException("handler:", MethodBase.GetCurrentMethod().Name, ex, HttpContext.Current.Session["user"]);
}
return result;
}
///
/// Format Curreny string
///
///
///
public static string FormatCurrency(string value)
{
return utils.returnFormattedDecimal(value); ;
}
///
/// Get Substring length
///
///
///
///
public static string GetSubstring(string str, int length)
{
return str.Length > length ? str.Substring(0, length) + " ..." : str;
}
///
/// Get Substring length
///
///
///
///
public static string GetBoolString(string str)
{
string result = "No";
if (str != null && (str == "1" || str == "True"))
result = "Yes";
return result;
}
///
/// String of Banners for a Bootstrap Carousel
///
/// bannerTypeId
/// id of div
///
///
///
///
public static string ReturnBannerCarousel(int bannerTypeId, string divId, bool includeCaptions, bool IncludeIndicators, bool IncludeControls)
{
string result = String.Empty;
StringBuilder bannerBuilder = new StringBuilder();
int counter = 0;
string bannerType = String.Empty;
try
{
//setup folder
foreach (oBannerType bType in xData.GetTypedByCriteriaSpecific("recId", typeof(oBannerType), "recId", bannerTypeId.ToString()))
{
bannerType = bType.bannerType;
break;
}
//fetch banners
ArrayList banners = xData.GetTypedByCriteriaSpecific("recId", typeof(oBanner), "isActive,bannerTypeId", "1," + bannerTypeId, "sequence");
if (banners.Count > 0)
{
bannerBuilder.Clear();
if (IncludeIndicators)
{
//build indicators
bannerBuilder.Append("
");
foreach (oBanner bannerIndicator in banners)
{
if (bannerIndicator.startDate.Date <= DateTime.Now.Date && bannerIndicator.endDate.Date >= DateTime.Now.Date)
{
if (counter == 0)//set active item
{ bannerBuilder.Append(""); }
else
{ bannerBuilder.Append(""); }
counter++;
}
}
bannerBuilder.Append("
");
}
counter = 0;
//carousel items
bannerBuilder.Append("");
foreach (oBanner banner in banners)
{
if (banner.startDate.Date <= DateTime.Now.Date && banner.endDate.Date >= DateTime.Now.Date)
{
if (counter == 0)//set active item
{ bannerBuilder.Append("
"); }
else
{ bannerBuilder.Append("
"); }
if (banner.path != String.Empty)
bannerBuilder.Append("

");
else
bannerBuilder.Append("

");
if (includeCaptions)
{
bannerBuilder.Append("
");
if (!banner.hideTitle)
bannerBuilder.Append("
" + banner.title + "
");
if (!banner.hideCaption)
bannerBuilder.Append("
" + banner.caption + "
");
bannerBuilder.Append("
");
}
bannerBuilder.Append("
");
counter++;
}
}
bannerBuilder.Append("
");
if (IncludeControls)
{
bannerBuilder.Append("
");
bannerBuilder.Append("");
bannerBuilder.Append("Previous");
bannerBuilder.Append("");
bannerBuilder.Append("
");
bannerBuilder.Append("");
bannerBuilder.Append("Next");
bannerBuilder.Append("");
}
}
result = bannerBuilder.ToString();
}
catch (Exception ex)
{
exception.HandleException("handler:", MethodBase.GetCurrentMethod().Name, ex, HttpContext.Current.Session["user"]);
}
return result;
}
public static List
> ConvertTableToStringLists(DataTable table)
{
return table.Rows.Cast()
.Select(row => table.Columns.Cast()
.Select(col => Convert.ToString(row[col]))
.ToList())
.ToList();
}
}
[Serializable]
public class UploadFileMetadata
{
public string FileVersion { get; set; }
public long FileSize_InBytes { get; set; }
public string FileType { get; set; }
public string UploadUser { get; set; }
public string FileSize_MB => FileSize_InBytes.ToFileSizeDescription();
//{
// get
// {
// return FileSize_InBytes.ToFileSizeDescription();
// }
//}
}
}