private Func <object> manyToManyValue(object entity, string propertyName) { return(() => { // In this case the key id represents an object being added to or removed from a set. // We use reflection to get the current contents of the set (so after the change we are logging). if (entity == null) { throw new InvalidOperationException("Attempted to log change to null object of type " + entity.GetType().Name); } var property = entity.GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property == null) { throw new InvalidOperationException(string.Format("Unable to find a property with name '{0}' on type '{1}'", propertyName, entity.GetType())); } var value = property.GetValue(entity, null); if (value == null) { throw new InvalidOperationException(string.Format("Many-to-many set '{0}.{1}' was null", entity.GetType().Name, property.Name)); } IEnumerable <string> current = ((IEnumerable <object>)value) .Select(e => DataContextHelper.GetReferenceForObject(context, e)) .Distinct() .OrderBy(reference => reference); return toIdList(current); }); }
public List <OrderDetail> GetOrderItems(int id) { var dataContext = DataContextHelper.GetDataContext(); var Query = PetaPoco.Sql.Builder.Select("*").From("OrderDetail").Where("OrderID=" + id); return(dataContext.Fetch <OrderDetail>(Query).ToList()); }
public GetPermissionByRoleOut GetPermissionByRole(GetPermissionByRoleIn input) { GetPermissionByRoleOut output = new GetPermissionByRoleOut() { result = Entities.Common.Result.Error }; using (var dataContext = DataContextHelper.GetDataContext <PermissionDataContext>()) { var linqResult = dataContext.spr_getPermissionByRole(input.role); output.listPermissions = new List <MethodParameters.Permission.GetPermissionByRoleOut.PermissionByRole>(); foreach (var item in linqResult) { var permission = new MethodParameters.Permission.GetPermissionByRoleOut.PermissionByRole() { pm_code = item.pm_code, pm_name = item.pm_name, rl_code = item.rl_code, rl_name = item.rl_name, rpID = item.rpID }; output.listPermissions.Add(permission); } output.result = Entities.Common.Result.Success; } return(output); }
public List <object> GetFullList(string table) { var dataContext = DataContextHelper.GetDataContext(); var Query = PetaPoco.Sql.Builder.Select("*").From(table); return(dataContext.Fetch <object>(Query).ToList()); }
public Customer GetCustomer(int id) { var dataContext = DataContextHelper.GetDataContext(); var Query = PetaPoco.Sql.Builder.Select("*").From("Customer").Where("CustomerID =" + id); return(dataContext.Fetch <Customer>(Query).FirstOrDefault()); }
public void UpdateUser(User user) { using (var context = DataContextHelper.GetCPDataContext()) { context.Update(user); } }
public Item GetItem(int ID) { var dataContext = DataContextHelper.GetDataContext(); var Query = PetaPoco.Sql.Builder.Select("*").From("Item").Where("ItemID=" + ID); return(dataContext.Fetch <Item>(Query).FirstOrDefault()); }
/* private void EditTarget(object parameter) { * var target = parameter as Target; * TargetId = target.TargetId; * * this.TargetAction = TargetAction.Update; * * ShowTargetControl = true; * } */ private async void DeleteTarget(object parameter) { var target = parameter as Target; await DataContextHelper.DeleteTarget <Target>(target);//Removes record FireOnDeleteFinished(); }
public NvaSd2Controller(INvaSd _dbcontext, IHttpErrorBuilder _errorBuilder, DataContextHelper _contextHelper, EntytyMetadatasHelper _mdHelper) { context = _dbcontext; errorBuilder = _errorBuilder; contextHelper = _contextHelper; mdHelper = _mdHelper; }
public void NewUserRoleOrganization(UserRole userRole) { using (var context = DataContextHelper.GetCPDataContext()) { context.Insert(userRole); } }
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) { if (item == null) { return(TextBlockTemplate); } DataContextHelper dataContextHelper = item as DataContextHelper; OrderInfo orderInfo = dataContextHelper.Record as OrderInfo; if (orderInfo == null) { return(TextBlockTemplate); } switch (orderInfo.ProductName) { case "TextColumn": return(TextBoxTemplate); case "DoubleTextBoxColumn": return(DoubleTemplate); case "GridUpDownColumn": return(UpdownTemplate); default: return(TextBlockTemplate); } }
public void NewRoleOrganization(Role role) { using (var context = DataContextHelper.GetCPDataContext()) { context.Insert(role); } }
public List <user> getUsers() { using (var context = DataContextHelper.GetCPDataContext()) { var sql = PetaPoco.Sql.Builder.Select("*").From("users"); return(context.Fetch <user>(sql).ToList()); } }
public user getUser(int userID) { using (var context = DataContextHelper.GetCPDataContext()) { var sql = PetaPoco.Sql.Builder.Select("*").From("users").Where("ID = @0", userID); return(context.Fetch <user>(sql).FirstOrDefault()); } }
public void AddUser(User user) { using (var context = DataContextHelper.GetCPDataContext()) { context.Insert(user); } }
public List <Dictionary <string, object> > GetTableListingData(string tableName, string columns, string joiningTables, string whereCondition) { using (var context = DataContextHelper.GetCPDataContext()) { var sql = PetaPoco.Sql.Builder.Select(columns).From(tableName).Append(joiningTables); if (!string.IsNullOrEmpty(whereCondition)) { sql = sql.Where(whereCondition); } var list = context.Fetch <dynamic>(sql); List <Dictionary <string, object> > finalList = new List <Dictionary <string, object> >(); foreach (var row in list) { Dictionary <string, object> dic = new Dictionary <string, object>(); foreach (var t in row) { dic.Add(t.Key, t.Value); } finalList.Add(dic); } return(finalList); } }
public void DeleteUser(int userID) { using (var context = DataContextHelper.GetCPDataContext()) { context.Execute("Delete From Users where UserID=@0", userID); } }
public Dictionary <string, object> GetTableSingleRecord(string tableName, List <string> fieldNames, Dictionary <string, object> searchFields) { using (var context = DataContextHelper.GetCPDataContext()) { // var tbPoco = Activator.CreateInstance("Framework.Shared", string.Format("Framework.Shared.DataServices.{0}", tableName.Singlofy())); var query = PetaPoco.Sql.Builder.Select(string.Join(",", fieldNames)); query.From(tableName); foreach (var sf in searchFields) { query.Where(sf.Key + " = @0", sf.Value); } //Tuple.Create(tbPoco.Unwrap()) var row = context.Fetch <dynamic>(query).FirstOrDefault(); Dictionary <string, object> record = new Dictionary <string, object>(); if (row == null) { return(null); } foreach (var t in row) { record.Add(t.Key, t.Value); } return(record); } }
public HomeController(IHostingEnvironment _env) { this._context = new DataContextHelper(); env = _env; this.objNumberToWord = new NumberToWord(); _externalKey = AppConfiguration.GetConfiguration("ExternalKey"); }
public DynamicPage GetTablePage(string tableName) { using (var context = DataContextHelper.GetCPDataContext()) { DynamicPage page = new DynamicPage(); page.TableName = tableName; page.PageTitle = tableName.Wordify(); page.Fields = context.Fetch <DynamicField>("Select * From EntityDetails Where EntityID = (Select EntityID From Entities Where NameEn = @0)", tableName).ToList(); if (page.Fields != null && page.Fields.Count != 0) { page.EntityID = page.Fields.FirstOrDefault().EntityID; } else { var query = PetaPoco.Sql.Builder.Select("c.name As Name, ~c.is_nullable As IsRequired,(c.max_length/(IsNull((Select 2 Where c.system_type_id = 231),1))) As MaxLength, c.system_type_id As DbTypeID,c.is_identity As IsAutoID,IsNull((select top 1 1 from sys.foreign_key_columns f where f.parent_column_id = c.column_id AND f.parent_object_id = c.object_id), 0) As IsForeignkey,(select name from sys.objects Where object_id = (select top 1 f.referenced_object_id from sys.foreign_key_columns f where f.parent_column_id = c.column_id AND f.parent_object_id = c.object_id)) RefrencedTableName,(select 1 from sys.indexes i inner join sys.index_columns ic on i.object_id = ic.object_id and i.index_id = ic.index_id Where i.object_id = c.object_id and i.is_primary_key = 1 and ic.column_id = c.column_id) As IsPrimaryKey"); query.From("sys.columns c") .InnerJoin("sysobjects o").On("c.object_id = o.id") .Where("o.name = @0", tableName); page.Fields = context.Fetch <DynamicField>(query).ToList(); } //if (tableName.ToLower() == "companyshares") //{ // DynamicField dynFld = page.Fields.Where(f => f.Name == "CreatedOn").FirstOrDefault(); // if (dynFld != null) // { // dynFld.MaxLength = 10; // } //} return(page); } }
public object GetSingleObject(int ID, string table, string idName) { var dataContext = DataContextHelper.GetDataContext(); var Query = PetaPoco.Sql.Builder.Select("*").From(table).Where(idName + "=" + ID); return(dataContext.Fetch <object>(Query).FirstOrDefault()); }
public DynamicEntity GetEntity(int entityID) { using (var context = DataContextHelper.GetCPDataContext()) { return(context.Fetch <DynamicEntity>("Select * From Entities Where EntityID = @0", entityID).FirstOrDefault()); } }
public List <Item> GetAllItems() { var dataContext = DataContextHelper.GetDataContext(); var Query = PetaPoco.Sql.Builder.Select("*").From("Item"); return(dataContext.Fetch <Item>(Query).ToList()); }
//deletes goal private async void DeleteGoalAsync(object parameter) { var goal = parameter as Goal; await DataContextHelper.DeleteItem <Goal>(goal); FireOnDeleteFinished(); }
public List <Order> GetAllOrders() { var dataContext = DataContextHelper.GetDataContext(); var Query = PetaPoco.Sql.Builder.Select("*").From("Orders"); return(dataContext.Fetch <Order>(Query).ToList()); }
private static bool IsAnySourcelessBindings(SceneNode sceneNode) { if (sceneNode == null) { return(false); } DocumentCompositeNode documentCompositeNode = sceneNode.DocumentNode as DocumentCompositeNode; if (documentCompositeNode == null) { return(false); } IProperty dataContextProperty = DataContextHelper.GetDataContextProperty(documentCompositeNode.Type); foreach (IProperty property in (IEnumerable <IProperty>)documentCompositeNode.Properties.Keys) { if (property.MemberType != MemberType.DesignTimeProperty && property != dataContextProperty) { BindingSceneNode binding = sceneNode.GetBinding((IPropertyId)property); if (binding != null && !DataContextHelper.GetDataSourceInfoFromBinding((DocumentCompositeNode)binding.DocumentNode).HasSource) { return(true); } } } return(false); }
public GetPermissionByCodeOut GetPermissionByCode(GetPermissionByCodeIn input) { GetPermissionByCodeOut output = new GetPermissionByCodeOut() { result = Entities.Common.Result.Error }; using (var dataContext = DataContextHelper.GetDataContext <PermissionDataContext>()) { var linqResult = dataContext.spr_getPermissionByCode(input.pm_code).FirstOrDefault(); output.permission = new Entities.Database.Permission(); var permission = new Entities.Database.Permission() { pmID = linqResult.pmID, pm_code = linqResult.pm_code, pm_name = linqResult.pm_name, pm_description = linqResult.pm_description, pm_creationUser = linqResult.pm_creationUser, pm_creationDate = linqResult.pm_creationDate, pm_modificationUser = linqResult.pm_modificationUser, pm_modificationDate = linqResult.pm_modificationDate, pm_status = linqResult.pm_status }; output.permission = permission; output.result = Entities.Common.Result.Success; } return(output); }
private static SceneNode FindHighestDataContextLocationWithoutSourcelessBindings(SceneNode upperBound, SceneNode lowerBound) { SceneNode sceneNode1 = (SceneNode)null; SceneNode childToSkip = lowerBound; for (SceneNode sceneNode2 = lowerBound; sceneNode2 != upperBound; sceneNode2 = sceneNode2.Parent) { if (sceneNode2 == null) { return((SceneNode)null); } if (DataContextPlacementEvaluator.IsNodeWithoutSourcelessBindings(sceneNode2, sceneNode2 != lowerBound, childToSkip)) { if (DataContextHelper.GetDataContextProperty(sceneNode2.Type) != null) { sceneNode1 = sceneNode2; childToSkip = sceneNode2; } if (sceneNode2.DocumentNode.NameScope != null) { break; } } else { break; } } return(sceneNode1); }
internal static IPropertyId RefineDataContextProperty(SceneNode target, IPropertyId targetProperty, DocumentNode dataNode) { if (targetProperty.MemberType == MemberType.DesignTimeProperty || !DataContextHelper.IsDataContextProperty(target.DocumentNode, targetProperty)) { return(targetProperty); } SampleNonBasicType sampleNonBasicType = dataNode.Type as SampleNonBasicType; if (sampleNonBasicType != null) { if (!sampleNonBasicType.DeclaringDataSet.IsEnabledAtRuntime) { return(DesignTimeProperties.DesignDataContextProperty); } if (((DocumentCompositeNode)target.DocumentNode).Properties[targetProperty] != null) { DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(target, targetProperty, true); if (dataContextInfo.DataSource != null && !(dataContextInfo.DataSource.DataSourceType is SampleNonBasicType)) { return(DesignTimeProperties.DesignDataContextProperty); } } return(targetProperty); } if (PlatformTypes.IsExpressionInteractiveType(dataNode.Type.RuntimeType)) { return(DesignTimeProperties.DesignDataContextProperty); } return(targetProperty); }
private void logForeignKeyChange(ObjectStateEntry entry, AssociationEndMember localEnd, AssociationEndMember foreignEnd) { // These "keys" represent in-memory unique references // to the objects at the ends of these associations. // In the case of new objects, these won't contain the primary key that has just // been generated, but we can still use it below to get to the real object in-memory // and pull the id out of that. var key = getEndEntityKey(entry, localEnd); // Get the object identified by the local key object entity = context.GetObjectByKey(key); if (!filter.ShouldLog(entity.GetType())) { return; } // The property on the "local" object that navigates to the "foreign" object var property = getProperty(entry, localEnd, foreignEnd, key); // We can control which directions of relationships we are interested in logging // by which navigation properties we keep in the model if (property == null || !filter.ShouldLog(property)) { return; } // Generate the change var value = getForeignValue(entry, entity, foreignEnd, property.Name); recorder.Record(entity, () => DataContextHelper.GetReferenceForObject(context, entity), property.Name, value); }