protected override void Initiliaze() { lock (_lock) { using (var db = new LicenseDbEntities()) { _modules = _modules ?? db.lu_LicenseModules.ToDictionary(x => x.Id, y => y.Name); _licenseLogs = db.LicensesLogs.Select(x => new LicenseLogModel() { Id = x.Id, LicenseId = x.LicenseId, IsDemo = x.IsDemo, ChangedBy = x.ChangedBy, Date = x.Date, Old = x.Old, New = x.New }).ToList(); } foreach (var v in _licenseLogs) { v.Changes = CreateChanges(v.Old, v.New); } } }
public Common.Models.LicenserInfoModel Get(int id) { using (var db = new LicenseDbEntities()) { return(DbHelper.FromDbModel(db.LicenseOwners.FirstOrDefault(x => x.Id == id))); } }
public bool Authorize(string key) { using (var db = new LicenseDbEntities()) { return(db.ApiKeys.Any(x => x.ApiKey1 == key && x.Enabled)); } }
public bool Update(int id, LicenserInfoModel model) { try { using (var db = new LicenseDbEntities()) { var dbModel = db.LicenseOwners.FirstOrDefault(x => x.Id == id); if (dbModel != null) { var result = DbHelper.CreateDbModel(model, dbModel); db.SaveChanges(); return(true); } return(false); } } catch (Exception ex) { var error = ((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors; _logger.Log(LogLevel.Error, ex); throw; } }
public bool UseIpFiltering() { using (var db = new LicenseDbEntities()) { var row = db.Settings.FirstOrDefault(); return(row != null ? row.UseIPFilter : false); } }
public List <Common.Models.LicenserInfoModel> GetAll() { using (var db = new LicenseDbEntities()) { return(db.LicenseOwners .Select(DbHelper.FromDbModel) .ToList()); } }
public bool AddServer(AddServerRequest request) { try { bool result = false; using (var db = new LicenseDbEntities()) { var owner = db.LicenseOwners.FirstOrDefault(x => x.RegNom == request.RegNom); if (owner != null) { foreach (var x in request.Servers) { var server = db.LicenseOwnerServers .FirstOrDefault(v => v.ServerInstance == x.ServerInstance && v.LicenseOwnerID == owner.Id && v.SendFromPC == request.ComputerName && v.SystemUserName == request.SystemUserName); if (server == null) { db.LicenseOwnerServers.Add(new LicenseOwnerServer() { LicenseOwnerID = owner.Id, ServerInstance = x.ServerInstance, ServerIPAddress = x.ServerIPAddress, SendFromPC = request.ComputerName, SendFromPCIPAddress = request.ComputerIP, CreateDate = request.RequestDate, SystemUserName = request.SystemUserName }); } else { server.ServerIPAddress = x.ServerIPAddress; server.SendFromPC = request.ComputerName; server.SendFromPCIPAddress = request.ComputerIP; server.CreateDate = request.RequestDate; server.SystemUserName = request.SystemUserName; } } db.SaveChanges(); return(true); } } return(result); } catch (Exception ex) { var error = ((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors; _logger.Log(LogLevel.Error, ex); throw; } }
public List <IpAddressElement> GetAll() { using (var db = new LicenseDbEntities()) { return(db.IpFilters.Select(x => new IpAddressElement() { Id = x.Id, Address = x.Address.Trim(), Denied = x.Denied }).ToList()); } }
public List <LicenseVariableModel> GetLookupVariables() { using (var db = new LicenseDbEntities()) { return(db.lu_LicenseVariables .Select(x => new LicenseVariableModel() { Id = x.Id, Name = x.Name }).ToList <LicenseVariableModel>()); } }
public IpAddressElement Get(int id) { using (var db = new LicenseDbEntities()) { return(db.IpFilters .Where(x => x.Id == id) .Select(x => new IpAddressElement() { Id = x.Id, Address = x.Address.Trim(), Denied = x.Denied }).FirstOrDefault()); } }
public bool Delete(int id) { using (var db = new LicenseDbEntities()) { var result = db.IpFilters.FirstOrDefault(x => x.Id == id); if (result != null) { db.IpFilters.Remove(result); } db.SaveChanges(); } return(true); }
public void UpdateVariables(string licenseId, Dictionary <string, object> values) { using (var db = new LicenseDbEntities()) { var licenseGuid = Guid.Parse(licenseId); foreach (var v in values) { var variable = db.LicenseVariables.FirstOrDefault(x => x.lu_LicenseVariables.Name == v.Key); if (variable != null) { variable.Value = v.Value != null?v.Value.ToString() : string.Empty; } } db.SaveChanges(); } }
public List <LicenseVariableModel> GetVariables(string licenseId = null) { using (var db = new LicenseDbEntities()) { var id = Guid.Parse(licenseId); return(db.LicenseVariables .Where(x => licenseId == null || x.LicenseId == id) .Select(x => new LicenseVariableModel() { Id = x.Id, LicenseId = x.LicenseId, Name = x.lu_LicenseVariables.Name, Value = x.Value }).ToList <LicenseVariableModel>()); } }
public bool Delete(string id) { using (var db = new LicenseDbEntities()) { var result = db.Licenses.FirstOrDefault(x => x.Id == new Guid(id)); if (result != null) { result.Enabled = false; db.SaveChanges(); return(true); } } return(false); }
public bool UpdateLookupVariable(VariableModel model) { using (var db = new LicenseDbEntities()) { var variable = db.lu_LicenseVariables.FirstOrDefault(x => x.Id == model.Id); if (variable == null) { return(false); } variable.Name = model.Name; variable.Type = model.Type; db.SaveChanges(); } return(true); }
public void DeleteVariables(string licenseId, List <string> variables) { using (var db = new LicenseDbEntities()) { var licenseGuid = Guid.Parse(licenseId); foreach (var v in variables) { var variable = db.LicenseVariables.FirstOrDefault(x => x.lu_LicenseVariables.Name == v); if (variable != null) { db.LicenseVariables.Remove(variable); } } db.SaveChanges(); } }
public VariableModel GetLookupVariable(int id) { using (var db = new LicenseDbEntities()) { var variable = db.lu_LicenseVariables.FirstOrDefault(x => x.Id == id); if (variable != null) { return(new VariableModel() { Id = variable.Id, Name = variable.Name, Type = variable.Type }); } } return(null); }
public List <LicenseActivationModel> LicenseActivations(string id) { using (var db = new LicenseDbEntities()) { var guid = Guid.Parse(id); var result = db.Licenses.FirstOrDefault(x => x.Id == guid); if (result != null) { return(result.LicenseActivations.Select(x => new LicenseActivationModel() { ComptuterId = x.ComputerId, UserId = x.UserId, PCName = x.ComputerName }).ToList()); } } return(null); }
private void LogLicenseChange(LicenseDbEntities db, bool isDemo, string oldObject, string newObject, Guid id, long?userId) { db.LicensesLogs.Add(new LicensesLog() { LicenseId = id, Date = DateTime.Now, IsDemo = isDemo, Old = oldObject, New = newObject, ChangedBy = userId ?? 0 }); db.SaveChanges(); }
public bool Add(IpAddressElement ipAddressElement) { using (var db = new LicenseDbEntities()) { if (db.IpFilters.Any(x => x.Address == ipAddressElement.Address)) { return(false); } db.IpFilters.Add(new IpFilter() { Address = ipAddressElement.Address.Trim(), Denied = ipAddressElement.Denied }); db.SaveChanges(); } return(true); }
public bool CreateLookupVariable(string name, string type = null) { using (var db = new LicenseDbEntities()) { var variable = db.lu_LicenseVariables.FirstOrDefault(x => x.Name == name); if (variable != null) { return(false); } var result = new lu_LicenseVariables() { Name = name, Type = type }; db.lu_LicenseVariables.Add(result); db.SaveChanges(); } return(true); }
public void SetUseIpFiltering(bool useRestriction) { using (var db = new LicenseDbEntities()) { var result = db.Settings.FirstOrDefault(); if (result != null) { result.UseIPFilter = useRestriction; } else { db.Settings.Add(new Setting() { UseIPFilter = useRestriction }); } db.SaveChanges(); } }
public bool Edit(int id, IpAddressElement ipAddressElement) { using (var db = new LicenseDbEntities()) { if (db.IpFilters.Any(x => x.Address == ipAddressElement.Address && x.Id != id)) { return(false); } var result = db.IpFilters.FirstOrDefault(x => x.Id == id); if (result != null) { result.Address = ipAddressElement.Address.Trim(); result.Denied = ipAddressElement.Denied; db.SaveChanges(); } } return(true); }
protected override void Initiliaze() { using (var db = new LicenseDbEntities()) { var row = db.Settings.FirstOrDefault(); _useIpFiltering = row != null ? row.UseIPFilter : false; if (_useIpFiltering) { lock (_lock) { _ipAddress = db.IpFilters.Select(x => new IpAddressElement() { Id = x.Id, Address = x.Address.Trim(), Denied = x.Denied }).ToList(); } } } }
public LicenseModel Get(string id) { using (var db = new LicenseDbEntities()) { var guid = Guid.Parse(id); var result = db.Licenses.FirstOrDefault(x => x.Id == guid); if (result != null) { var activator = result.LicenseActivations.Any() ? result.LicenseActivations.FirstOrDefault() : null; return(new LicenseModel() { Id = result.Id, IsDemo = result.IsDemo, ValidTo = result.ValidTo, Type = (LicenseTypeEnum)result.Type, Enabled = result.Enabled ?? false, SubscribedTo = result.SubscribedTo, Created = result.CreatedDate, WorkstationsCount = result.WorkstationsCount, User = DbHelper.FromDbModel(result.LicenseOwner), LicenseModules = result.LicenseModules .Select(x => (LicenseModulesEnum)x.ModuleId).ToList(), Modules = result.LicenseModules .Select(x => new LicenseModuleModel() { Id = x.Id, Code = x.lu_LicenseModules.Code, ValidTo = x.ValidTo, Type = (LicenseModulesEnum)x.lu_LicenseModules.Id }).ToList(), IsActivated = activator != null }); } } return(null); }
protected override void Initiliaze() { lock (_lock) { using (var db = new LicenseDbEntities()) { _requestLogs = db.ApiLogs.Select(x => new ApiLogEntry() { Id = x.Id, RequestContentBody = x.RequestBody, RequestIpAddress = x.RequestIpAddress, RequestMethod = x.RequestMethod, RequestTimestamp = x.RequestTimestamp, RequestUri = x.RequestUri, ResponseContentBody = x.ResponseContentBody, ResponseStatusCode = x.ResponseStatusCode, ResponseTimestamp = x.ResponseTimestamp, AbsoluteUri = x.AbsoluteUri }).ToList(); } } }
public bool Create(LicenserInfoModel model) { try { using (var db = new LicenseDbEntities()) { var result = DbHelper.CreateDbModel(model); db.LicenseOwners.Add(result); db.SaveChanges(); return(true); } } catch (Exception ex) { var error = ((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors; _logger.Log(LogLevel.Error, ex); throw; } }
public List <LicenseModel> GetByFilter(LicenseFilterModel filter) { using (var db = new LicenseDbEntities()) { var result = db.Licenses.Where(x => x.LicenseOwner.IsCompany == true && x.LicenseOwner.CompanyId == filter.CompanyId) .ToList(); return(result .Select(x => new LicenseModel() { Id = x.Id, IsDemo = x.IsDemo, ValidTo = x.ValidTo, Created = x.CreatedDate, WorkstationsCount = x.WorkstationsCount, Type = (LicenseTypeEnum)x.Type, User = new Common.Models.LicenserInfoModel() { Name = x.LicenseOwner.Name, IsCompany = x.LicenseOwner.IsCompany, Email = x.LicenseOwner.Email, Phone = x.LicenseOwner.Phone, ContactPerson = x.LicenseOwner.ContactPerson, CompanyId = x.LicenseOwner.CompanyId }, LicenseModules = x.LicenseModules.Select(m => (LicenseModulesEnum)m.ModuleId).ToList(), Modules = x.LicenseModules .Select(m => new LicenseModuleModel() { Id = m.Id, Code = m.lu_LicenseModules.Code, ValidTo = m.ValidTo }).ToList(), }) .ToList()); } }
public void CreateVariables(string licenseId, Dictionary <string, object> values) { using (var db = new LicenseDbEntities()) { var licenseGuid = Guid.Parse(licenseId); foreach (var v in values) { var variable = db.lu_LicenseVariables.FirstOrDefault(x => x.Name == v.Key); if (variable != null) { int intValue; if (variable.Type == ((int)VariableTypeEnum.Integer).ToString() && v.Value != null && !int.TryParse(v.Value.ToString(), out intValue)) { continue; } var licenseVariable = db.LicenseVariables.FirstOrDefault(x => x.lu_LicenseVariables.Id == variable.Id && x.LicenseId == licenseGuid); if (licenseVariable != null) { licenseVariable.Value = v.Value != null?v.Value.ToString() : string.Empty; } else { db.LicenseVariables.Add(new LicenseVariable() { LicenseId = licenseGuid, VariableId = variable.Id, Value = v.Value != null ? v.Value.ToString() : string.Empty }); } } } db.SaveChanges(); } }
public List <LicenseModel> GetAll() { using (var db = new LicenseDbEntities()) { var result = db.Licenses .ToList(); return(result .Select(x => new LicenseModel() { Id = x.Id, IsDemo = x.IsDemo, Enabled = x.Enabled ?? false, IsActivated = x.LicenseActivations.Any(), ValidTo = x.ValidTo, Created = x.CreatedDate, SubscribedTo = x.SubscribedTo, Type = (LicenseTypeEnum)(x.Type ?? 1), User = DbHelper.FromDbModel(x.LicenseOwner), LicenseModules = x.LicenseModules.Select(m => (LicenseModulesEnum)m.ModuleId).ToList() }) .ToList()); } }