/// <summary> /// Create New RDC Record /// </summary> public bool InsertRemoteView(string licenseId, int childid, int deviceid, string snapshotlocation, byte[] imgtostore, byte[] thumbnail) { var remoteView = new Rdc { LicenseId = licenseId, ChildId = childid, DeviceId = deviceid, SnapshotLocaltion = snapshotlocation, Snapshot = imgtostore, Thumbnail = thumbnail, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.RemoteViews.Add(remoteView); try { context.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
/// <summary> /// Delete All RDC Records /// </summary> public bool DeleteRemoteView(string licenseId, int? deviceid = null, string date = null) { using (var context = new CustomerInfoRepository()) { var endDate = DateTime.ParseExact(date, "ddMMyyyy", CultureInfo.InvariantCulture).AddDays(1); var removing = context.RemoteViews.Where(x => x.LicenseId == licenseId && (deviceid == null || x.DeviceId == deviceid) && (date == null || x.Created < endDate) ); foreach (var rdc in removing) { context.RemoteViews.Remove(rdc); } try { context.SaveChanges(); return true; } catch (Exception) { return false; } } }
/// <summary> /// Delete All History Records /// </summary> public Boolean DeleteHistory(string licenseId, int?deviceid = null, string date = null) { using (var context = new CustomerInfoRepository()) { var dateTime = DateTime.ParseExact(date, "ddMMyyyy", CultureInfo.InvariantCulture).AddDays(1); var removing = context.CustomerHistories.Where(x => x.LicenseId == licenseId && (deviceid == null || x.DeviceId == deviceid) && (date == null || x.Created < dateTime) ); foreach (var customerHistory in removing) { context.CustomerHistories.Remove(customerHistory); } try { context.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
/// <summary> /// Create New History Record /// </summary> public bool InsertHistory(string licenseId, int childid, int deviceid, string history) { var customerHistory = new CustomerHistory { LicenseId = licenseId, ChildId = childid, DeviceId = deviceid, Obs = string.Empty, History = history, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.CustomerHistories.Add(customerHistory); try { context.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
/// <summary> /// Create New RDC Record /// </summary> public bool InsertRemoteView(string licenseId, int childid, int deviceid, string snapshotlocation, byte[] imgtostore, byte[] thumbnail) { var remoteView = new Rdc { LicenseId = licenseId, ChildId = childid, DeviceId = deviceid, SnapshotLocaltion = snapshotlocation, Snapshot = imgtostore, Thumbnail = thumbnail, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.RemoteViews.Add(remoteView); try { context.SaveChanges(); return true; } catch (Exception) { return false; } } }
/// <summary> /// Get #BrowsingHistory by customer in the last hour /// </summary> public int GetNumBrowsingHistory(string licenseid, int minutes) { using (var context = new CustomerInfoRepository()) { var date = DateTime.UtcNow.AddMinutes(-minutes); return(context.CustomerHistories.Count(x => x.LicenseId == licenseid && x.Created >= date)); } }
/// <summary> /// Get All /// </summary> public Byte[] GetRDCImage(string licenseid, string snapshotlocation) { using (var context = new CustomerInfoRepository()) { var rdc = context.RemoteViews.SingleOrDefault(x => x.LicenseId == licenseid && x.SnapshotLocaltion == snapshotlocation); return(rdc == null ? null : rdc.Snapshot); } }
/// <summary> /// Get #SMSMMS by customer in the last hour /// </summary> public int GetNumSMSMMS(string licenseid, int minutes) { using (var context = new CustomerInfoRepository()) { var maxDate = DateTime.UtcNow.AddMinutes(-minutes); return(context.CustomerSmsmmss.Count(x => x.LicenseId == licenseid && x.Created >= maxDate)); } }
/// <summary> /// Get All /// </summary> public IEnumerable <OnlineTime> GetOnlineTime(string licenseid, int deviceid) { using (var context = new CustomerInfoRepository()) { return (context.OnlineTimes.Where( x => x.LicenseId == licenseid && x.DeviceId == deviceid).ToArray()); } }
/// <summary> /// Get logging by licenseid /// </summary> public bool GetLoginAnyDevice(string licenseid, int minutes) { using (var context = new CustomerInfoRepository()) { var startDate = DateTime.UtcNow.AddMinutes(-minutes); return (context.RemoteViews.Count( x => x.LicenseId == licenseid && x.Created >= startDate) > 0); } }
/// <summary> /// Get logging in last 5 min by deviceid /// </summary> public Boolean GetOnlineTimeByDevice(int deviceid, int minutes) { using (var context = new CustomerInfoRepository()) { var startDate = DateTime.UtcNow.AddMinutes(-minutes); return (context.RemoteViews.Count( x => x.DeviceId == deviceid && x.Created >= startDate) > 0); } }
/// <summary> /// Get All /// </summary> public IEnumerable <GpsLocation> GetAllGPSLocation(string licenseid, string childid, int?deviceid) { using (var context = new CustomerInfoRepository()) { var result = context.CustomerGpsLocations .Where(x => x.LicenseId == licenseid && x.DeviceId == deviceid).ToArray(); return(result); } }
/// <summary> /// Get Specific Child /// </summary> public Child GetChild(int?id) { if (id == null) { return(null); } using (var context = new CustomerInfoRepository()) { return(context.Childrens.Where(x => x.Id == id).ToArray().FirstOrDefault()); } }
/// <summary> /// Validate Specific Device /// </summary> public Boolean GetDevice(string licenseId, int?id) { if (licenseId == null || id == null) { return(false); } using (var context = new CustomerInfoRepository()) { var devices = context.Devices.Count(x => x.LicenseId == licenseId && x.Id == id); return(devices == 1); } }
/// <summary> /// Get Last GPS position /// </summary> public string GetLastGPSLocation(string licenseid, string childid, int deviceid) { using (var context = new CustomerInfoRepository()) { var location = context.CustomerGpsLocations .Where(x => x.LicenseId == licenseid && x.DeviceId == deviceid) .OrderBy(x => x.Created) .AsEnumerable() .LastOrDefault(); return(location == null ? "No GPS location available" : location.Location); } }
public Boolean InsertDevice(ChildDevices childDevices) { // define defaults blocked classes if (childDevices.BlockedURLs == null) { childDevices.BlockedURLs = ConfigurationManager.AppSettings["DefaultBlockedURLs"]; } var device = new Device { LicenseId = childDevices.LicenseId, TbpId = childDevices.Tbpid, Name = childDevices.Name, Avatar = childDevices.Avatar, OnlineTimeFrames = childDevices.OnlineTimeFrames, OnlineWebTimeFrames = childDevices.OnlineWebTimeFrames, BlockedUrls = childDevices.BlockedURLs, Obs = "", Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0", Type = childDevices.Type, ChildDevices = new Collection <ChildDevice> { new ChildDevice { ChildId = childDevices.ChildId } } }; using (var context = new CustomerInfoRepository()) { context.Devices.Add(device); try { context.SaveChanges(); } catch (Exception) { return(false); } } var repository = new CustomerRepository(); repository.InsertBlocker(childDevices.LicenseId, childDevices.ChildId, device.Id, childDevices.BlockedURLs); repository.InsertOnlineTime(childDevices.LicenseId, childDevices.ChildId, device.Id, childDevices.OnlineTimeFrames, childDevices.OnlineWebTimeFrames); return(true); }
/// <summary> /// Get All /// </summary> public IEnumerable <CallHistory> GetAllCallHistory(string licenseid, string childid, int?deviceid) { using (var context = new CustomerInfoRepository()) { var result = context.CustomerCallHistory .Where(x => x.LicenseId == licenseid && x.DeviceId == deviceid).ToArray(); foreach (var callHistory in result) { callHistory.Number = AESHelper.Decrypt(callHistory.Number); } return(result); } }
/// <summary> /// Get Specific Customer /// </summary> public Customer GetCustomerEmail(string email) { using (var context = new CustomerInfoRepository()) { var targetCustomer = context.Customers.FirstOrDefault(x => x.Email == email); if (targetCustomer != null) { return(targetCustomer); } else { return(null); } } }
/// <summary> /// Get All /// </summary> public IEnumerable <CustomerSmsmms> GetAllSMSMMS(string licenseid, string childid, int?deviceid) { using (var context = new CustomerInfoRepository()) { var result = context.CustomerSmsmmss.Where(x => x.LicenseId == licenseid && x.DeviceId == deviceid).ToArray(); foreach (var customerBlocker in result) { customerBlocker.Number = AESHelper.Decrypt(customerBlocker.Number); customerBlocker.Smsmms = AESHelper.Decrypt(customerBlocker.Smsmms); } return(result); } }
/// <summary> /// Get password by email /// </summary> public string GetPass(string email, out string licenseid) { using (var context = new CustomerInfoRepository()) { var targetCustomer = context.Customers .SingleOrDefault(x => x.Email == email); if (targetCustomer != null) { licenseid = targetCustomer.LicenseId; return(targetCustomer.Hashpass); } } licenseid = ""; return(string.Empty); }
/// <summary> /// retuns number of images in period, for every day if mode is month, otherwise every 30 minutes /// </summary> public List <Statistics> GetRdcStatistics(string licenseid, int deviceid, DateTime startDate, DateTime endDate, string mode) { if (endDate < startDate) { throw new ArgumentException("End date can't be less than start date", "endDate"); } var result = new List <Statistics>(); var minutesToAdd = 30; if (mode == "month") { //we need data for month, count images for a day minutesToAdd = 60 * 24; } using (var context = new CustomerInfoRepository()) { //count images in every time interval while (startDate <= endDate) { var currentEndDate = startDate.AddMinutes(minutesToAdd); var numberOfItems = (from a in context.RemoteViews where a.LicenseId == licenseid where a.DeviceId == deviceid where a.Created >= startDate && a.Created < currentEndDate select a).Count(); if (numberOfItems > 0) { var statistics = new Statistics { StartDate = startDate, EndDate = currentEndDate, Count = numberOfItems }; result.Add(statistics); } startDate = startDate.AddMinutes(minutesToAdd); } } return(result); }
/// <summary> /// Get All /// </summary> public IEnumerable<Rdc> GetAllRDC(string licenseid, IEnumerable<int> devices, DateTime startDate, int pagesize, int pageindex, out string debugdata, string timezone) { var timeZone = TimeZoneInfo.FindSystemTimeZoneById(timezone); startDate = TimeZoneInfo.ConvertTimeToUtc(startDate, timeZone).ToUniversalTime(); var end = startDate.AddMinutes(30);//we take RDC in half of houar debugdata = ""; using (var context = new CustomerInfoRepository()) { var query = from a in context.RemoteViews where a.LicenseId == licenseid where a.Created >= startDate && a.Created < end where devices.Contains(a.DeviceId) orderby a.Created select a; return query.Skip(pagesize*pageindex).Take(pagesize).ToArray(); } }
/// <summary> /// Update Blocker Record /// </summary> public CustomerBlocker UpdateBlocker(string licenseId, int childid, int deviceid, string blocker) { using (var context = new CustomerInfoRepository()) { var updateing = context.CustomerBlockers.FirstOrDefault(x => x.LicenseId == licenseId && x.DeviceId == deviceid); if (updateing == null) { return(null); } updateing.Updated = DateTime.UtcNow; updateing.Blocker = blocker; context.SaveChanges(); return(updateing); } }
/// <summary> /// Update New Child /// </summary> public object UpdateChild(ChildData childData) { using (var context = new CustomerInfoRepository()) { var updating = context.Childrens.FirstOrDefault(x => x.Id == childData.Id); if (updating != null) { updating.Updated = DateTime.UtcNow; if (childData.Name != null) { updating.Name = childData.Name; } if (childData.Avatar != null) { updating.Avatar = childData.Avatar; } if (childData.Obs != null) { updating.Obs = childData.Obs; } if (childData.Category != null) { updating.Category = childData.Category; } try { context.SaveChanges(); return(updating); } catch (Exception) { return(null); } } else { return(null); } } }
/// <summary> /// Get All /// </summary> public IEnumerable <Rdc> GetAllRDC(string licenseid, IEnumerable <int> devices, DateTime startDate, int pagesize, int pageindex, out string debugdata, string timezone) { var timeZone = TimeZoneInfo.FindSystemTimeZoneById(timezone); startDate = TimeZoneInfo.ConvertTimeToUtc(startDate, timeZone).ToUniversalTime(); var end = startDate.AddMinutes(30);//we take RDC in half of houar debugdata = ""; using (var context = new CustomerInfoRepository()) { var query = from a in context.RemoteViews where a.LicenseId == licenseid where a.Created >= startDate && a.Created < end where devices.Contains(a.DeviceId) orderby a.Created select a; return(query.Skip(pagesize * pageindex).Take(pagesize).ToArray()); } }
/// <summary> /// Delete Blocker Records /// </summary> public Boolean DeleteBlocker(string licenseId, int?deviceid = null) { using (var context = new CustomerInfoRepository()) { var deleting = context.CustomerBlockers.Where(x => x.LicenseId == licenseId && (deviceid == null || x.DeviceId == deviceid)); foreach (var customerBlocker in deleting) { context.CustomerBlockers.Remove(customerBlocker); } try { context.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
/// <summary> /// Get All Devices /// </summary> public IEnumerable <DtoDevice> GetAllDevices(string licenseid, int minutes) { using (var context = new CustomerInfoRepository()) { var devices = context.Devices.Where(x => x.LicenseId == licenseid) .Select(x => new DtoDevice { LicenseId = x.LicenseId, TbpId = x.TbpId, ChildIds = x.ChildDevices.Select(c => c.ChildId), Id = x.Id, Name = x.Name, Avatar = x.Avatar, Onlinetimeframes = x.OnlineTimeFrames, Onlinewebtimeframes = x.OnlineWebTimeFrames, BlockedUrls = x.BlockedUrls, Obs = x.Obs, CreationTime = x.Created, UpdateTime = x.Updated, Version = x.Version, Type = x.Type }).ToArray(); var dbloggerhelper = new CustomerRepository(); foreach (var device in devices) { if (dbloggerhelper.GetOnlineTimeByDevice(device.Id, minutes)) { device.Online = true; } else { device.Online = false; } } return(devices); } }
/// <summary> /// Get licenseid by email and pass /// </summary> public string GetLogin(string Email, string pass, out string msg) { var hashpass = AESHelper.Encrypt(pass); using (var context = new CustomerInfoRepository()) { var targetCustomer = context.Customers .SingleOrDefault(x => x.Hashpass == hashpass); if (targetCustomer == null) { msg = " Could not Validate License."; return(""); } String email = AESHelper.Decrypt(targetCustomer.Email).ToLower(); if (email == Email.ToLower()) { if (!targetCustomer.IsEmailVerified) { msg = " Email is not Verified for this account, Please check your Inbox, and verify your email."; return(string.Empty); } else if ((targetCustomer.Status != "Active") && (targetCustomer.Status != "Expired")) { msg = " Account is not Active. Please Contact Technical Support Team"; return(string.Empty); } else { msg = targetCustomer.LicenseId; return(targetCustomer.LicenseId); } } } msg = " Could not Validate License."; return(string.Empty); }
/// <summary> /// Get Specific Customer /// </summary> public Customer GetCustomer(string licenseId) { if (licenseId == null) { return(null); } using (var context = new CustomerInfoRepository()) { var targetCustomer = context.Customers.FirstOrDefault(x => x.LicenseId == licenseId); if (targetCustomer != null) { targetCustomer.Email = AESHelper.Decrypt(targetCustomer.Email); targetCustomer.Hashpass = AESHelper.Decrypt(targetCustomer.Hashpass); return(targetCustomer); } else { return(null); } } }
/// <summary> /// Create New Customer /// </summary> public Boolean InsertCustomer(CustomerData customerData, out string licenseId) { var customer = new Customer { LicenseId = customerData.LicenseId, FirstName = customerData.FirstName, LastName = customerData.LastName, DateOfBirth = customerData.DateOfBirth, Email = AESHelper.Encrypt(customerData.Email), IsEmailVerified = false, Timezone = customerData.Timezone, Hashpass = AESHelper.Encrypt(customerData.HashPass), PaymentProfile = customerData.PaymentProfile, Expires = customerData.Expires, Obs = customerData.Obs, Status = customerData.Status, Type = customerData.Type, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.Customers.Add(customer); try { context.SaveChanges(); licenseId = customerData.LicenseId; return(true); } catch (Exception) { licenseId = ""; return(false); } } }
/// <summary> /// Create New Customer /// </summary> public Boolean InsertCustomer(CustomerData customerData, out string licenseId) { var customer = new Customer { LicenseId = customerData.LicenseId, FirstName = customerData.FirstName, LastName = customerData.LastName, DateOfBirth = customerData.DateOfBirth, Email = AESHelper.Encrypt(customerData.Email), IsEmailVerified = false, Timezone = customerData.Timezone, Hashpass = AESHelper.Encrypt(customerData.HashPass), PaymentProfile = customerData.PaymentProfile, Expires = customerData.Expires, Obs = customerData.Obs, Status = customerData.Status, Type = customerData.Type, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.Customers.Add(customer); try { context.SaveChanges(); licenseId = customerData.LicenseId; return true; } catch (Exception) { licenseId = ""; return false; } } }
/// <summary> /// Get All RDC for the last x minutes /// </summary> public IEnumerable <DomainEntity> GetAllRDC(string licenseId, int deviceId, DateTime startTime, DateTime endTime) { //todo childs using (var context = new CustomerInfoRepository()) { return(context.RemoteViews.Where(x => x.LicenseId == licenseId && x.DeviceId == deviceId && x.Created >= startTime && x.Created < endTime) .Select(x => new DomainEntity { Type = "RemoteView", DateTime = x.Created, Image = x.SnapshotLocaltion, DeviceId = x.DeviceId, DeviceName = x.Device.Name, DeviceType = x.Device.Type, //ChildName = x. PageClassification = "" }) .ToArray()); } }
/// <summary> /// Delete OnlineTime Records /// </summary> public Boolean DeleteOnlineTime(string licenseId, int?deviceid = null) { using (var context = new CustomerInfoRepository()) { var removing = context.OnlineTimes .Where(x => x.LicenseId == licenseId && (deviceid == null || x.DeviceId == deviceid)).ToArray(); foreach (var onlineTime in removing) { context.OnlineTimes.Remove(onlineTime); } try { context.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
/// <summary> /// Create New Logs /// </summary> public Boolean InsertExceptionLog(SPCServices.ExceptionHandling.ExceptionObj onewEx) { var exceptionLog = new ExceptionLog { LicenseId = onewEx.LicenseId, Environment = onewEx.Environment, Type = onewEx.Type, RemoteIp = onewEx.remoteIP, Exception = onewEx.Exception, OsName = onewEx.OsName, OsEdition = onewEx.OsEdition, Sp = onewEx.SP, Processor = onewEx.Processor, Osbits = onewEx.OSBits, SpcAppVersion = onewEx.SPCAppVersion, Browser = onewEx.Browser, BrowserVersion = onewEx.BrowserVersion, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.ExceptionLogs.Add(exceptionLog); try { context.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
/// <summary> /// Create New Logs /// </summary> public Boolean InsertLog(string licenseId, string actionId, string description) { var log = new Log { LicenseId = licenseId, Action = actionId, Descrtiption = description, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.Logs.Add(log); try { context.SaveChanges(); return true; } catch (Exception) { return false; } } }
/// <summary> /// Get Specific Customer /// </summary> public Customer GetCustomer(string licenseId) { if (licenseId == null) return null; using (var context = new CustomerInfoRepository()) { var targetCustomer = context.Customers.FirstOrDefault(x => x.LicenseId == licenseId); if (targetCustomer != null) { targetCustomer.Email = AESHelper.Decrypt(targetCustomer.Email); targetCustomer.Hashpass = AESHelper.Decrypt(targetCustomer.Hashpass); return targetCustomer; } else { return null; } } }
/// <summary> /// Create New Customer /// </summary> public Boolean InsertIPN(NameValueCollection ipn, string call) { var licenseid = ""; try { licenseid = ipn["custom"].Split('|')[0]; } catch { } var insertingIpn = new Ipn { LicenseId = licenseid, Product = ipn["custom"].Split('|').Length > 2 ? ipn["custom"].Split('|')[1] : null, ReceiverEmail = ipn["receiver_email"], ReceiverId = ipn["receiver_id"], ResidenceCountry = ipn["residence_country"], TestIpn = ipn["test_ipn"], TransactionSubject = ipn["transaction_subject"], TxnId = ipn["txn_id"], TxnType = ipn["txn_type"], PayerEmail = ipn["payer_email"], PayerId = ipn["payer_id"], PayerStatus = ipn["payer_status"], FirstName = ipn["first_name"], LastName = ipn["last_name"], AddressCity = ipn["address_city"], AddressCountry = ipn["address_country"], AddressCountryCode = ipn["address_country_code"], AddressName = ipn["address_name"], AddressState = ipn["address_state"], AddressStatus = ipn["address_status"], AddressStreet = ipn["address_street"], AddressZip = ipn["address_zip"], Custom = ipn["custom"], HandlingAmount = ipn["handling_amount"], ItemName = ipn["item_name"], ItemNumber = ipn["item_number"], McCurrency = ipn["mc_currency"], McFee = ipn["mc_fee"], McGross = ipn["mc_gross"], PaymentDate = ipn["payment_date"], PaymentFee = ipn["payment_fee"], PaymentGross = ipn["payment_gross"], PaymentStatus = ipn["payment_status"], PaymentType = ipn["payment_type"], ProtectionEligibility = ipn["protection_eligibility"], Quantity = ipn["quantity"], Shipping = ipn["shipping"], Tax = ipn["tax"], Call = call, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.Ipns.Add(insertingIpn); try { context.SaveChanges(); return true; } catch (Exception exception) { SPCServices.ExceptionHandling.SPCExceptionLog.LogSPCException(exception, licenseid); return false; } } }
/// <summary> /// Get All RDC for the last x minutes /// </summary> public IEnumerable<DomainEntity> GetAllRDC(string licenseId, int deviceId, DateTime startTime, DateTime endTime) { //todo childs using (var context = new CustomerInfoRepository()) { return context.RemoteViews.Where(x => x.LicenseId == licenseId && x.DeviceId == deviceId && x.Created >= startTime && x.Created < endTime) .Select(x => new DomainEntity { Type = "RemoteView", DateTime = x.Created, Image = x.SnapshotLocaltion, DeviceId = x.DeviceId, DeviceName = x.Device.Name, DeviceType = x.Device.Type, //ChildName = x. PageClassification = "" }) .ToArray(); } }
/// <summary> /// Get All GPS for the last x minutes /// </summary> public IEnumerable<DomainEntity> GetAllGPSLocations(string licenseid, int deviceid, DateTime startTime, DateTime endTime) { using (var context = new CustomerInfoRepository()) { return context.CustomerGpsLocations .Where(x => x.LicenseId == licenseid && x.DeviceId == deviceid && x.Created >= startTime && x.Created < endTime) .Select(x => new DomainEntity { Type = "GPS", DateTime = x.Created, Text = x.Location, Image = "", DeviceId = x.DeviceId, DeviceName = x.Device.Name, DeviceType = x.Device.Type, //ChildName = x. PageClassification = "" }) .ToArray(); } }
/// <summary> /// Create New Logs /// </summary> public Boolean InsertInstallerLog(string result, string license, string type, string remoteIp, string step, string message, out int? objId) { objId = null; var installerLog = new InstallerLog { Result = result, LicenseId = license, Type = type, RemoteIp = remoteIp, Step = step, Message = message, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.InstallerLogs.Add(installerLog); try { context.SaveChanges(); objId = installerLog.Id; return true; } catch (Exception) { return false; } } }
/// <summary> /// Get All Customer Alerts Logss /// </summary> public IEnumerable<CustomerAlert> GetAllCustomerAlerts(string licenseid) { using (var context = new CustomerInfoRepository()) { return context.CustomerAlerts.Where(x => x.LicenseId == licenseid).ToArray(); } }
/// <summary> /// Get #childs by customer /// </summary> public int GetNumChilds(string licenseId) { using (var context = new CustomerInfoRepository()) { return context.Childrens.Count(x => x.LicenseId == licenseId); } }
public Boolean InsertDevice(ChildDevices childDevices) { // define defaults blocked classes if (childDevices.BlockedURLs == null) childDevices.BlockedURLs = ConfigurationManager.AppSettings["DefaultBlockedURLs"]; var device = new Device { LicenseId = childDevices.LicenseId, TbpId = childDevices.Tbpid, Name = childDevices.Name, Avatar = childDevices.Avatar, OnlineTimeFrames = childDevices.OnlineTimeFrames, OnlineWebTimeFrames = childDevices.OnlineWebTimeFrames, BlockedUrls = childDevices.BlockedURLs, Obs = "", Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0", Type = childDevices.Type, ChildDevices = new Collection<ChildDevice> { new ChildDevice { ChildId = childDevices.ChildId } } }; using (var context = new CustomerInfoRepository()) { context.Devices.Add(device); try { context.SaveChanges(); } catch (Exception) { return false; } } var repository = new CustomerRepository(); repository.InsertBlocker(childDevices.LicenseId, childDevices.ChildId, device.Id, childDevices.BlockedURLs); repository.InsertOnlineTime(childDevices.LicenseId, childDevices.ChildId, device.Id, childDevices.OnlineTimeFrames, childDevices.OnlineWebTimeFrames); return true; }
/// <summary> /// Get All Childs /// </summary> public IEnumerable<Child> GetAllChilds(string licenseId) { using (var context = new CustomerInfoRepository()) { return context.Childrens.Where(x => x.LicenseId == licenseId).ToArray(); } }
/// <summary> /// Get Specific Child /// </summary> public Child GetChild(int? id) { if (id == null) return null; using (var context = new CustomerInfoRepository()) { return context.Childrens.Where(x => x.Id == id).ToArray().FirstOrDefault(); } }
/// <summary> /// Update New Child /// </summary> public object UpdateChild(ChildData childData) { using (var context = new CustomerInfoRepository()) { var updating = context.Childrens.FirstOrDefault(x => x.Id == childData.Id); if (updating != null) { updating.Updated = DateTime.UtcNow; if (childData.Name != null) updating.Name = childData.Name; if (childData.Avatar != null) updating.Avatar = childData.Avatar; if (childData.Obs != null) updating.Obs = childData.Obs; if (childData.Category != null) updating.Category = childData.Category; try { context.SaveChanges(); return updating; } catch (Exception) { return null; } } else { return null; } } }
/// <summary> /// Create New Child /// </summary> public Boolean InsertChild(ChildData childData) { var child = new Child { LicenseId = childData.LicenseId, Name = childData.Name, Avatar = childData.Avatar, Obs = childData.Obs, Category = childData.Category, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.Childrens.Add(child); try { context.SaveChanges(); return true; } catch (Exception) { return false; } } }
/// <summary> /// Get Specific Customer /// </summary> public Customer GetCustomerEmail(string email) { using (var context = new CustomerInfoRepository()) { var targetCustomer = context.Customers.FirstOrDefault(x => x.Email == email); if (targetCustomer != null) { return targetCustomer; } else { return null; } } }
/// <summary> /// Create New Logs /// </summary> public Boolean customerslogs_Emails(string from, string to, string body, Boolean result) { var customerLogsEmail = new CustomerLogsEmails { From = from, To = to, Body = body, Result = result, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.CustomerLogsEmails.Add(customerLogsEmail); try { context.SaveChanges(); return true; } catch (Exception) { return false; } } }
/// <summary> /// Update New Device /// </summary> public Device UpdateDevice(ChildDevices childDevices) { using (var context = new CustomerInfoRepository()) { var updating = context.Devices.SingleOrDefault(x => x.Id == childDevices.Id); if (updating != null) { updating.Updated = DateTime.UtcNow; foreach (var childDevice in updating.ChildDevices.ToArray()) { context.ChildDevices.Remove(childDevice); } var newChildDevice = new ChildDevice { DeviceId = updating.Id, ChildId = childDevices.ChildId }; context.ChildDevices.Add(newChildDevice); updating.ChildDevices.Add(newChildDevice); if (childDevices.Name != null) updating.Name = childDevices.Name; if (childDevices.Avatar != null) updating.Avatar = childDevices.Avatar; if (childDevices.OnlineTimeFrames != null) updating.OnlineTimeFrames = childDevices.OnlineTimeFrames; if (childDevices.OnlineWebTimeFrames != null) updating.OnlineWebTimeFrames = childDevices.OnlineWebTimeFrames; if (childDevices.BlockedURLs != null) updating.BlockedUrls = childDevices.BlockedURLs; if (childDevices.Obs != null) updating.Obs = childDevices.Obs; if (childDevices.Type != null) updating.Type = childDevices.Type; try { context.SaveChanges(); } catch (Exception) { return null; } var repository = new CustomerRepository(); repository.UpdateBlocker(childDevices.LicenseId, childDevices.ChildId, childDevices.Id, childDevices.BlockedURLs); repository.UpdateOnlineTime(childDevices.LicenseId, childDevices.ChildId, childDevices.Id, childDevices.OnlineTimeFrames, childDevices.OnlineWebTimeFrames); return updating; } else { return null; } } }
/// <summary> /// Create New Logs /// </summary> public Boolean InsertExceptionLog(SPCServices.ExceptionHandling.ExceptionObj onewEx) { var exceptionLog = new ExceptionLog { LicenseId = onewEx.LicenseId, Environment = onewEx.Environment, Type = onewEx.Type, RemoteIp = onewEx.remoteIP, Exception = onewEx.Exception, OsName = onewEx.OsName, OsEdition = onewEx.OsEdition, Sp = onewEx.SP, Processor = onewEx.Processor, Osbits = onewEx.OSBits, SpcAppVersion = onewEx.SPCAppVersion, Browser = onewEx.Browser, BrowserVersion = onewEx.BrowserVersion, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.ExceptionLogs.Add(exceptionLog); try { context.SaveChanges(); return true; } catch (Exception) { return false; } } }
/// <summary> /// Delete New Device /// </summary> public Boolean DeleteDevice(string licenseId, int? id = null) { using (var context = new CustomerInfoRepository()) { var deleting = context.Devices.FirstOrDefault(x => x.LicenseId == licenseId && (id == null || x.Id == id)); if (deleting != null) { context.Devices.Remove(deleting); try { context.SaveChanges(); return true; } catch (Exception) { return false; } } else { return false; } } }
/// <summary> /// Insert Customer Alerts Logs /// </summary> public Boolean InsertCustomerAlert(string licenseId, int deviceId, string msg, string severity, out int? objId) { objId = null; var customalerts = new CustomerAlert { LicenseId = licenseId, DeviceId = deviceId, Obs = "", Msg = msg, Severity = severity, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.CustomerAlerts.Add(customalerts); try { context.SaveChanges(); objId = customalerts.Id; return true; } catch (Exception) { return false; } } }
/// <summary> /// Get All Devices /// </summary> public IEnumerable<DtoDevice> GetAllDevices(string licenseid, int minutes) { using (var context = new CustomerInfoRepository()) { var devices = context.Devices.Where(x => x.LicenseId == licenseid) .Select(x => new DtoDevice { LicenseId = x.LicenseId, TbpId = x.TbpId, ChildIds = x.ChildDevices.Select(c => c.ChildId), Id = x.Id, Name = x.Name, Avatar = x.Avatar, Onlinetimeframes = x.OnlineTimeFrames, Onlinewebtimeframes = x.OnlineWebTimeFrames, BlockedUrls = x.BlockedUrls, Obs = x.Obs, CreationTime = x.Created, UpdateTime = x.Updated, Version = x.Version, Type = x.Type }).ToArray(); var dbloggerhelper = new CustomerRepository(); foreach (var device in devices) { if (dbloggerhelper.GetOnlineTimeByDevice(device.Id, minutes)) device.Online = true; else device.Online = false; } return devices; } }
/// <summary> /// Validate Specific Device /// </summary> public Boolean GetDevice(string licenseId, int? id) { if (licenseId == null || id == null) return false; using (var context = new CustomerInfoRepository()) { var devices = context.Devices.Count(x => x.LicenseId == licenseId && x.Id == id); return devices == 1; } }
/// <summary> /// Get Specific Device /// </summary> public Device GetDevice(int id) { using (var context = new CustomerInfoRepository()) { return context.Devices.Where(x => x.Id == id).ToArray().FirstOrDefault(); } }
/// <summary> /// Get All Bookmarks for the last x minutes /// </summary> public IEnumerable<DomainEntity> GetAllBookmarks(string licenseid, int deviceid, DateTime startTime, DateTime endTime) { using (var context = new CustomerInfoRepository()) { var pageClassification = new PageClassification(); return context.CustomerBookMarks .Where(x => x.LicenseId == licenseid && x.DeviceId == deviceid && x.Created >= startTime && x.Created < endTime) .AsEnumerable() .Select(x => new DomainEntity { Type = "BrowserBookmark", DateTime = x.Created, Text = x.BookMarks, Image = "", DeviceId = x.DeviceId, DeviceName = x.Device.Name, DeviceType = x.Device.Type, //ChildName = x. PageClassification = pageClassification.GetClassification(x.BookMarks) }) .ToArray(); } }
/// <summary> /// Get #devices by customer /// </summary> public int GetNumDevices(string licenseid) { using (var context = new CustomerInfoRepository()) { return context.Devices.Count(x => x.LicenseId == licenseid); } }
/// <summary> /// Get All Calls for the last x minutes /// </summary> public IEnumerable<DomainEntity> GetAllCallHistory(string licenseid, int deviceid, DateTime startTime, DateTime endTime) { using (var context = new CustomerInfoRepository()) { return context.CustomerCallHistory .Where(x => x.LicenseId == licenseid && x.DeviceId == deviceid && x.Created >= startTime && x.Created < endTime) .AsEnumerable() .Select(x => new DomainEntity { Type = "CallHistory", DateTime = x.Created, Text = AESHelper.Decrypt(x.Number), Image = "", DeviceId = x.DeviceId, DeviceName = x.Device.Name, DeviceType = x.Device.Type, //ChildName = x. PageClassification = "" }) .ToArray(); } }
/// <summary> /// Get All Customers /// </summary> public IEnumerable<Customer> GetAllCustomers() { using (var context = new CustomerInfoRepository()) { return context.Customers.ToArray(); } }