Esempio n. 1
0
        public ControlPanelMenuEntity Update(ControlPanelMenuEntity entity)
        {
            if (entity.Type == MenuType.Page)
            {
                var dx = this.GetMenuQueryable(new ControlPanelMenuQueryEntity
                {
                    ApplicationIds = CPConfig.Keystone.ApplicationIds,
                    LinkPath       = entity.LinkPath,
                }).ToList();

                if (dx.Count > 0 && dx.All(d => d.MenuId != entity.MenuId))
                {
                    throw new BusinessException(InfoMessage.Error_MenuMaintain_DuplicateMenu);
                }
            }

            entity = this.UpdateItem(entity);
            DeleteLocalizedRes(new List <Guid> {
                entity.MenuId
            });

            foreach (var localized in entity.LocalizedMenuEntities)
            {
                localized.EditDate = DateTime.Now;
            }

            m_dataContext.ControlPanelMenuLocalizedRes.InsertAllOnSubmit(entity.LocalizedMenuEntities);
            this.m_dataContext.SubmitChanges();

            return(entity);
        }
Esempio n. 2
0
        public void Delete(string id)
        {
            var biz       = new ControlPanelMenuBiz();
            var linkQuery = new ControlPanelMenuQueryEntity
            {
                LinkPath = id
            };

            var entity = new ControlPanelMenuEntity
            {
                MenuId = Guid.Parse(id)
            };

            var links = biz.GetMenuItems(linkQuery);

            using (var scope = new TransactionScope())
            {
                biz.Delete(entity);

                foreach (var link in links)
                {
                    biz.Delete(new ControlPanelMenuEntity {
                        MenuId = link.MenuId
                    });
                }

                scope.Complete();
            }
        }
Esempio n. 3
0
        private void GetCategories(ControlPanelMenuEntity item, List <ControlPanelMenuEntity> list, ref List <ControlPanelMenuEntity> _categoryList)
        {
            var category = list.FirstOrDefault(c => c.MenuId == item.ParentMenuId);

            if (category != null)
            {
                if (!_categoryList.Contains(category))
                {
                    _categoryList.Add(category);
                }
                GetCategories(category, list, ref _categoryList);
            }


            //var uniques = new List<ControlPanelMenuEntity>();
            //foreach (var c in categories)
            //{
            //    if (!_categoryList.Contains(c))
            //    {

            //    }
            //}
            //_categoryList.AddRange(uniques);

            //foreach (var c in categories)
            //{

            //}
        }
Esempio n. 4
0
 public void Delete(ControlPanelMenuEntity entity)
 {
     this.DeleteItem(entity);
     DeleteLocalizedRes(new List <Guid> {
         entity.MenuId
     });
     this.m_dataContext.SubmitChanges();
 }
Esempio n. 5
0
        public ControlPanelMenuEntity GetMenuItem(ControlPanelMenuQueryEntity queryEntity)
        {
            var query = this.GetMenuQueryable(queryEntity);

            ControlPanelMenuEntity result = query.FirstOrDefault();

            return(result);
        }
Esempio n. 6
0
        public MenuItem Create(MenuItem item)
        {
            ControlPanelMenuEntity entity = item.ToEntity();

            entity = new ControlPanelMenuBiz().Create(entity);

            MenuItem result = entity.ToItem();

            return(result);
        }
Esempio n. 7
0
        public MenuItem Update(string id, MenuItem item)
        {
            ControlPanelMenuEntity entity = item.ToEntity();

            entity.MenuId = Guid.Parse(id);

            entity = new ControlPanelMenuBiz().Update(entity);

            MenuItem result = entity.ToItem();

            return(result);
        }
Esempio n. 8
0
        private ControlPanelMenuEntity CreateItem(ControlPanelMenuEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            entity.InDate = DateTime.Now;

            this.m_dataContext.ControlPanelMenuEntities.InsertOnSubmit(entity);

            return(entity);
        }
Esempio n. 9
0
        private void DeleteItem(ControlPanelMenuEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entity.MenuId == null)
            {
                throw new ArgumentNullException("entity.MenuId");
            }

            var original = from menu in this.m_dataContext.ControlPanelMenuEntities
                           where menu.MenuId == entity.MenuId
                           select menu;

            this.m_dataContext.ControlPanelMenuEntities.DeleteAllOnSubmit(original);
        }
Esempio n. 10
0
        public MenuItem Get(string id)
        {
            ControlPanelMenuQueryEntity queryEntity = new ControlPanelMenuQueryEntity()
            {
                MenuId = Guid.Parse(id)
            };

            var biz = new ControlPanelMenuBiz();
            ControlPanelMenuEntity item = biz.GetMenuItem(queryEntity);

            MenuItem result = item.ToItem();

            if (result != null)
            {
                result.LocalizedResCollection = biz.GetLocalizedRes(result.MenuId).ToMsg();
            }
            return(result);
        }
Esempio n. 11
0
        public static MenuItem ToItem(this ControlPanelMenuEntity entity)
        {
            MenuItem msg = null;

            if (entity != null)
            {
                msg = new MenuItem()
                {
                    MenuId                 = entity.MenuId,
                    DisplayName            = entity.DisplayName,
                    Description            = entity.Description,
                    IconStyle              = entity.IconStyle,
                    LinkPath               = entity.LinkPath,
                    AuthKey                = entity.AuthKey,
                    Type                   = entity.TypeCode,
                    IsDisplay              = entity.IsDisplay,
                    Status                 = entity.StatusCode,
                    SortIndex              = entity.SortIndex,
                    ParentMenuId           = entity.ParentMenuId,
                    ApplicationId          = entity.ApplicationId == null ? null : entity.ApplicationId.ToUpper(),
                    LanguageCode           = entity.LanguageCode,
                    InDate                 = entity.InDate,
                    InUser                 = entity.InUser,
                    EditDate               = entity.EditDate,
                    EditUser               = entity.EditUser,
                    LocalizedResCollection = entity.LocalizedMenuEntities.ToMsg()
                };

                if (msg.ApplicationId != null)
                {
                    foreach (var app in CPConfig.Keystone.KeystoneApplications)
                    {
                        if (app.Value.Equals(msg.ApplicationId, StringComparison.OrdinalIgnoreCase))
                        {
                            msg.ApplicationName = app.Key;
                            break;
                        }
                    }
                }
            }

            return(msg);
        }
Esempio n. 12
0
        public ControlPanelMenuEntity Create(ControlPanelMenuEntity entity)
        {
            if (entity.Type == MenuType.Page)
            {
                var d = this.GetMenuItem(new ControlPanelMenuQueryEntity
                {
                    ApplicationIds = CPConfig.Keystone.ApplicationIds,
                    LinkPath       = entity.LinkPath
                });

                if (d != null)
                {
                    throw new BusinessException(InfoMessage.Error_MenuMaintain_DuplicateMenu);
                }
            }

            this.CreateItem(entity);
            m_dataContext.ControlPanelMenuLocalizedRes.InsertAllOnSubmit(entity.LocalizedMenuEntities);
            this.m_dataContext.SubmitChanges();
            return(entity);
        }
Esempio n. 13
0
        public static ControlPanelMenuLocalizedRes ToEntity(this LocalizedRes msg, ControlPanelMenuEntity menuItemEntity)
        {
            ControlPanelMenuLocalizedRes entity = null;

            if (msg != null)
            {
                entity = new ControlPanelMenuLocalizedRes
                {
                    MenuDescription = msg.Description,
                    EditDate        = menuItemEntity.InDate,
                    EditUser        = menuItemEntity.InUser,
                    IconStyle       = menuItemEntity.IconStyle,
                    InDate          = menuItemEntity.InDate,
                    InUser          = menuItemEntity.InUser,
                    LanguageCode    = msg.LanguageCode,
                    LinkPath        = menuItemEntity.LinkPath,
                    DisplayName     = msg.Name,
                    ReferenceMenuId = menuItemEntity.MenuId
                };
            }
            return(entity);
        }
Esempio n. 14
0
        public static ControlPanelMenuEntity ToEntity(this MenuItem msg)
        {
            ControlPanelMenuEntity entity = null;

            if (msg != null)
            {
                entity = new ControlPanelMenuEntity()
                {
                    MenuId       = msg.MenuId.HasValue ? msg.MenuId.Value : Guid.NewGuid(),
                    DisplayName  = msg.DisplayName,
                    Description  = msg.Description,
                    IconStyle    = msg.IconStyle,
                    LinkPath     = msg.LinkPath,
                    AuthKey      = msg.AuthKey,
                    Type         = msg.Type.ToMenuType(),
                    IsDisplay    = msg.IsDisplay,
                    Status       = msg.Status.ToMenuStatus(),
                    SortIndex    = msg.SortIndex,
                    ParentMenuId = msg.ParentMenuId,
                    //ApplicationId = msg.ApplicationId == null ? null : msg.ApplicationId.ToUpper(),
                    LanguageCode = msg.LanguageCode,
                    InDate       = msg.InDate.HasValue ? msg.InDate.Value : DateTime.Now,
                    InUser       = msg.InUser,
                    EditDate     = msg.EditDate,
                    EditUser     = msg.EditUser
                };

                if (msg.ApplicationId != null)
                {
                    entity.ApplicationId = msg.ApplicationId.ToUpper();
                }
                else if (msg.ApplicationName != null)
                {
                    foreach (var app in CPConfig.Keystone.KeystoneApplications)
                    {
                        if (app.Key.Equals(msg.ApplicationName, StringComparison.OrdinalIgnoreCase))
                        {
                            entity.ApplicationId = app.Value.ToUpper();
                            break;
                        }
                    }
                    if (entity.ApplicationId == null)
                    {
                        throw new IndexOutOfRangeException("ApplicationId is not found via application name.");
                    }
                }

                entity.LocalizedMenuEntities = msg.LocalizedResCollection.ToEntity(entity);
            }

            if (entity.LocalizedMenuEntities != null)
            {
                for (int i = entity.LocalizedMenuEntities.Count - 1; i > -1; i--)
                {
                    if (StringUtility.IsNullOrEmpty(entity.LocalizedMenuEntities[i].DisplayName))
                    {
                        entity.LocalizedMenuEntities.RemoveAt(i);
                    }
                }
            }

            return(entity);
        }
Esempio n. 15
0
        public static List <ControlPanelMenuLocalizedRes> ToEntity(this List <LocalizedRes> msg, ControlPanelMenuEntity menuItemEntity)
        {
            List <ControlPanelMenuLocalizedRes> entity = null;

            if (msg != null)
            {
                entity = new List <ControlPanelMenuLocalizedRes>();

                msg.ForEach(item =>
                {
                    entity.Add(item.ToEntity(menuItemEntity));
                });
            }

            return(entity);
        }
Esempio n. 16
0
        private void GetAllSubMenuItems(ref List <Guid> menuIds, List <ControlPanelMenuEntity> collection, ControlPanelMenuEntity item)
        {
            var subCollection = collection.FindAll(p =>
            {
                if (item.MenuId == p.ParentMenuId)
                {
                    return(true);
                }
                return(false);
            });

            foreach (var sub in subCollection)
            {
                menuIds.Add(sub.MenuId);
                GetAllSubMenuItems(ref menuIds, collection, sub);
            }
        }
Esempio n. 17
0
        private ControlPanelMenuEntity UpdateItem(ControlPanelMenuEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entity.MenuId == null)
            {
                throw new ArgumentNullException("entity.MenuId");
            }

            var original = from menu in this.m_dataContext.ControlPanelMenuEntities
                           where menu.MenuId == entity.MenuId
                           select menu;

            var item = original.FirstOrDefault();

            if (item != null)
            {
                if (entity.DisplayName != null)
                {
                    item.DisplayName = entity.DisplayName;
                }

                if (entity.Description != null)
                {
                    item.Description = entity.Description;
                }

                if (entity.IconStyle != null)
                {
                    item.IconStyle = entity.IconStyle;
                }

                if (entity.AuthKey != null)
                {
                    item.AuthKey = entity.AuthKey;
                }

                if (entity.LinkPath != null)
                {
                    item.LinkPath = entity.LinkPath;
                }

                if (entity.IsDisplay != null)
                {
                    item.IsDisplay = entity.IsDisplay;
                }

                if (entity.SortIndex != null)
                {
                    item.SortIndex = entity.SortIndex;
                }

                if (entity.ParentMenuId != null)
                {
                    item.ParentMenuId = entity.ParentMenuId;
                }

                if (entity.Status != null)
                {
                    item.Status = entity.Status;
                }

                if (entity.ApplicationId != null)
                {
                    //如果ApplicationId改变,并且此Menu为Domain Categoory
                    //则需要对其下面的所有的Category和Page的ApplicationId进行批量更新
                    if (item.TypeCode == "C" && item.ParentMenuId == null && item.ApplicationId != entity.ApplicationId)
                    {
                        var menuIds    = new List <Guid>();
                        var collection = GetMenuItems(new ControlPanelMenuQueryEntity {
                            ApplicationIds = new string[] { item.ApplicationId }
                        });

                        GetAllSubMenuItems(ref menuIds, collection, item);

                        var list = from p in m_dataContext.ControlPanelMenuEntities
                                   where menuIds.Contains(p.MenuId)
                                   select p;

                        foreach (var i in list)
                        {
                            i.ApplicationId = entity.ApplicationId;
                            i.EditUser      = entity.EditUser;
                            i.EditDate      = DateTime.Now;
                        }
                    }

                    item.ApplicationId = entity.ApplicationId;
                }

                if (entity.EditUser != null)
                {
                    item.EditUser = entity.EditUser;
                }

                if (entity.LocalizedMenuEntities != null)
                {
                    item.LocalizedMenuEntities = entity.LocalizedMenuEntities;
                }

                item.EditDate = DateTime.Now;
            }
            ;

            return(item);
        }