public override RouteValueDictionary GetRouteValues(object entity) { return(new RouteValueDictionary { { "id", LinqToSqlUtils.GetPK(entity) }, { "tabFocus", DisplayName.GetHashCode() } }); }
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())); }
private IQueryable <Group> GetHotGroupByRelations(object entity) { var courseTCList = CourseService.GetCourseTCListFor(entity.GetType(), _.List(LinqToSqlUtils.GetPK(entity))); return(GetHotGroupsForCourses(courseTCList)); }
public void DeleteAndSubmit(T obj) { var id = LinqToSqlUtils.GetPK(obj); var oldObj = GetByPK(id); _source.Remove(oldObj); }
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 override RouteValueDictionary GetRouteValues(object entity) { return(new RouteValueDictionary { { "pageIndex", 1 }, { ForeignProperty, LinqToSqlUtils.GetPK(entity) } }); }
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 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)); }
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 Entity(object entity) { Type = entity.GetType(); if (LinqToSqlUtils.GetPKPropertyInfo(Type) != null) { PK = LinqToSqlUtils.GetPK(entity); } TypeName = Type.Name; if (entity is IEntityCommonInfo) { Name = entity.As <IEntityCommonInfo>().Name; } }
public override string ToString() { if (Entity == null) { return(string.Empty); } return(HtmlControls.Anchor( _urlHelper.Action("Edit", Entity.GetType().Name + Const.Common.ControlPosfix, new { id = LinqToSqlUtils.GetPK(Entity) }), EntityDisplayName .CutLong(MetaData.DisplayProperty().GetValue(Entity).ToString()) ).ToString()); }
public virtual void UpdateOrInsert(T obj) { var id = LinqToSqlUtils.GetPK(obj); if (id.Equals(LinqToSqlUtils.GetPKPropertyInfo(_type).PropertyType.Default())) { this.InsertAndSubmit(obj); return; } var oldOjb = GetByPK(id); oldOjb.UpdateByMeta(obj); context.SubmitChanges(); }
public virtual ActionResult Add(FormCollection formCollection, string operationType) { var queryString = formCollection["QueryString"]; var values = new Dictionary <string, object>(); if (queryString != null) { values = HttpUtility.ParseQueryString(queryString) .ConvertTypeByProperties(typeof(T)); } var routeValueDictionary = new RouteValueDictionary(values) { { "pageIndex", 1 } }; var obj = new T(); UpdateEntity(obj, formCollection); OnEntityAdding(obj); Validate(obj); if (!ModelState.IsValid) { var editVM = new EditVM(obj, MetaData); return(View("Add", editVM)); } try { SetUpdateDateAndChanger(obj); Repository.InsertAndSubmit(obj); } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); var editVM = new EditVM(obj, MetaData); return(View("Add", editVM)); } AfterAdded(obj); if (operationType == OperationType.Apply) { return(RedirectToAction("Edit", new { id = LinqToSqlUtils.GetPK(obj) })); } return(RedirectToAction("List", routeValueDictionary)); }
public IQueryable <T> GetRelation <T>(object obj) where T : class { var id = LinqToSqlUtils.GetPK(obj); return(GetRelation <T>(obj.GetType(), id)); }
public override RouteValueDictionary GetRouteValues(object entity) { return(new RouteValueDictionary(new { typeName = entity.GetType().FullName, id = LinqToSqlUtils.GetPK(entity) })); }
public void Delete(T obj) { var id = LinqToSqlUtils.GetPK(obj); context.GetTable <T>().DeleteOnSubmit(GetByPK(id)); }
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 T GetByPK(object pk) { return(_source.Where(x => LinqToSqlUtils.GetPK(x).Equals(pk)).FirstOrDefault()); }
public override RouteValueDictionary GetRouteValues(object entity) { return(new RouteValueDictionary(new { id = LinqToSqlUtils.GetPK(entity) })); }
public IQueryable <T> GetDoubleRelation <T>(object obj) where T : class { return(GetDoubleRelation <T>(obj.GetType(), LinqToSqlUtils.GetPK(obj))); }
private int GetMaxId() { return(_source.Max(x => Convert.ToInt32(LinqToSqlUtils.GetPK(x)))); }