sync
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using Foresight.Fleet.Services.Customer;
|
||||
using Foresight.Standard;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -11,6 +12,20 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
{
|
||||
public class CustomerProviderBasePage : ContractorBasePage
|
||||
{
|
||||
protected bool IsDev
|
||||
{
|
||||
get
|
||||
{
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
if (Helper.DevAccounts.Contains(session.User.ID, StringComparer.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void ProcessRequest(string methodName)
|
||||
{
|
||||
object result = null;
|
||||
@ -29,6 +44,30 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
case "DELETECUSTOMERLOCATION":
|
||||
result = DeleteCustomerLocation();
|
||||
break;
|
||||
case "GETDEPARTMENTS":
|
||||
result = GetDepartments();
|
||||
break;
|
||||
case "SAVEDEPARTMENT":
|
||||
result = SaveDepartment();
|
||||
break;
|
||||
case "DELETEDEPARTMENT":
|
||||
result = DeleteDepartment();
|
||||
break;
|
||||
case "GETREGIONS":
|
||||
result = GetRegions();
|
||||
break;
|
||||
case "SAVEREGION":
|
||||
result = SaveRegion();
|
||||
break;
|
||||
case "DELETEREGION":
|
||||
result = DeleteRegion();
|
||||
break;
|
||||
case "GETSYSTEMPARAMS":
|
||||
result = GetSystemParams();
|
||||
break;
|
||||
case "SETSYSTEMPARAMS":
|
||||
result = SetSystemParams();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,19 +88,15 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
CustomerLocation[] locations = CreateClient<CustomerProvider>().GetCustomerLocations(SystemParams.CompanyID);
|
||||
|
||||
List<CustomerLocationItem> list = new List<CustomerLocationItem>();
|
||||
foreach (CustomerLocation lc in locations)
|
||||
CustomerLocation[] alllocs = CreateClient<CustomerProvider>().GetLocations(SystemParams.CompanyID);
|
||||
var plocs = alllocs.Where(d => d.PId <= 0).OrderBy(d => d.Name);
|
||||
List<CustomerLocation> result = new List<CustomerLocation>();
|
||||
foreach (var ploc in plocs)
|
||||
{
|
||||
CustomerLocationItem item = new CustomerLocationItem();
|
||||
Helper.CloneProperty(item, lc);
|
||||
list.Add(item);
|
||||
result.Add(ploc);
|
||||
result.AddRange(alllocs.Where(d => d.PId == ploc.ID).OrderBy(d => d.Name));
|
||||
}
|
||||
if (list.Count() > 0)
|
||||
return list.ToArray().OrderBy(m => m.Name);
|
||||
else
|
||||
return new CustomerLocationItem[0];
|
||||
return result.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -79,7 +114,7 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
{
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
string data = HttpUtility.UrlDecode(Request.Params["ClientData"]);
|
||||
string data = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
HttpPostedFile uploadFile = null;
|
||||
byte[] logobyte = null;
|
||||
if (Request.Files.Count > 0)
|
||||
@ -88,18 +123,16 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
logobyte = ConvertFile2bytes(uploadFile);
|
||||
}
|
||||
|
||||
CustomerLocationItem item = JsonConvert.DeserializeObject<CustomerLocationItem>(data);
|
||||
CustomerLocation location = new CustomerLocation();
|
||||
Helper.CloneProperty(location, item);
|
||||
CustomerLocation location = JsonConvert.DeserializeObject<CustomerLocation>(data);
|
||||
var cp = CreateClient<CustomerProvider>();
|
||||
int locationid = location.ID;
|
||||
if (locationid == -1)
|
||||
locationid = cp.AddCustomerLocation(SystemParams.CompanyID, location);
|
||||
locationid = cp.AddLocation(SystemParams.CompanyID, location);
|
||||
else
|
||||
cp.UpdateCustomerLocation(location);
|
||||
cp.UpdateLocation(SystemParams.CompanyID, location);
|
||||
|
||||
if (logobyte != null)
|
||||
cp.ChangeLocationLOGO(locationid, logobyte);
|
||||
cp.ChangeLocationLOGO(SystemParams.CompanyID, locationid, logobyte);
|
||||
return "OK";
|
||||
}
|
||||
else
|
||||
@ -113,16 +146,234 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
}
|
||||
}
|
||||
|
||||
private string DeleteCustomerLocation()
|
||||
private object DeleteCustomerLocation()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
string id = HttpUtility.UrlDecode(Request.Params["ClientData"]);
|
||||
string id = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
int locationid = -1;
|
||||
int.TryParse(id, out locationid);
|
||||
CreateClient<CustomerProvider>().DeleteCustomerLocation(locationid);
|
||||
CreateClient<CustomerProvider>().DeleteLocation(SystemParams.CompanyID, locationid);
|
||||
|
||||
return new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private object GetDepartments()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
DepartmentInfo[] alldeps = CreateClient<CustomerProvider>().GetAllDepartments(SystemParams.CompanyID);
|
||||
var pdeps = alldeps.Where(d => d.PId <= 0).OrderBy(d => d.Name);
|
||||
List<DepartmentInfo> result = new List<DepartmentInfo>();
|
||||
foreach (var pdep in pdeps)
|
||||
{
|
||||
result.Add(pdep);
|
||||
result.AddRange(alldeps.Where(d => d.PId == pdep.Id).OrderBy(d => d.Name));
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
private object SaveDepartment()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
string data = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
|
||||
DepartmentInfo dep = JsonConvert.DeserializeObject<DepartmentInfo>(data);
|
||||
var cp = CreateClient<CustomerProvider>();
|
||||
if (dep.Id > 0)
|
||||
cp.UpdateDepartment(SystemParams.CompanyID, dep);
|
||||
else
|
||||
dep = cp.AddNewDepartment(SystemParams.CompanyID, dep);
|
||||
|
||||
return dep.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private object DeleteDepartment()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
string id = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
int depid = -1;
|
||||
int.TryParse(id, out depid);
|
||||
CreateClient<CustomerProvider>().DeleteDepartment(SystemParams.CompanyID, depid);
|
||||
|
||||
return new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
#region Region
|
||||
private object GetRegions()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
RegionInfo[] regions = CreateClient<CustomerProvider>().GetRegions(SystemParams.CompanyID);
|
||||
|
||||
if (regions == null || regions.Length == 0)
|
||||
return new RegionItem[0];
|
||||
|
||||
List<RegionItem> ls = new List<RegionItem>();
|
||||
foreach (var region in regions)
|
||||
{
|
||||
RegionItem item = new RegionItem();
|
||||
Helper.CloneProperty(item, region);
|
||||
ls.Add(item);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
private object SaveRegion()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
string data = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
|
||||
RegionInfo region = JsonConvert.DeserializeObject<RegionInfo>(data);
|
||||
var cp = CreateClient<CustomerProvider>();
|
||||
if (region.Id > 0)
|
||||
cp.UpdateRegion(SystemParams.CompanyID, region);
|
||||
else
|
||||
cp.AddNewRegion(SystemParams.CompanyID, region);
|
||||
|
||||
return new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private object DeleteRegion()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
string clientdata = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
int id = -1;
|
||||
int.TryParse(clientdata, out id);
|
||||
CreateClient<CustomerProvider>().DeleteRegion(SystemParams.CompanyID, id);
|
||||
|
||||
return new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region System Params
|
||||
|
||||
private object GetSystemParams()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
StringKeyValue[] items = CreateClient<CustomerProvider>().GetSystemParams(SystemParams.CompanyID);
|
||||
|
||||
if (items == null || items.Length == 0)
|
||||
return new StringKeyValue[0];
|
||||
|
||||
return items;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private object SetSystemParams()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GetCurrentLoginSession() != null && IsDev)
|
||||
{
|
||||
string data = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
|
||||
string[] pstr = JsonConvert.DeserializeObject<string[]>(data);
|
||||
var cp = CreateClient<CustomerProvider>();
|
||||
cp.SetSystemParams(SystemParams.CompanyID, pstr[0], pstr[1]);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
else
|
||||
@ -136,14 +387,14 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomerLocationItem
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public string Address { get; set; }
|
||||
public string Notes { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
class RegionItem : RegionInfo
|
||||
{
|
||||
public string StartDateStr { get { return StartDate == null ? "" : StartDate.Value.ToShortDateString(); } }
|
||||
public string EndDateStr { get { return EndDate == null ? "" : EndDate.Value.ToShortDateString(); } }
|
||||
public string ProjectedEndDateStr { get { return ProjectedEndDate == null ? "" : ProjectedEndDate.Value.ToShortDateString(); } }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,36 @@ using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using System.Xml;
|
||||
using System.Web;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Contractor.Users;
|
||||
using Foresight.ServiceModel;
|
||||
using Foresight.Fleet.Services.Styles;
|
||||
using Foresight.Fleet.Services;
|
||||
using Foresight.Fleet.Services.User;
|
||||
using Foresight;
|
||||
using IronIntel.Contractor.Machines;
|
||||
using Foresight.Fleet.Services.JobSite;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using System.Web.UI.WebControls;
|
||||
using FI.FIC.Contracts.DataObjects.BaseObject;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace IronIntel.Contractor.Site.SystemSettings
|
||||
{
|
||||
public class SystemSettingsBasePage : ContractorBasePage
|
||||
{
|
||||
protected bool IsDev
|
||||
{
|
||||
get
|
||||
{
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
if (Helper.DevAccounts.Contains(session.User.ID, StringComparer.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
protected void ProcessRequest(string methodName)
|
||||
{
|
||||
object result = null;
|
||||
@ -47,6 +69,39 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
case "SAVESYSTEMOPTIONS":
|
||||
result = SaveSystemOptions();
|
||||
break;
|
||||
case "GETLANGUAGES":
|
||||
result = GetLanguages();
|
||||
break;
|
||||
case "GETSYSTEMUNITOFODOMETER":
|
||||
result = GetSystemUnitOfOdometer();
|
||||
break;
|
||||
case "GETASSETGROUPLIST":
|
||||
result = GetAssetGroupList();
|
||||
break;
|
||||
case "GETJOBSITELIST":
|
||||
result = GetJobsiteList();
|
||||
break;
|
||||
case "GETASSETTYPES":
|
||||
result = GetAssetTypes();
|
||||
break;
|
||||
case "GETFILTERTEMPLATES":
|
||||
result = GetFilterTemplates();
|
||||
break;
|
||||
case "GETFILTERTEMPLATEITEM":
|
||||
result = GetFilterTemplateItem();
|
||||
break;
|
||||
case "GETUSERASSIGNEDASSETGROUPS":
|
||||
result = GetUserAssignedAssetGroups();
|
||||
break;
|
||||
case "GETUSERASSIGNEDJOBSITES":
|
||||
result = GetUserAssignedJobsites();
|
||||
break;
|
||||
case "GETUSERASSIGNEDASSETTYPES":
|
||||
result = GetUserAssignedAssetTypes();
|
||||
break;
|
||||
case "SAVEASSETALERTFILTER":
|
||||
result = SaveAssetAlertFilter();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,10 +120,10 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GetCurrentLoginSession() != null)
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
IronSysServiceClient ic = SystemParams.GetIronSystemServiceClient();
|
||||
CustUIStyleList uis = ic.GetCompanyUIStyles(SystemParams.CompanyID);
|
||||
CustUIStyleList uis = CreateClient<StyleProvider>().GetCompanyUIStyles(SystemParams.CompanyID);
|
||||
|
||||
List<CustUIStyleItem> list = new List<CustUIStyleItem>();
|
||||
foreach (CustUIStyle ui in uis)
|
||||
@ -102,11 +157,10 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
{
|
||||
string uidata = Request.Params["ClientData"];
|
||||
CustUIStyleItem item = JsonConvert.DeserializeObject<CustUIStyleItem>(uidata);
|
||||
item.UIStyleName = HttpUtility.UrlDecode(item.UIStyleName);
|
||||
item.UIStyleName = HttpUtility.HtmlDecode(item.UIStyleName);
|
||||
CustUIStyle ui = new CustUIStyle();
|
||||
Helper.CloneProperty(ui, item);
|
||||
IronSysServiceClient ic = SystemParams.GetIronSystemServiceClient();
|
||||
ic.SetCompanyUIStyle(SystemParams.CompanyID, ui);
|
||||
CreateClient<StyleProvider>().SetCompanyUIStyle(SystemParams.CompanyID, ui);
|
||||
return "OK";
|
||||
}
|
||||
else
|
||||
@ -127,11 +181,10 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
string uistyleid = HttpUtility.UrlDecode(Request.Params["ClientData"]);
|
||||
string uistyleid = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
int styleid = -1;
|
||||
int.TryParse(uistyleid, out styleid);
|
||||
IronSysServiceClient ic = SystemParams.GetIronSystemServiceClient();
|
||||
ic.DeleteCompanyUIStyle(SystemParams.CompanyID, styleid);
|
||||
CreateClient<StyleProvider>().DeleteCompanyUIStyle(SystemParams.CompanyID, styleid);
|
||||
return "OK";
|
||||
}
|
||||
else
|
||||
@ -173,9 +226,132 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
string options = HttpUtility.UrlDecode(Request.Params["ClientData"]);
|
||||
UserParamInfo upi = JsonConvert.DeserializeObject<UserParamInfo>(options);
|
||||
UserParams.SetUserParams(session.User.UID, upi);
|
||||
string content = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
var user = JsonConvert.DeserializeObject<UserOptionObject>(content);
|
||||
var uid = session.User.UID;
|
||||
UserParamInfo upi = user.UserParam;
|
||||
|
||||
UserParams.SetUserParams(uid, upi);
|
||||
var uc = CreateClient<UserQueryClient>();
|
||||
uc.UpdateUserPreferredLanguage(uid, upi.PreferredLanguage);
|
||||
uc.UpdateUserTimeZone(uid, upi.TimeZone);
|
||||
|
||||
// save subscribe message
|
||||
if (user.Subscribe != null)
|
||||
{
|
||||
user.Subscribe.UserIID = uid;
|
||||
List<UserAlertFilter> filters = null;
|
||||
if (!string.IsNullOrEmpty(user.UserAlertFilter))
|
||||
{
|
||||
filters = JsonConvert.DeserializeObject<List<UserAlertFilter>>(user.UserAlertFilter);
|
||||
}
|
||||
FI.FIC.Models.WorkspaceManager.SaveSubscribeMessageByEmail(user.Subscribe, filters, uid);
|
||||
}
|
||||
|
||||
|
||||
//FIC Alert Filter Templates
|
||||
var userfilterclient = CreateClient<Foresight.Fleet.Services.User.UserFilterProvider>();
|
||||
if (user.FilterTemplates != null && user.FilterTemplates.Length > 0)
|
||||
{
|
||||
foreach (UserFilterTemplateItem filter in user.FilterTemplates)
|
||||
{
|
||||
if (filter.Id < 0)
|
||||
filter.Id = userfilterclient.AddFilterTemplate(SystemParams.CompanyID, uid, filter.Name);
|
||||
else
|
||||
userfilterclient.ChangeFilterName(SystemParams.CompanyID, filter.Id, filter.Name);
|
||||
|
||||
long[] assetids = null;
|
||||
if (filter.Assets != null && filter.Assets.Length > 0)
|
||||
assetids = filter.Assets.Select(m => m.Id).ToArray();
|
||||
userfilterclient.SetAssetFilter(SystemParams.CompanyID, filter.Id, assetids);
|
||||
|
||||
string[] assetgroups = null;
|
||||
if (filter.AssetGroups != null && filter.AssetGroups.Length > 0)
|
||||
assetgroups = filter.AssetGroups.Select(m => m.GroupID).ToArray();
|
||||
userfilterclient.SetAssetGroupFilter(SystemParams.CompanyID, filter.Id, assetgroups);
|
||||
|
||||
int[] assettypes = null;
|
||||
if (filter.AssetTypes != null && filter.AssetTypes.Length > 0)
|
||||
assettypes = filter.AssetTypes.Select(m => m.ID).ToArray();
|
||||
userfilterclient.SetAssetTypeFilter(SystemParams.CompanyID, filter.Id, assettypes);
|
||||
|
||||
long[] jobsites = null;
|
||||
if (filter.Jobsites != null && filter.Jobsites.Length > 0)
|
||||
jobsites = filter.Jobsites.Select(m => m.ID).ToArray();
|
||||
userfilterclient.SetJobSiteFilter(SystemParams.CompanyID, filter.Id, jobsites);
|
||||
}
|
||||
}
|
||||
if (user.DeleteFilterTemplates != null && user.DeleteFilterTemplates.Length > 0)
|
||||
{
|
||||
foreach (int id in user.DeleteFilterTemplates)
|
||||
{
|
||||
userfilterclient.DeleteFilterTemplate(SystemParams.CompanyID, id);
|
||||
}
|
||||
}
|
||||
|
||||
return "OK";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private object SaveAssetAlertFilter()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
string content = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
var user = JsonConvert.DeserializeObject<UserOptionObject>(content);
|
||||
var uid = session.User.UID;
|
||||
|
||||
var userfilterclient = CreateClient<Foresight.Fleet.Services.User.UserFilterProvider>();
|
||||
if (user.FilterTemplates != null && user.FilterTemplates.Length > 0)
|
||||
{
|
||||
foreach (UserFilterTemplateItem filter in user.FilterTemplates)
|
||||
{
|
||||
if (filter.Id < 0)
|
||||
filter.Id = userfilterclient.AddFilterTemplate(SystemParams.CompanyID, uid, filter.Name);
|
||||
else
|
||||
userfilterclient.ChangeFilterName(SystemParams.CompanyID, filter.Id, filter.Name);
|
||||
|
||||
long[] assetids = null;
|
||||
if (filter.Assets != null && filter.Assets.Length > 0)
|
||||
assetids = filter.Assets.Select(m => m.Id).ToArray();
|
||||
userfilterclient.SetAssetFilter(SystemParams.CompanyID, filter.Id, assetids);
|
||||
|
||||
string[] assetgroups = null;
|
||||
if (filter.AssetGroups != null && filter.AssetGroups.Length > 0)
|
||||
assetgroups = filter.AssetGroups.Select(m => m.GroupID).ToArray();
|
||||
userfilterclient.SetAssetGroupFilter(SystemParams.CompanyID, filter.Id, assetgroups);
|
||||
|
||||
int[] assettypes = null;
|
||||
if (filter.AssetTypes != null && filter.AssetTypes.Length > 0)
|
||||
assettypes = filter.AssetTypes.Select(m => m.ID).ToArray();
|
||||
userfilterclient.SetAssetTypeFilter(SystemParams.CompanyID, filter.Id, assettypes);
|
||||
|
||||
long[] jobsites = null;
|
||||
if (filter.Jobsites != null && filter.Jobsites.Length > 0)
|
||||
jobsites = filter.Jobsites.Select(m => m.ID).ToArray();
|
||||
userfilterclient.SetJobSiteFilter(SystemParams.CompanyID, filter.Id, jobsites);
|
||||
}
|
||||
}
|
||||
if (user.DeleteFilterTemplates != null && user.DeleteFilterTemplates.Length > 0)
|
||||
{
|
||||
foreach (int id in user.DeleteFilterTemplates)
|
||||
{
|
||||
userfilterclient.DeleteFilterTemplate(SystemParams.CompanyID, id);
|
||||
}
|
||||
}
|
||||
|
||||
return "OK";
|
||||
}
|
||||
else
|
||||
@ -210,6 +386,46 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
}
|
||||
}
|
||||
|
||||
private object GetSystemUnitOfOdometer()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
return SystemParams.GetStringParam("UnitOfOdometer");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private object GetLanguages()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
return CountryAndRegionCode.SupportedLanguages;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("not login.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private object GetSystemOptions()
|
||||
{
|
||||
try
|
||||
@ -221,11 +437,36 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
double accuracyfilter = 0;
|
||||
double.TryParse(af, out accuracyfilter);
|
||||
|
||||
string au = SystemParams.GetStringParam("AreaUnits");
|
||||
int areaunits = 0;
|
||||
int.TryParse(au, out areaunits);
|
||||
|
||||
string vu = SystemParams.GetStringParam("VolumnUnits");
|
||||
int volumeunits = 0;
|
||||
int.TryParse(vu, out volumeunits);
|
||||
|
||||
string wu = SystemParams.GetStringParam("WeightUnits");
|
||||
int weightunits = 0;
|
||||
int.TryParse(wu, out weightunits);
|
||||
|
||||
string rmd = SystemParams.GetStringParam("MFARememberMeDays");
|
||||
int remembermedays = 0;
|
||||
if (!int.TryParse(rmd, out remembermedays))
|
||||
remembermedays = 30;
|
||||
|
||||
SystemOptionInfo soi = new SystemOptionInfo();
|
||||
soi.TimeZone = SystemParams.GetStringParam("CustomerTimeZone", false);
|
||||
soi.AccuracyFilter = accuracyfilter;
|
||||
soi.UnitOfOdometer = SystemParams.GetStringParam("UnitOfOdometer");
|
||||
soi.AcknowledgingAlerts = SystemParams.GetStringParam("AcknowledgingAlerts");
|
||||
soi.LoginVerifyType = SystemParams.GetStringParam("LoginVerifyType");
|
||||
soi.AreaUnits = areaunits;
|
||||
soi.VolumeUnits = volumeunits;
|
||||
soi.WeightUnits = weightunits;
|
||||
soi.MFARememberMeDays = remembermedays;
|
||||
|
||||
string connectorxml = SystemParams.GetStringParam("Connector");
|
||||
soi.Connectors = ConnectorHelper.FromXML(connectorxml);
|
||||
return soi;
|
||||
}
|
||||
else
|
||||
@ -246,7 +487,7 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
string options = HttpUtility.UrlDecode(Request.Params["ClientData"]);
|
||||
string options = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
|
||||
SystemOptionInfo upi = JsonConvert.DeserializeObject<SystemOptionInfo>(options);
|
||||
|
||||
SystemParams.SetStringParam("CustomerTimeZone", upi.TimeZone);
|
||||
@ -254,6 +495,14 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
SystemParams.SetStringParam("AccuracyFilter", upi.AccuracyFilter.ToString());
|
||||
SystemParams.SetStringParam("UnitOfOdometer", upi.UnitOfOdometer);
|
||||
SystemParams.SetStringParam("AcknowledgingAlerts", upi.AcknowledgingAlerts);
|
||||
SystemParams.SetStringParam("AreaUnits", upi.AreaUnits.ToString());
|
||||
SystemParams.SetStringParam("VolumnUnits", upi.VolumeUnits.ToString());
|
||||
SystemParams.SetStringParam("WeightUnits", upi.WeightUnits.ToString());
|
||||
SystemParams.SetStringParam("LoginVerifyType", upi.LoginVerifyType);
|
||||
SystemParams.SetStringParam("MFARememberMeDays", upi.MFARememberMeDays.ToString());
|
||||
|
||||
XmlDocument doc = ConnectorHelper.ToXml(upi.Connectors);
|
||||
SystemParams.SetStringParam("Connector", doc.InnerXml);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
@ -268,6 +517,334 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region user filter
|
||||
private object GetFilterTemplates()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = GetCurrentLoginSession();
|
||||
|
||||
if (session != null)
|
||||
{
|
||||
var client = CreateClient<Foresight.Fleet.Services.User.UserFilterProvider>();
|
||||
KeyValuePair<int, string>[] filters = client.GetFilterTemplates(SystemParams.CompanyID, session.User.UID);
|
||||
if (filters == null && filters.Length == 0)
|
||||
return new KeyValuePair<int, string>[0];
|
||||
|
||||
return filters;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new KeyValuePair<int, string>[0];
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private object GetFilterTemplateItem()
|
||||
{
|
||||
try
|
||||
{
|
||||
var clientdata = Request.Form["ClientData"];
|
||||
string filteridstr = HttpUtility.HtmlDecode(clientdata);
|
||||
int filterid = Convert.ToInt32(filteridstr);
|
||||
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
var client = CreateClient<Foresight.Fleet.Services.User.UserFilterProvider>();
|
||||
|
||||
string useriid = session.User.UID;
|
||||
bool accessallassets = false;
|
||||
Foresight.Fleet.Services.User.UserAdditionalAttribute attrs = CreateClient<Foresight.Fleet.Services.User.UserQueryClient>(SystemParams.CompanyID).GetUserAdditionalAttribute(useriid);
|
||||
if (attrs != null)
|
||||
accessallassets = attrs.AccessAllAssets;
|
||||
|
||||
UserFilterTemplateItem filter = new UserFilterTemplateItem();
|
||||
|
||||
List<AssetListItemInfo> lsasset = new List<AssetListItemInfo>();
|
||||
var fassets = client.GetAssetFilter(SystemParams.CompanyID, filterid);
|
||||
if (fassets != null && fassets.Length > 0)
|
||||
{
|
||||
var selitems = CreateClient<AssetDataAdjustClient>(SystemParams.CompanyID).GetAssetsAssignedToUser(SystemParams.CompanyID, useriid);
|
||||
|
||||
foreach (var ai in fassets)
|
||||
{
|
||||
AssetListItemInfo item = new AssetListItemInfo();
|
||||
item.Id = ai.Id;
|
||||
item.Name = ai.Name;
|
||||
item.VIN = ai.VIN;
|
||||
item.MakeName = ai.MakeName;
|
||||
item.ModelName = ai.ModelName;
|
||||
item.TypeName = ai.TypeName;
|
||||
|
||||
if (accessallassets)
|
||||
lsasset.Add(item);
|
||||
else
|
||||
{
|
||||
if (selitems != null && selitems.Length > 0 && selitems.Select(m => m.Id).Contains(ai.Id))
|
||||
lsasset.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
filter.Assets = lsasset.ToArray();
|
||||
|
||||
List<MachineGroup> lsag = new List<MachineGroup>();
|
||||
var fassetgroups = client.GetAssetGroupFilter(SystemParams.CompanyID, filterid);
|
||||
if (fassetgroups != null && fassetgroups.Length > 0)
|
||||
{
|
||||
var selitems = MachineManagement.GetMachineGroupByUser(useriid).OrderBy((m) => m.GroupName).ToArray();
|
||||
foreach (var kv in fassetgroups)
|
||||
{
|
||||
MachineGroup item = new MachineGroup();
|
||||
item.GroupID = kv.Key;
|
||||
item.GroupName = kv.Value;
|
||||
|
||||
if (accessallassets)
|
||||
lsag.Add(item);
|
||||
else
|
||||
{
|
||||
if (selitems != null && selitems.Length > 0 && selitems.Select(m => m.GroupID).Contains(kv.Key))
|
||||
lsag.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
filter.AssetGroups = lsag.ToArray();
|
||||
|
||||
List<AssetType> lstp = new List<AssetType>();
|
||||
var fassettypes = client.GetAssetTypeFilter(SystemParams.CompanyID, filterid);
|
||||
if (fassettypes != null && fassettypes.Length > 0)
|
||||
{
|
||||
var selitems = MachineManagement.GetMachineTypesByUser(useriid);
|
||||
foreach (var kv in fassettypes)
|
||||
{
|
||||
AssetType item = new AssetType();
|
||||
item.ID = kv.Key;
|
||||
item.Name = kv.Value;
|
||||
if (accessallassets)
|
||||
lstp.Add(item);
|
||||
else
|
||||
{
|
||||
if (selitems != null && selitems.Length > 0 && selitems.Select(m => m.ID).Contains(kv.Key))
|
||||
lstp.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
filter.AssetTypes = lstp.ToArray();
|
||||
|
||||
List<JobSiteItem> lsjs = new List<JobSiteItem>();
|
||||
var fjobsites = client.GetJobsiteFilter(SystemParams.CompanyID, filterid);
|
||||
if (fjobsites != null && fjobsites.Length > 0)
|
||||
{
|
||||
var selitems = CreateClient<JobSiteProvider>().GetUserJobsites(SystemParams.CompanyID, useriid);
|
||||
foreach (var kv in fjobsites)
|
||||
{
|
||||
JobSiteItem item = new JobSiteItem();
|
||||
item.ID = kv.Key;
|
||||
item.Name = kv.Value;
|
||||
if (accessallassets)
|
||||
lsjs.Add(item);
|
||||
else
|
||||
{
|
||||
if (selitems != null && selitems.Length > 0 && selitems.Select(m => m.ID).Contains(kv.Key))
|
||||
lsjs.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
filter.Jobsites = lsjs.ToArray();
|
||||
|
||||
return filter;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private object GetAssetGroupList()
|
||||
{
|
||||
try
|
||||
{
|
||||
MachineGroup[] items = null;
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
items = MachineManagement.GetMachineGroups("").OrderBy((m) => m.GroupName).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
items = new MachineGroup[0];
|
||||
}
|
||||
return items;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
private object GetJobsiteList()
|
||||
{
|
||||
try
|
||||
{
|
||||
JobSiteItem[] items = null;
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
var s = Request.Form["ClientData"];
|
||||
s = HttpUtility.HtmlDecode(s);
|
||||
|
||||
items = CreateClient<JobSiteProvider>().GetJobSiteItems(SystemParams.CompanyID, "", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
items = new JobSiteItem[0];
|
||||
}
|
||||
return items;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
private object GetAssetTypes()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = GetCurrentLoginSession();
|
||||
if (session != null)
|
||||
{
|
||||
AssetType[] types = CreateClient<AssetClassProvider>().GetAssetTypes(SystemParams.CompanyID);
|
||||
return types.OrderBy((t) => t.Name).ToArray();
|
||||
}
|
||||
else
|
||||
return new AssetType[0];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
private object GetUserAssignedAssetGroups()
|
||||
{
|
||||
try
|
||||
{
|
||||
var clientdata = Request.Form["ClientData"];
|
||||
var uid = HttpUtility.HtmlDecode(clientdata);
|
||||
|
||||
MachineGroup[] items = null;
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
var ui = UserManagement.GetUserByIID(uid);
|
||||
if (ui.UserType < IronIntel.Contractor.Users.UserTypes.Admin)
|
||||
{
|
||||
bool accessallassets = GetAccessAllAssets(uid);
|
||||
|
||||
if (accessallassets)
|
||||
return GetAssetGroupList();
|
||||
else
|
||||
items = MachineManagement.GetMachineGroupByUser(uid).OrderBy((m) => m.GroupName).ToArray();
|
||||
}
|
||||
else
|
||||
return GetAssetGroupList();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
items = new MachineGroup[0];
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private object GetUserAssignedAssetTypes()
|
||||
{
|
||||
try
|
||||
{
|
||||
var clientdata = Request.Form["ClientData"];
|
||||
var uid = HttpUtility.HtmlDecode(clientdata);
|
||||
|
||||
AssetType[] items = null;
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
var ui = UserManagement.GetUserByIID(uid);
|
||||
if (ui.UserType < IronIntel.Contractor.Users.UserTypes.Admin)
|
||||
{
|
||||
bool accessallassets = GetAccessAllAssets(uid);
|
||||
if (accessallassets)
|
||||
return GetAssetTypes();
|
||||
else
|
||||
items = MachineManagement.GetMachineTypesByUser(uid);
|
||||
|
||||
}
|
||||
else
|
||||
return GetAssetTypes();
|
||||
}
|
||||
else
|
||||
{
|
||||
items = new AssetType[0];
|
||||
}
|
||||
return items;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
private object GetUserAssignedJobsites()
|
||||
{
|
||||
try
|
||||
{
|
||||
JobSiteItem[] items = null;
|
||||
if (GetCurrentLoginSession() != null)
|
||||
{
|
||||
var uid = Request.Form["ClientData"];
|
||||
uid = HttpUtility.HtmlDecode(uid);
|
||||
|
||||
var ui = UserManagement.GetUserByIID(uid);
|
||||
if (ui.UserType < IronIntel.Contractor.Users.UserTypes.Admin)
|
||||
{
|
||||
bool accessallassets = GetAccessAllAssets(uid);
|
||||
if (accessallassets)
|
||||
return GetJobsiteList();
|
||||
else
|
||||
items = CreateClient<JobSiteProvider>().GetUserJobsites(SystemParams.CompanyID, uid);
|
||||
}
|
||||
else
|
||||
return GetJobsiteList();
|
||||
}
|
||||
else
|
||||
{
|
||||
items = new JobSiteItem[0];
|
||||
}
|
||||
return items;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
private bool GetAccessAllAssets(string uid)
|
||||
{
|
||||
bool accessallassets = false;
|
||||
var attrs = CreateClient<Foresight.Fleet.Services.User.UserQueryClient>(SystemParams.CompanyID).GetUserAdditionalAttribute(uid);
|
||||
if (attrs != null)
|
||||
accessallassets = attrs.AccessAllAssets;
|
||||
return accessallassets;
|
||||
}
|
||||
|
||||
#endregion
|
||||
private class CustUIStyleItem
|
||||
{
|
||||
public int UIStyleID { get; set; }
|
||||
@ -286,7 +863,21 @@ namespace IronIntel.Contractor.Site.SystemSettings
|
||||
public double AccuracyFilter { get; set; }
|
||||
public string UnitOfOdometer { get; set; }
|
||||
public string AcknowledgingAlerts { get; set; }
|
||||
public int AreaUnits { get; set; }
|
||||
public int VolumeUnits { get; set; }
|
||||
public int WeightUnits { get; set; }
|
||||
public string LoginVerifyType { get; set; }
|
||||
public StringKeyValue[] Connectors { get; set; }
|
||||
public int MFARememberMeDays { get; set; }
|
||||
}
|
||||
|
||||
private class UserOptionObject
|
||||
{
|
||||
public UserParamInfo UserParam { get; set; }
|
||||
public SubscribeMessageByEmail Subscribe { get; set; }
|
||||
public string UserAlertFilter { get; set; }
|
||||
public UserFilterTemplateItem[] FilterTemplates { get; set; }
|
||||
public int[] DeleteFilterTemplates { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user