public IQueryable <SiteObjectRelation> GetByRelation(string relationObjectType, object relationObjectId, Type objectType) { return(GetAll().Where(sor => sor.RelationObject_ID .Equals(relationObjectId) && sor.RelationObjectType == relationObjectType && sor.ObjectType == LinqToSqlUtils.GetTableName(objectType))); }
public IQueryable <SiteObjectRelation> GetByRelation(Type relationType, object relationObjectId, Type objectType) { var relationObjectType = LinqToSqlUtils.GetTableName(relationType); return(GetByRelation(relationObjectType, relationObjectId, objectType)); }
public static string SiteObjectLink(this HtmlHelper helper, SiteObject siteObject) { if (siteObject == null) { return(null); } var entityType = (new ContextProvider()).GetTypeByTableName(siteObject.Type); var linkName = siteObject.Name; /* if(siteObject.Type == LinqToSqlUtils.GetTableName(typeof(Block))) * { * var context = new SpecialistWebDataContext(); * var block = context.Blocks.FirstOrDefault( * b => b.BlockID == (int) siteObject.ID); * return helper.BlockLink(block); * * }*/ if (siteObject.Type == LinqToSqlUtils.GetTableName(typeof(Employee)) && siteObject.Entity != null) { return(HtmlControls.Anchor(Const.Common.SiteDomain + helper.GetUrlFor(siteObject.Entity), siteObject.ObjectType.Name + ":" + siteObject.Entity.As <Employee>().FullName).ToString()); } if (linkName.IsEmpty()) { linkName = siteObject.Type; } return(helper.ActionLink(siteObject.ObjectType.Name + ":" + linkName, "Edit", entityType.Name + Const.Common.ControlPosfix, new { id = siteObject.ID }, null).ToString()); }
public void DeleteAndSubmit(T obj) { var id = LinqToSqlUtils.GetPK(obj); var oldObj = GetByPK(id); _source.Remove(oldObj); }
public virtual IQueryable GetComboBoxSource( PropertyMetaData propertyMetaData, bool onlyActive, string filter) { var relatedMeta = MetaDataProvider.Get( propertyMetaData.ForeignType()); var idProperty = LinqToSqlUtils.GetPKPropertyName(relatedMeta.EntityType); var selector = "new(" + idProperty + " as " + propertyMetaData.Info.Name + ", " + relatedMeta.DisplayProperty().Name + ")"; var result = DynamicRepository.GetAll(propertyMetaData.ForeignType()); if (filter != null) { result = result.Where(filter); } /* if(onlyActive) * foreach (var property in Const.Common.ActiveProperties) * { * if(propertyMetaData.ForeignType.HasProperty(property)) * result = result.Where(property); * }*/ return(result.Select(selector)); }
public ActionResult ReverseRelationSorting(string className, string RelationObject_ID, string RelationObjectType) { var type = SiteObjectType.GetAll().First(x => x.ClassName == className); var model = new ReverseRelationSortingVM(); model.ObjectType = type.SysName; model.ClassName = className; if (RelationObject_ID == null) { return(View(model)); } var objId = LinqToSqlUtils.CorrectPKType(RelationObject_ID, ContextProvider.GetTypeByTableName( RelationObjectType)); var relationObjectType = ContextProvider.GetTypeByTableName( RelationObjectType); var relationObjectID = LinqToSqlUtils.CorrectPKType(RelationObject_ID, relationObjectType); model.SiteObject = SORepository.GetAll().First(so => so.ID.Equals(relationObjectID) && so.Type == RelationObjectType); model.Relations = GetCourseRelations(type.Type, RelationObjectType, (int)objId); return(View(model)); }
public List <Course> GetAllFor(object obj) { IQueryable <Course> result = null; obj.Match <Course>(x => result = GetAllForTrack(x.Course_TC, true) .AsQueryable()); obj.Match <Exam>(x => result = GetAllForExam(x.Exam_ID)); obj.Match <TrackListVM>(x => result = GetCoursesForTrackList(x).AsQueryable()); if (result == null) { var siteObjectRelations = SiteObjectRelationService .GetByRelation(LinqToSqlUtils.GetTableName(obj), LinqToSqlUtils.GetPK(obj), typeof(Course)); var courses = siteObjectRelations .Select(r => new { r.Object_ID, r.RelationOrder }).ToList() .Distinct(x => x.Object_ID.ToString()) .ToDictionary(x => x.Object_ID.ToString(), x => x.RelationOrder); return(AllCoursesForList() .Where(c => courses.ContainsKey(c.Course_TC)) // .OrderBy(c => courses.GetValueOrDefault(c.Course_TC)).ToList(); .OrderByDescending(x => x.IsTrackBool) .ThenByDescending(x => x.IsDiplom) .ThenByDescending(x => x.IsHit) .ThenBy(c => courses.GetValueOrDefault(c.Course_TC)).ToList()); } return(result.ToList()); }
private static List <SelectListItem> GetSelectedListItems( PropertyMetaData property, System.Collections.IEnumerable source) { var result = new List <SelectListItem>(); var relatedPropertyType = property.ForeignType(); var foreignMetaData = MetaDataProvider.Get(relatedPropertyType); var first = true; PropertyInfo propertyInfo = null; foreach (var o in source) { object id; if (first) { propertyInfo = o.GetType().GetProperty(property.Info.Name); first = false; } if (propertyInfo != null) { id = o.GetValue(property.Info.Name); } else { id = o.GetValue(LinqToSqlUtils.GetPKPropertyName( foreignMetaData.EntityType)); } result.Add(new SelectListItem { Text = GetDisplay(o, foreignMetaData).ToString(), Value = id.ToString() }); } return(result.OrderBy(sli => sli.Text).ToList()); }
public override RouteValueDictionary GetRouteValues(object entity) { return(new RouteValueDictionary { { "pageIndex", 1 }, { ForeignProperty, LinqToSqlUtils.GetPK(entity) } }); }
public virtual ActionResult Edit(object id, int?tabFocus) { id = Server.UrlDecode(id.ToString()); id = Convert.ChangeType(id, LinqToSqlUtils.GetPKPropertyInfo( MetaData.EntityType).PropertyType); var obj = Repository.GetByPK(id); if (obj == null) { return(Content("ќбъект не найден")); } var editVM = new EditVM(obj, MetaData); AddExtraControls(editVM, false); /* if(tabFocus.HasValue) * { * for (int i = 0; i < editVM.MetaData.ExtraControls.Count; i++) * { * var control = editVM.MetaData.ExtraControls[i]; * if (control.DisplayName.GetHashCode() == tabFocus) * editVM.TabFocus = i + 1; * } * }*/ editVM.SiteUrl = Html.GetUrlFor(obj); SetSiteObject(id, editVM); return(View("Edit", editVM)); }
public virtual ActionResult CheckBoxList(string propertyName, object id) { id = CorrectIdType(id); var propertyNameWithoutPrefix = RemovePrefix(propertyName); var propertyMetaData = MetaData.GetProperties() .First(p => p.Name == propertyNameWithoutPrefix); var model = new ComboBoxVM(); model.PropertyName = propertyName; var entity = Repository.GetByPK(id); var m2MEntities = entity.GetValue(propertyNameWithoutPrefix) as IEnumerable; var values = new List <object>(); var otherM2MType = LinqToSqlUtils.GetOtherM2MEntityType(propertyMetaData.Info); var otherM2MPropertyInfo = LinqToSqlUtils.GetOtherM2MPropertyInfo( propertyMetaData.Info); foreach (var m2MEntity in m2MEntities) { values.Add(otherM2MPropertyInfo.GetValue(m2MEntity)); } var source = ComboBoxSourceCreator.GetSource(otherM2MType); model.Source = SelectListUtil.GetSelectedListItems(propertyMetaData, source, values); return(PartialView(Const.Common.FolderControls + Controls.CheckBoxList, model)); }
public virtual ActionResult ListControl(int pageIndex, OrderColumn orderColumn) { var currentFilterValues = GetCurrentFilterValues(); var items = AddFilterToList(currentFilterValues); if (!orderColumn.ColumnName.IsEmpty()) { var orderQuery = orderColumn.ColumnName; if (orderColumn.IsDesc) { orderQuery += " " + Const.Common.Descending; } items = items.OrderBy(orderQuery); } var tableData = new List <ListVM.Row>(); var pagedList = items.ToPagedList(pageIndex - 1); foreach (var item in pagedList) { var id = LinqToSqlUtils.GetPK(item); var list = GetValuesForRow(item); tableData.Add(new ListVM.Row { Id = id, Entity = item, Values = list }); } var listVM = new ListVM(MetaData, pagedList, tableData); AddExtraControls(listVM, true); listVM.FilterValues = currentFilterValues; listVM.OrderColumn = orderColumn; return(View(PartialViewNames.ListControl, listVM)); }
public ActionResult GuideFor(object obj) { var model = new List <Guide>(); var track = obj.As <Course>(); var ids = new List <object>(); if (track != null && track.IsTrackBool) { var courseTCs = CourseService.GetActiveTrackCourses() .GetValueOrDefault(track.Course_TC) ?? new List <string>(); ids = courseTCs.Cast <object>().ToList(); } else { ids = _.List(LinqToSqlUtils.GetPK(obj)); } if (ids.Any()) { var guideIds = SiteObjectRelationService .GetRelation(typeof(Guide), Enumerable.Empty <object>(), obj.GetType()).Where(x => ids.Contains(x.RelationObject_ID)) .OrderBy(x => x.RelationOrder) .Select(x => x.Object_ID).ToList().Cast <int>().ToList(); model = GuideService.GetAll(x => guideIds.Contains(x.GuideID) && x.IsActive).Distinct().ToList() .OrderBy(x => guideIds.IndexOf(x.GuideID)).ToList(); } return(View(PartialViewNames.GuidesBlock, model.ToList())); }
/* [InjectionMethod] * public virtual void SetInvoker(IUnityContainer container) * { * ActionInvoker = new CustomControllerActionInvoker(container); * } */ protected void AddExtraControls(IExtraControls model, bool tabFocus) { foreach (var metaData in MetaDataProviderUtils.GetWhereForeign(MetaDataProvider, MetaData.EntityType)) { /*if(metaData.IsReadOnly()) * continue;*/ if (tabFocus) { model.ExtraControls.Add(new TabFocusControl( "[" + metaData.DisplayName() + "]", MetaData.EntityType.Name + Const.Common.ControlPosfix)); } else { var foreignProperty = metaData.GetProperties() .Where(p => p.ForeignType() != null && p.ForeignType() == MetaData.EntityType).First(); model.ExtraControls.Add(new FilterLinkControl( "[" + metaData.DisplayName() + "]", metaData.EntityType.Name + Const.Common.ControlPosfix, foreignProperty.Info.Name)); } } var siteObjectType = LinqToSqlUtils.GetTableName(MetaData.EntityType); if (SiteObjectTypeRepository.GetByPK(siteObjectType) != null) { model.ExtraControls.Add(new RelationsLinkControl()); } }
public override RouteValueDictionary GetRouteValues(object entity) { return(new RouteValueDictionary { { "id", LinqToSqlUtils.GetPK(entity) }, { "tabFocus", DisplayName.GetHashCode() } }); }
private IEnumerable <Course> GetCourses(string RelationObject_ID, string RelationObjectType) { IQueryable <Course> courseQuery = null; if (RelationObjectType == null) { courseQuery = new List <Course>().AsQueryable();//Repository.GetAll(); } else { var relationObjectType = ContextProvider.GetTypeByTableName( RelationObjectType); /* if (obj.RelationObject_ID is string[]) * obj.RelationObject_ID = (obj.RelationObject_ID as string[]).First();*/ var relationObjectID = LinqToSqlUtils.CorrectPKType(RelationObject_ID, relationObjectType); courseQuery = SiteObjectService .GetByRelationObject <Course>(relationObjectType, relationObjectID); ViewData["SiteObject"] = SORepository.GetAll().First(so => so.ID.Equals(relationObjectID) && so.Type == RelationObjectType); } return(courseQuery.Where(c => c.IsActive) .OrderBy(c => c.WebSortOrder) .Select(c => new { c.Course_TC, c.Name }) .ToList() .Select(c => new Course { Course_TC = c.Course_TC, Name = c.Name })); }
public ActionResult MainEntityList(string type, object id, List <string> entities) { if (entities != null) { var objectType = ContextProvider.GetTypeByTableName(type); var objectId = LinqToSqlUtils.CorrectPKType(id, objectType); var oldRelations = SiteObjectRelationRepository .GetAll(x => x.Object_ID == objectId && x.ObjectType == type).ToList(); foreach (var entity in entities) { var parts = entity.Split(';'); var tableName = parts[0]; var entityType = ContextProvider.GetTypeByTableName(tableName); var entityId = LinqToSqlUtils.CorrectPKType(parts[1], entityType); var relation = new SiteObjectRelation { Object_ID = objectId, ObjectType = type, RelationObject_ID = entityId, RelationObjectType = tableName }; if (!oldRelations.Any(x => x.RelationObject_ID.Equals(relation.RelationObject_ID) && x.RelationObjectType == relation.RelationObjectType)) { SiteObjectRelationRepository.Insert(relation); } } SiteObjectRelationRepository.SubmitChanges(); } return(Json("ok")); }
public static Expression <Func <DataContext, object, K> > GetExpression() { var _type = typeof(K); var itemParameter = Expression.Parameter(_type, "item"); var pkParameter = Expression.Parameter(typeof(object), "pk"); var dcParameter = Expression.Parameter(typeof(DataContext), "dc"); Expression <Func <IQueryable <K>, K> > exp = x => x.FirstOrDefault(y => true); Expression <Func <DataContext, Table <K> > > exp2 = x => x.GetTable <K>(); var firstOrDefaultInfo = ((MethodCallExpression)exp.Body).Method; var getTableInfo = ((MethodCallExpression)exp2.Body).Method; var pkPropertyName = LinqToSqlUtils.GetPKPropertyName(_type); var pkProperty = Expression.Property( itemParameter, pkPropertyName ); return(Expression.Lambda <Func <DataContext, object, K> >( Expression.Call(null, firstOrDefaultInfo, Expression.Call(dcParameter, getTableInfo), Expression.Lambda <Func <K, bool> > ( Expression.Equal( Expression.Convert(pkProperty, typeof(object)), pkParameter ), new[] { itemParameter } )), new[] { dcParameter, pkParameter })); }
private IQueryable <Group> GetHotGroupByRelations(object entity) { var courseTCList = CourseService.GetCourseTCListFor(entity.GetType(), _.List(LinqToSqlUtils.GetPK(entity))); return(GetHotGroupsForCourses(courseTCList)); }
private IQueryable <T> GetSingleRelation <T>(Type entityType, object id) where T : class { var type = LinqToSqlUtils.GetTableName(entityType); return(GetSingleRelation <T>(type, id)); }
public SiteObjectType(string name, Type type) { Name = name; Type = type; SysName = LinqToSqlUtils.GetTableName(type); ClassName = type.Name; }
public List <EntityWithList <IEntityCommonInfo, IEntityCommonInfo> > GetMenuTree(object entity) { var allTree = GetAllMenuTree(); return(allTree.GetValueOrDefault(Tuple.Create(entity.GetType(), (int)LinqToSqlUtils.GetPK(entity))) ?? new List <EntityWithList <IEntityCommonInfo, IEntityCommonInfo> >()); }
public static SiteObject GetSiteObject(this object obj) { return(new SiteObject { ID = LinqToSqlUtils.GetPK(obj), Type = LinqToSqlUtils.GetTableName(obj) }); }
public virtual ActionResult List(int pageIndex, OrderColumn orderColumn) { var currentFilterValues = GetCurrentFilterValues(); var items = AddFilterToList(currentFilterValues); if (orderColumn.ColumnName.IsEmpty()) { if (MetaData.EntityType.HasProperty(UpdateDate)) { orderColumn = new OrderColumn { IsDesc = true, ColumnName = UpdateDate, }; } else { orderColumn = new OrderColumn { IsDesc = true, ColumnName = LinqToSqlUtils.GetPKPropertyName(MetaData.EntityType) } }; } if (!orderColumn.ColumnName.IsEmpty()) { var orderQuery = orderColumn.ColumnName; if (orderColumn.IsDesc) { orderQuery += " " + Const.Common.Descending; } items = items.OrderBy(orderQuery); } items = OnListSelecting(items); var tableData = new List <ListVM.Row>(); var pagedList = items.ToPagedList(pageIndex - 1); foreach (var item in pagedList) { var id = LinqToSqlUtils.GetPK(item); var list = GetValuesForRow(item); tableData.Add(new ListVM.Row { Id = id, Entity = item, Values = list }); } var listVM = new ListVM(MetaData, pagedList, tableData); AddExtraControls(listVM, true); listVM.FilterValues = currentFilterValues; listVM.OrderColumn = orderColumn; ListVMCreated(listVM); return(View(listVM)); }
public IQueryable <SiteObjectRelation> GetByRelation(Type relationType, IEnumerable <object> relationObjectIds, Type objectType) { var relationObjectType = LinqToSqlUtils.GetTableName(relationType); return(GetAll().Where(sor => relationObjectIds.Contains(sor.RelationObject_ID) && sor.RelationObjectType == relationObjectType && sor.ObjectType == LinqToSqlUtils.GetTableName(objectType))); }
public IQueryable <SiteObjectRelation> GetTestSectionRelations() { var testType = LinqToSqlUtils.GetTableName(typeof(Test)); var sectionType = LinqToSqlUtils.GetTableName(typeof(Section)); var relations = SiteObjectRelationService.GetAll(x => x.ObjectType == testType && x.RelationObjectType == sectionType); return(relations); }
public JsonSection EntityJson(IEntityCommonInfo x) { var tp = x.GetType(); var type = SiteObject.TypeTableNames[tp]; var id = LinqToSqlUtils.GetPK(x); var count = Counts().GetValueOrDefault(Tuple.Create(type, id.ToString())); var name = GetName(type, id); return(new JsonSection(type, id, x.UrlName, count, name)); }
public IQueryable <T> GetDoubleRelation <T>(Type objectType, object id) where T : class { var type = LinqToSqlUtils.GetTableName(objectType); var requiredObjectType = LinqToSqlUtils.GetTableName(typeof(T)); var requiredRelations = GetRequiredRelationsByDoubleLink( id, type, requiredObjectType); var requiredIds = requiredRelations.Select(sor => sor.Object.ID); return(context.GetTable <T>().Where(LinqToSqlUtils.WhereContains <T>(requiredIds))); }
private void AddEntitiesWithoutNews(List <object> entitiesWithoutNews, IEnumerable <object> entities, ISiteObjectRelationService objectRelationService, IEnumerable <object> newIds) { var type = entities.First().GetType(); var relationIds = objectRelationService.GetRelation(typeof(News), newIds, type) .Select(x => x.RelationObject_ID).Cast <int>().ToList(); entitiesWithoutNews.AddRange( entities.Where(x => !relationIds.Contains((int)LinqToSqlUtils.GetPK(x)))); }
public IQueryable <T> GetSingleRelation <T>(string objectType, object id) where T : class { var requiredObjectType = LinqToSqlUtils.GetTableName(typeof(T)); var requiredIds = GetRequiredObjectIdsByObject(id, objectType, requiredObjectType); var objList = context.GetTable <T>().Where(LinqToSqlUtils.WhereContains <T>(requiredIds)); return(objList); }