internal static void Delete(int id) { var entities = QPContext.EFContext; var dalDb = entities.CustomActionSet .Include("Action.ToolbarButtons") .Include("Action.ContextMenuItems") .Include("Action.EntityType") .Single(a => a.Id == id); var contextMenuId = dalDb.Action.EntityType.ContextMenuId; foreach (var t in dalDb.Action.ToolbarButtons.ToArray()) { entities.ToolbarButtonSet.DeleteObject(t); } foreach (var t in entities.ToolbarButtonSet.Where(b => b.ParentActionId == dalDb.ActionId)) { entities.ToolbarButtonSet.DeleteObject(t); } int?oldContextMenuId = null; foreach (var c in dalDb.Action.ContextMenuItems.ToArray()) { oldContextMenuId = c.ContextMenuId; entities.ContextMenuItemSet.DeleteObject(c); } entities.BackendActionSet.DeleteObject(dalDb.Action); entities.CustomActionSet.DeleteObject(dalDb); entities.SaveChanges(); if (oldContextMenuId != contextMenuId) { SetBottomSeparator(oldContextMenuId); } SetBottomSeparator(contextMenuId); BackendActionCache.Reset(); }
internal static CustomAction Update(CustomAction customAction) { GetById(customAction.Id); var entities = QPContext.EFContext; var dal = MapperFacade.CustomActionMapper.GetDalObject(customAction); dal.LastModifiedBy = QPContext.CurrentUserId; using (new QPConnectionScope()) { dal.Modified = Common.GetSqlDate(QPConnectionScope.Current.DbConnection); } entities.CustomActionSet.Attach(dal); entities.ObjectStateManager.ChangeObjectState(dal, EntityState.Modified); var dal2 = MapperFacade.BackendActionMapper.GetDalObject(customAction.Action); entities.BackendActionSet.Attach(dal2); entities.ObjectStateManager.ChangeObjectState(dal2, EntityState.Modified); // Toolbar Buttons foreach (var t in entities.ToolbarButtonSet.Where(t => t.ActionId == customAction.Action.Id)) { entities.ToolbarButtonSet.DeleteObject(t); } foreach (var t in MapperFacade.ToolbarButtonMapper.GetDalList(customAction.Action.ToolbarButtons.ToList())) { entities.ToolbarButtonSet.AddObject(t); } var refreshBtnDal = CreateRefreshButton(dal.ActionId); if (!customAction.Action.IsInterface) { foreach (var t in entities.ToolbarButtonSet.Where(b => b.ParentActionId == dal.ActionId && b.ActionId == refreshBtnDal.ActionId)) { entities.ToolbarButtonSet.DeleteObject(t); } } if (customAction.Action.IsInterface && !entities.ToolbarButtonSet.Any(b => b.ParentActionId == dal.ActionId && b.ActionId == refreshBtnDal.ActionId)) { entities.ToolbarButtonSet.AddObject(refreshBtnDal); } int?oldContextMenuId = null; foreach (var c in entities.ContextMenuItemSet.Where(c => c.ActionId == customAction.Action.Id)) { oldContextMenuId = c.ContextMenuId; entities.ContextMenuItemSet.DeleteObject(c); } foreach (var c in MapperFacade.ContextMenuItemMapper.GetDalList(customAction.Action.ContextMenuItems.ToList())) { entities.ContextMenuItemSet.AddObject(c); } var dalDb = entities.CustomActionSet .Include("Contents") .Include("Sites") .Single(a => a.Id == customAction.Id); var inmemorySiteIDs = new HashSet <decimal>(customAction.Sites.Select(bs => Converter.ToDecimal(bs.Id))); var indbSiteIDs = new HashSet <decimal>(dalDb.Sites.Select(bs => Converter.ToDecimal(bs.Id))); foreach (var s in dalDb.Sites.ToArray()) { if (!inmemorySiteIDs.Contains(s.Id)) { entities.SiteSet.Attach(s); dalDb.Sites.Remove(s); } } foreach (var s in MapperFacade.SiteMapper.GetDalList(customAction.Sites.ToList())) { if (!indbSiteIDs.Contains(s.Id)) { entities.SiteSet.Attach(s); dal.Sites.Add(s); } } // Binded Contents var inmemoryContentIDs = new HashSet <decimal>(customAction.Contents.Select(bs => Converter.ToDecimal(bs.Id))); var indbContentIDs = new HashSet <decimal>(dalDb.Contents.Select(bs => Converter.ToDecimal(bs.Id))); foreach (var s in dalDb.Contents.ToArray()) { if (!inmemoryContentIDs.Contains(s.Id)) { entities.ContentSet.Attach(s); dalDb.Contents.Remove(s); } } foreach (var s in MapperFacade.ContentMapper.GetDalList(customAction.Contents.ToList())) { if (!indbContentIDs.Contains(s.Id)) { entities.ContentSet.Attach(s); dal.Contents.Add(s); } } entities.SaveChanges(); if (oldContextMenuId != customAction.Action.EntityType.ContextMenu.Id) { SetBottomSeparator(oldContextMenuId); } SetBottomSeparator(customAction.Action.EntityType.ContextMenu.Id); var updated = MapperFacade.CustomActionMapper.GetBizObject(dal); BackendActionCache.Reset(); return(updated); }
internal static CustomAction Save(CustomAction customAction) { var entities = QPContext.EFContext; var actionDal = MapperFacade.BackendActionMapper.GetDalObject(customAction.Action); entities.BackendActionSet.AddObject(actionDal); EntityObject.VerifyIdentityInserting(EntityTypeCode.BackendAction, actionDal.Id, customAction.ForceActionId); if (customAction.ForceActionId != 0) { actionDal.Id = customAction.ForceActionId; } DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.BackendAction); entities.SaveChanges(); DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.BackendAction); var customActionDal = MapperFacade.CustomActionMapper.GetDalObject(customAction); customActionDal.LastModifiedBy = QPContext.CurrentUserId; customActionDal.Action = actionDal; using (new QPConnectionScope()) { customActionDal.Created = Common.GetSqlDate(QPConnectionScope.Current.DbConnection); customActionDal.Modified = customActionDal.Created; } entities.CustomActionSet.AddObject(customActionDal); DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.CustomAction, customAction); entities.SaveChanges(); DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.CustomAction); foreach (var t in MapperFacade.ToolbarButtonMapper.GetDalList(customAction.Action.ToolbarButtons.ToList())) { t.ActionId = customActionDal.Action.Id; entities.ToolbarButtonSet.AddObject(t); } foreach (var c in MapperFacade.ContextMenuItemMapper.GetDalList(customAction.Action.ContextMenuItems.ToList())) { c.ActionId = customActionDal.Action.Id; entities.ContextMenuItemSet.AddObject(c); } foreach (var s in MapperFacade.SiteMapper.GetDalList(customAction.Sites.ToList())) { entities.SiteSet.Attach(s); customActionDal.Sites.Add(s); } foreach (var s in MapperFacade.ContentMapper.GetDalList(customAction.Contents.ToList())) { entities.ContentSet.Attach(s); customActionDal.Contents.Add(s); } if (customAction.Action.IsInterface) { var refreshBtnDal = CreateRefreshButton(customActionDal.ActionId); entities.ToolbarButtonSet.AddObject(refreshBtnDal); } entities.SaveChanges(); var contextMenuId = entities.EntityTypeSet.Single(t => t.Id == customAction.Action.EntityTypeId).ContextMenuId; SetBottomSeparator(contextMenuId); var updated = MapperFacade.CustomActionMapper.GetBizObject(customActionDal); BackendActionCache.Reset(); return(updated); }
internal static CustomAction Update(CustomAction customAction) { GetById(customAction.Id); var entities = QPContext.EFContext; var dal = MapperFacade.CustomActionMapper.GetDalObject(customAction); dal.LastModifiedBy = QPContext.CurrentUserId; using (new QPConnectionScope()) { dal.Modified = Common.GetSqlDate(QPConnectionScope.Current.DbConnection); } entities.Entry(dal).State = EntityState.Modified; var dal2 = MapperFacade.BackendActionMapper.GetDalObject(customAction.Action); entities.Entry(dal2).State = EntityState.Modified; // Toolbar Buttons foreach (var t in entities.ToolbarButtonSet.Where(t => t.ActionId == customAction.Action.Id)) { entities.Entry(t).State = EntityState.Deleted; } foreach (var t in MapperFacade.ToolbarButtonMapper.GetDalList(customAction.Action.ToolbarButtons.ToList())) { entities.Entry(t).State = EntityState.Added; } var refreshBtnDal = CreateRefreshButton(dal.ActionId); if (!customAction.Action.IsInterface) { foreach (var t in entities.ToolbarButtonSet.Where(b => b.ParentActionId == dal.ActionId && b.ActionId == refreshBtnDal.ActionId)) { entities.Entry(t).State = EntityState.Deleted; } } if (customAction.Action.IsInterface && !entities.ToolbarButtonSet.Any(b => b.ParentActionId == dal.ActionId && b.ActionId == refreshBtnDal.ActionId)) { entities.Entry(refreshBtnDal).State = EntityState.Added; } int?oldContextMenuId = null; foreach (var c in entities.ContextMenuItemSet.Where(c => c.ActionId == customAction.Action.Id)) { oldContextMenuId = c.ContextMenuId; entities.Entry(c).State = EntityState.Deleted; } foreach (var c in MapperFacade.ContextMenuItemMapper.GetDalList(customAction.Action.ContextMenuItems.ToList())) { entities.Entry(c).State = EntityState.Added; } var dalDb = entities.CustomActionSet .Include(x => x.ContentCustomActionBinds) .Include(x => x.SiteCustomActionBinds) .Single(a => a.Id == customAction.Id); var inmemorySiteIDs = new HashSet <decimal>(customAction.SiteIds.Select(bs => Converter.ToDecimal(bs))); var dalSiteBinds = dalDb.SiteCustomActionBinds.ToArray(); var indbSiteIDs = new HashSet <decimal>(dalSiteBinds.Select(bs => bs.SiteId)); var dalSiteBindsToRemove = dalSiteBinds.Where(n => !inmemorySiteIDs.Contains(n.SiteId)).ToArray(); var dalSiteBindsToCreate = customAction.SiteIds.Where(n => !indbSiteIDs.Contains(n)).Select( n => new SiteCustomActionBindDAL { CustomAction = dal, SiteId = n } ); foreach (var s in dalSiteBindsToRemove) { dal.SiteCustomActionBinds.Remove(s); } foreach (var c in dalSiteBindsToCreate) { dal.SiteCustomActionBinds.Add(c); } // Binded Contents var inmemoryContentIDs = new HashSet <decimal>(customAction.ContentIds.Select(bs => Converter.ToDecimal(bs))); var dalBinds = dalDb.ContentCustomActionBinds.ToArray(); var indbContentIDs = new HashSet <decimal>(dalBinds.Select(bs => bs.ContentId)); var dalBindsToRemove = dalBinds.Where(n => !inmemoryContentIDs.Contains(n.ContentId)).ToArray(); var dalbindsToCreate = customAction.ContentIds.Where(n => !indbContentIDs.Contains(n)).Select( n => new ContentCustomActionBindDAL { CustomAction = dal, ContentId = n } ); foreach (var r in dalBindsToRemove) { dal.ContentCustomActionBinds.Remove(r); } foreach (var c in dalbindsToCreate) { dal.ContentCustomActionBinds.Add(c); } entities.SaveChanges(); if (oldContextMenuId != customAction.Action.EntityType.ContextMenu.Id) { SetBottomSeparator(oldContextMenuId); } SetBottomSeparator(customAction.Action.EntityType.ContextMenu.Id); var updated = MapperFacade.CustomActionMapper.GetBizObject(dal); BackendActionCache.ResetForCustomerCode(); return(updated); }
internal static CustomAction Save(CustomAction customAction) { var entities = QPContext.EFContext; var actionDal = MapperFacade.BackendActionMapper.GetDalObject(customAction.Action); entities.Entry(actionDal).State = EntityState.Added; EntityObject.VerifyIdentityInserting(EntityTypeCode.BackendAction, actionDal.Id, customAction.ForceActionId); if (customAction.ForceActionId != 0) { actionDal.Id = customAction.ForceActionId; } DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.BackendAction); entities.SaveChanges(); DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.BackendAction); var customActionDal = MapperFacade.CustomActionMapper.GetDalObject(customAction); customActionDal.LastModifiedBy = QPContext.CurrentUserId; customActionDal.Action = actionDal; using (new QPConnectionScope()) { customActionDal.Created = Common.GetSqlDate(QPConnectionScope.Current.DbConnection); customActionDal.Modified = customActionDal.Created; } entities.Entry(customActionDal).State = EntityState.Added; DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.CustomAction, customAction); entities.SaveChanges(); DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.CustomAction); var buttonsToInsert = MapperFacade.ToolbarButtonMapper.GetDalList(customAction.Action.ToolbarButtons.ToList()); foreach (var item in buttonsToInsert) { item.ActionId = customActionDal.ActionId; entities.Entry(item).State = EntityState.Added; } var cmiToInsert = MapperFacade.ContextMenuItemMapper.GetDalList(customAction.Action.ContextMenuItems.ToList()); foreach (var item in cmiToInsert) { item.ActionId = customActionDal.ActionId; entities.Entry(item).State = EntityState.Added; } customActionDal.SiteCustomActionBinds = new List <SiteCustomActionBindDAL>(); foreach (var item in customAction.SiteIds) { var bind = new SiteCustomActionBindDAL { SiteId = item, CustomAction = customActionDal }; customActionDal.SiteCustomActionBinds.Add(bind); } customActionDal.ContentCustomActionBinds = new List <ContentCustomActionBindDAL>(); foreach (var item in customAction.ContentIds) { var bind = new ContentCustomActionBindDAL { ContentId = item, CustomAction = customActionDal }; customActionDal.ContentCustomActionBinds.Add(bind); } if (customAction.Action.IsInterface) { var refreshBtnDal = CreateRefreshButton(customActionDal.ActionId); entities.Entry(refreshBtnDal).State = EntityState.Added; } entities.SaveChanges(); var contextMenuId = entities.EntityTypeSet.Single(t => t.Id == customAction.Action.EntityTypeId).ContextMenuId; SetBottomSeparator(contextMenuId); var updated = MapperFacade.CustomActionMapper.GetBizObject(customActionDal); updated.Action = MapperFacade.BackendActionMapper.GetBizObject(actionDal); BackendActionCache.ResetForCustomerCode(); return(updated); }
public static void ResetUserCache() => BackendActionCache.ResetForUser();