예제 #1
0
        public new void Insert(AdminPermission entity)
        {
            // When no parent selected
            if (entity.ParentId == null)
            {
                var maxNestedSet = AsNoTracking.Max(c => c.Right) ?? 0;
                entity.Left  = maxNestedSet + 1;
                entity.Right = maxNestedSet + 2;
                entity.Depth = 0;
            }
            else
            {
                var parentAdminPermission = AsNoTracking.First(w => w.Id == entity.ParentId);
                var valNode = (parentAdminPermission.Left + 1 == parentAdminPermission.Right)
                    ? parentAdminPermission.Left
                    : parentAdminPermission.Right - 1;

                var rightNodes = _dbSet.Where(f => f.Right > valNode).ToList();
                rightNodes.ForEach(c => c.Right = c.Right + 2);

                var leftNodes = _dbSet.Where(f => f.Left > valNode).ToList();
                leftNodes.ForEach(c => c.Left = c.Left + 2);

                entity.Left  = valNode + 1;
                entity.Right = valNode + 2;
                entity.Depth = parentAdminPermission.Depth + 1;
            }

            _dbSet.Add(entity);
            _unitOfWork.Commit();
        }
예제 #2
0
        public string GenerateUniqueSlug(string phrse, int?id = null, string slugFieldName = "Slug")
        {
            int?loop = null;
            var slug = phrse.GenerateSlug();

            var where = $"{slugFieldName} = @0";
            if (id != null)
            {
                where += " AND Id <> @1";
            }

            while (AsNoTracking.Where(where, slug, id).Count() > 0)
            {
                loop = loop == null ? 1 : loop + 1;
                slug = phrse.GenerateSlug() + ("-" + loop);
            }

            return(slug);
        }
예제 #3
0
 public Domain.Members.Member FindActiveUserByEmail(string email)
 {
     return(AsNoTracking.FirstOrDefault(t => t.Email == email && t.IsActive));
 }