/// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Result <int> deleteSecondlevelDir(int id)
        {
            Result <int> result = new Result <int>();

            try
            {
                using (var ts = new TransactionScope())
                {
                    DirDbContext      context     = new DirDbContext();
                    RoleMenuDbContext roleContext = new RoleMenuDbContext();
                    var entity = context.secondLevels.Where(x => x.id == id).FirstOrDefault();
                    if (entity != null)
                    {
                        context.secondLevels.Remove(entity);
                        context.SaveChanges();
                    }
                    var roleMenu = roleContext.roleMenus.Where(x => x.menuLevel == 2 && x.menuId == id).FirstOrDefault();
                    if (roleMenu != null)
                    {
                        roleContext.roleMenus.Remove(roleMenu);
                        roleContext.SaveChanges();
                    }
                    ts.Complete();
                }
            }
            catch (Exception err)
            {
                result.addError(err.Message);
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int updateFirstLevelDir(FirstLevelDirModel model)
        {
            DirDbContext context = new DirDbContext();
            var          result  = context.firstLevels.Where(x => x.id > 0 && x.activityFlag == 1);

            result = model.id.HasValue ? result.Where(x => x.id == model.id.Value) : null;
            if (result != null)
            {
                FirstLevel entity = result.First();
                modelToEntity(model, ref entity);
            }
            return(context.SaveChanges());
        }
Beispiel #3
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int deleteFirstlevelDir(int id)
        {
            //DONE: delete from roleMenu
            DirDbContext context = new DirDbContext();
            var          result  = context.firstLevels.Where(x => x.id > 0 && x.id == id);
            FirstLevel   entity  = result.First();

            context.firstLevels.Remove(entity);

            RoleMenuDbContext roleContext = new RoleMenuDbContext();
            var roleMenu = roleContext.roleMenus.Where(x => x.menuLevel == 1 && x.menuId == id).First();

            roleContext.roleMenus.Remove(roleMenu);
            roleContext.SaveChanges();
            return(context.SaveChanges());
        }
Beispiel #4
0
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int addFirstLevelDir(FirstLevelDirModel model)
        {
            DirDbContext context = new DirDbContext();

            if (model != null)
            {
                FirstLevel entity = new FirstLevel();
                modelToEntity(model, ref entity);
                DirTools tools = new DirTools();
                entity.afterContent = tools.afterContent;
                entity.beforContent = tools.beforContent;
                entity.activityFlag = 1;
                var result = context.firstLevels.Add(entity);
            }
            return(context.SaveChanges());
        }