private IQueryable <T> GetSingleRelation <T>(Type entityType, object id) where T : class { var type = LinqToSqlUtils.GetTableName(entityType); return(GetSingleRelation <T>(type, id)); }
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 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 SiteObjectType(string name, Type type) { Name = name; Type = type; SysName = LinqToSqlUtils.GetTableName(type); ClassName = type.Name; }
/* [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 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()); }
public static SiteObject GetSiteObject(this object obj) { return(new SiteObject { ID = LinqToSqlUtils.GetPK(obj), Type = LinqToSqlUtils.GetTableName(obj) }); }
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 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 <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))); }
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); }
public IQueryable <T> GetWithoutRelation <T>() where T : class { var requiredObjectType = LinqToSqlUtils.GetTableName(typeof(T)); var objectIdsWithRelations = from sor in context.GetTable <SiteObjectRelation>() where sor.ObjectType == requiredObjectType select sor.Object_ID; return(context.GetTable <T>() .Where(LinqToSqlUtils.WhereContains <T>(objectIdsWithRelations, true))); }
public ActionResult MainEntityList(string type, object id) { var entities = EntityService.GetMainEntites(); return(this.Content( H.Form(Url.Action <SiteObjectRelationEntityController>(c => c.MainEntityList(type, id, null))) .Id("add-entities-form")[ H.Ul(entities.Select(x => H.span[ H.InputCheckbox("entities", LinqToSqlUtils.GetTableName(x) + ";" + LinqToSqlUtils.GetPK(x)), x.Name])) .Class("default-ul"), H.button["Добавить"]] .ToString())); }
public ActionResult SiteObjectEdit(string typeName, object id) { var entityType = typeof(SpecialistDataContext).Assembly.GetTypes() .Where(t => t.FullName == typeName).First(); var type = LinqToSqlUtils.GetTableName(entityType); var siteObject = SiteObjectService .GetBy(type, LinqToSqlUtils.CorrectPKType(id, entityType)); if (siteObject == null) { return(Redirect(Request.UrlReferrer.AbsoluteUri)); } return(View(ViewNames.EditRelationList, new EditVM(siteObject, MetaDataProvider.Get(typeof(SiteObject))))); }
public ActionResult MainPageResponse() { var courseTableName = LinqToSqlUtils.GetTableName(typeof(Course)); var courseTCs = GroupService.GetPlannedAndNotBegin().Where(g => g.Discount > 0) .Take(CommonConst.GroupForMainCount) .Select(x => x.Course_TC).Distinct().ToList(); var courseTCsForResponse = CacheUtils.Get("courseTCsForMainResponses", () => SiteObjectRelationService.GetRelation(typeof(Course), courseTCs) .SelectMany(x => x.RelationObject.RelationObjectRelations.Where(sor => sor.ObjectType == courseTableName).Select(y => y.Object_ID)).Select(x => x.ToString()).Distinct().ToList()); var response = ResponseService.GetRandomForMainPage(courseTCsForResponse); var orgResponse = ResponseService.GetOrgRandomResponseForMainPage(); return(PartialView(Tuple.Create(response, orgResponse))); }
private int UpdateCourseRelations(ResponseUpdateView model) { var courseTableName = LinqToSqlUtils.GetTableName(typeof(Course)); var relations = SORelationService.GetAll(x => x.Object_ID.Equals(model.FromCourseTC) && x.ObjectType == courseTableName).ToList(); foreach (var relation in relations) { relation.Object_ID = model.ToCourseTC; } var count = relations.Count; return(count); }
public IQueryable <SiteObjectRelation> GetRelation(Type type, IEnumerable <object> objectIds, Type relationType = null) { var objectType = LinqToSqlUtils.GetTableName(type); IQueryable <SiteObjectRelation> query; if (objectIds.Any()) { query = GetAll().Where(sor => objectIds.Contains(sor.Object_ID) && sor.ObjectType == objectType); } else { query = GetAll().Where(sor => sor.ObjectType == objectType); } if (relationType != null) { var relationObjectType = LinqToSqlUtils.GetTableName(relationType); query = query.Where(sor => sor.RelationObjectType == relationObjectType); } return(query); }
public ActionResult Search(string typeName, int id, int?pageIndex) { if (!pageIndex.HasValue) { return(RedirectToAction(() => Search(typeName, id, 1))); } var type = SiteObject.GetType(typeName); if (type == null) { return(null); } var news = SiteObjectService.GetByRelationObject <News>(type, id) .IsActive().OrderByDescending(n => n.PublishDate) .ToPagedList(pageIndex.GetValueOrDefault(1) - 1, 5); return(View( new RelationNewsVM { News = news, SiteObject = SiteObjectService.GetBy( LinqToSqlUtils.GetTableName(type), id) })); }
private IQueryable <SiteObjectRelation> GetRequiredRelationsByRelations2WithCity( object id, string type, string requiredObjectType, string cityTC) { var cityObjectType = LinqToSqlUtils.GetTableName(typeof(City)); var relations = GetRequiredRelationsByDoubleLink(id, type, requiredObjectType); /* context.GetTable<SiteObjectRelation>().Where( * sor => sor.Object_ID == id && sor.ObjectType == type) * .SelectMany(sor => sor.RelationObject.RelationObjectRelations) * .Where(sor => sor.Object.Type == requiredObjectType);*/ var result = from o in relations let cityTCList = from sor in context.GetTable <SiteObjectRelation>() where sor.ObjectType == requiredObjectType && o.Object_ID == sor.Object_ID && sor.RelationObjectType == cityObjectType select sor.RelationObject_ID where cityTCList.Count() == 0 || cityTCList.Contains(cityTC) select o; return(result); }
private void SetSiteObject(object id, EditVM editVM) { var siteObjectType = LinqToSqlUtils.GetTableName(MetaData.EntityType); editVM.SiteObject = SiteObjectService.GetBy(siteObjectType, id); }
public Type GetTypeByTableName(string tableName) { return(_contextList.SelectMany(pair => pair.Value) .FirstOrDefault(t => LinqToSqlUtils.GetTableName(t) == tableName)); }
public IQueryable <T> GetRelation <T>(Type objectType, object id) where T : class { var type = LinqToSqlUtils.GetTableName(objectType); var requiredObjectType = LinqToSqlUtils.GetTableName(typeof(T)); var cityTC = UserSettingsService.CityTC; IQueryable <T> objList = null; var doubleLinkRelations = new List <Type> { typeof(Banner), typeof(Response), typeof(News) }; var singleLinkRelations = new List <Type> { typeof(City) }; var byRelationObject = new List <Type> { typeof(Course), typeof(Product), typeof(Certification) }; if (doubleLinkRelations.Contains(typeof(T))) { IQueryable <SiteObjectRelation> requiredRelations; if (cityTC == null) { requiredRelations = GetRequiredRelationsByDoubleLink( id, type, requiredObjectType); } else { requiredRelations = GetRequiredRelationsByRelations2WithCity( id, type, requiredObjectType, cityTC); } /* if (cityTC != null ) * requiredRelations = FilterByCity<T>(requiredRelations, * context.GetTable<SiteObjectRelation>(), cityTC);*/ var requiredIds = requiredRelations.Select(sor => sor.Object.ID); objList = context.GetTable <T>().Where( LinqToSqlUtils.WhereContains <T>(requiredIds)); } else if (singleLinkRelations.Contains(typeof(T))) { objList = GetSingleRelation <T>(objectType, id); } else if (byRelationObject.Contains(typeof(T))) { objList = GetByRelationObject <T>(objectType, id); } /* if (typeof(T) == ) * objList = (IQueryable<T>)( * from o in context.GetTable<Response>() * where context.GetTable<SiteObjectRelation>().Where( * sor => sor.Object_ID == id && sor.ObjectType == type) * .SelectMany(sor => sor.RelationObject.RelationObjectRelations) * .Where(sor => sor.Object.Type == relationObjectType) * .Select(sor => sor.Object.ID).Contains(o.ResponseId) * select o); * * if (typeof(T) == typeof(Certification)) * objList = (IQueryable<T>)( * from o in context.GetTable<Certification>() * where context.GetTable<SiteObjectRelation>().Where( * sor => sor.Object_ID == id && sor.ObjectType == type * && sor.RelationObjectType == requiredObjectType) * .Select(sor => sor.RelationObject_ID).Contains(o.Certification_ID) * select o); * */ return(objList); }