public void GetUsers_WhenNotEmptyContext_ReturnsUsers()
        {
            // Arrange
            var user = new User
            {
                Id       = 1,
                Username = "******",
                Email    = "*****@*****.**",
                Name     = "fake",
                Phone    = "1234567",
                Website  = "fake.com"
            };

            _cloudDbContext.Users.Add(user);
            _cloudDbContext.SaveChanges();

            var usersCount = _cloudDbContext.Users.Count();

            // Act
            var users = _cloudManager.GetUsers().ToList();

            // Assert
            Assert.NotEmpty(users);
            Assert.Equal(users.Count, usersCount);
        }
Exemplo n.º 2
0
 private void CreateUsers()
 {
     for (int i = 0; i < 10; i++)
     {
         string userName    = "******" + i;
         var    defaultUser = _context.Users.IgnoreQueryFilters().FirstOrDefault(e => e.UserName == userName);
         if (defaultUser == null)
         {
             _context.Users.Add(new User()
             {
                 UserName         = userName,
                 PassWord         = "******" + i,
                 TrueName         = "test" + i,
                 Sex              = null,
                 Birthday         = Clock.Now,
                 Phone            = "",
                 Email            = "",
                 IDCard           = "",
                 UserStatus       = UserStatus.ÆôÓÃ,
                 LoginIp          = "",
                 LoginTime        = Clock.Now,
                 LoginCount       = 0,
                 LoginFailedTimes = null,
                 RegisterIp       = "",
                 RegisterTime     = Clock.Now,
                 PasswordSetTime  = Clock.Now,
                 Departments      = null,
                 UserRoles        = null
             });
         }
         _context.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public Guid CreateDirectory(CreateDirectoryData createDirectoryData)
 {
     Models.Directory directory = new Models.Directory()
     {
         Id                = Guid.NewGuid(),
         Name              = createDirectoryData.Name,
         OwnerId           = new Guid(User.Identity.GetUserId()),
         ParentDirectoryId = createDirectoryData.ParentDirectoryId,
     };
     db.Directories.Add(directory);
     db.SaveChanges();
     return(directory.Id);
 }
Exemplo n.º 4
0
        public bool AddUser(long ProjectID, long UserID)
        {
            var userproject = _CloudDbContext.UserProjects.FirstOrDefault(m => m.UserID == UserID && m.ProjectID == ProjectID);

            if (userproject == null)
            {
                _CloudDbContext.UserProjects.Add(new UserProject()
                {
                    ProjectID = ProjectID,
                    UserID    = UserID,
                    Role      = 0
                                //CreateTime = DateTimeUtility.
                });
                var _rows = _CloudDbContext.SaveChanges();
                return(_rows > 0);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 5
0
        public bool SaveGuid(Guid g)
        {
            using (var db = new CloudDbContext())
            {
                var guid = new UsedGuid {
                    Guid = g
                };

                db.UsedGuids.Add(guid);
                return(db.SaveChanges() > 0);
            }
        }
Exemplo n.º 6
0
        public void Build()
        {
            var users = new List <User>();

            for (int i = 0; i < 10; i++)
            {
                users.Add(new User()
                {
                    UserName         = "******" + i,
                    PassWord         = "******" + i,
                    TrueName         = "test" + i,
                    Sex              = null,
                    Birthday         = Clock.Now,
                    Phone            = "",
                    Email            = "",
                    IDCard           = "",
                    UserStatus       = UserStatus.ÆôÓÃ,
                    LoginIp          = "",
                    LoginTime        = Clock.Now,
                    LoginCount       = 0,
                    LoginFailedTimes = null,
                    RegisterIp       = "",
                    RegisterTime     = Clock.Now,
                    PasswordSetTime  = Clock.Now,
                    Departments      = null,
                    UserRoles        = null
                });
            }
            _context.Users.AddRange(users);
            _context.SaveChanges();

            var pages = new List <Page>();

            for (int i = 0; i < 10; i++)
            {
                pages.Add(new Page()
                {
                    CreationTime       = Clock.Now,
                    CreatorUserId      = Guid.Empty,
                    Description        = "",
                    Icon               = "",
                    IsVisible          = true,
                    LastModifierUserId = Guid.Empty,
                    Name               = "²Ëµ¥" + i
                });
            }
            _context.Pages.AddRange(pages);
        }
Exemplo n.º 7
0
        public bool UpdateOrderBy(long projectID, List <Page> pages)
        {
            var list = _CloudDbContext.Pages.Where(m => m.ProjectID == projectID);

            foreach (var page in pages)
            {
                var dbpage = list.FirstOrDefault(m => m.ID == page.ID);
                if (dbpage != null)
                {
                    if (dbpage.OrderBy != page.OrderBy)
                    {
                        dbpage.OrderBy = page.OrderBy;
                    }
                }
            }
            _CloudDbContext.SaveChanges();
            return(true);
        }
Exemplo n.º 8
0
 public static void Initialize(IServiceProvider serviceProvider)
 {
     using (var context = new CloudDbContext(serviceProvider.GetRequiredService <DbContextOptions <CloudDbContext> >()))
     {
         if (context.Users.Any())
         {
             return;   // 已经初始化过数据,直接返回
         }
         Guid departmentId = Guid.NewGuid();
         #region 增加一个部门
         context.Departments.Add(
             new Department
         {
             Id                 = departmentId,
             ParentId           = Guid.Empty,
             Name               = "牵心集团总部",
             Description        = "牵心集团是一个虚拟的集团",
             CreatorUserId      = Guid.Empty,
             LastModifierUserId = Guid.Empty,
         }
             );
         #endregion
         #region 增加一个超级管理员用户
         context.Users.Add(
             new User
         {
             UserName           = "******",
             PassWord           = Zeje.Utils.Encrypt_.SHA256("123456"),
             TrueName           = "超级管理员",
             Sex                = null,
             Birthday           = Clock.Now,
             Phone              = "",
             Email              = "",
             IDCard             = "",
             UserStatus         = UserStatus.启用,
             LoginIp            = "",
             LoginTime          = Clock.Now,
             LoginCount         = 0,
             LoginFailedTimes   = null,
             RegisterIp         = "",
             RegisterTime       = Clock.Now,
             PasswordSetTime    = Clock.Now,
             Departments        = null,
             UserRoles          = null,
             CreatorUserId      = Guid.Empty,
             LastModifierUserId = Guid.Empty,
         }
             );
         #endregion
         #region 增加基本功能菜单
         var pagePlatform = new Page
         {
             Name               = "平台管理",
             Description        = "平台管理",
             ParentId           = Guid.Empty,
             Sort               = 0,
             Icon               = "fa fa-link",
             Url                = "",
             IsVisible          = true,
             CreatorUserId      = Guid.Empty,
             LastModifierUserId = Guid.Empty
         };
         var pageSystem = new Page
         {
             Name               = "平台管理",
             Description        = "平台管理",
             ParentId           = Guid.Empty,
             Sort               = 0,
             Icon               = "fa fa-link",
             Url                = "",
             IsVisible          = true,
             CreatorUserId      = Guid.Empty,
             LastModifierUserId = Guid.Empty
         };
         var subPage = new Page[] {
             new Page
             {
                 Name               = "组织机构管理",
                 Description        = "组织机构管理",
                 ParentId           = Guid.Empty,
                 Sort               = 0,
                 Icon               = "fa fa-link",
                 Url                = "",
                 IsVisible          = true,
                 CreatorUserId      = Guid.Empty,
                 LastModifierUserId = Guid.Empty
             },
             new Page
             {
                 Name               = "角色管理",
                 Description        = "角色管理",
                 ParentId           = Guid.Empty,
                 Sort               = 0,
                 Icon               = "fa fa-link",
                 Url                = "",
                 IsVisible          = true,
                 CreatorUserId      = Guid.Empty,
                 LastModifierUserId = Guid.Empty
             },
             new Page
             {
                 Name               = "用户管理",
                 Description        = "用户管理",
                 ParentId           = Guid.Empty,
                 Sort               = 0,
                 Icon               = "fa fa-link",
                 Url                = "",
                 IsVisible          = true,
                 CreatorUserId      = Guid.Empty,
                 LastModifierUserId = Guid.Empty
             },
             new Page
             {
                 Name               = "功能管理",
                 Description        = "功能管理",
                 ParentId           = Guid.Empty,
                 Sort               = 0,
                 Icon               = "fa fa-link",
                 Url                = "",
                 IsVisible          = true,
                 CreatorUserId      = Guid.Empty,
                 LastModifierUserId = Guid.Empty
             }
         };
         foreach (var page in subPage)
         {
             pageSystem.SubPages.Add(page);
         }
         pagePlatform.SubPages.Add(pageSystem);
         context.Pages.Add(pagePlatform);
         #endregion
         context.SaveChanges();
     }
 }