Ejemplo n.º 1
0
        public async Task <IActionResult> PostCommandToFunction(string functionId, string commandId)
        {
            var commandInFunction = await _context.CommandInFunctions.FindAsync(functionId, commandId);

            if (commandInFunction == null)
            {
                return(BadRequest($"This command is not existed in function"));
            }

            var entity = new CommandInFunction()
            {
                CommandId  = commandId,
                FunctionId = functionId
            };

            _context.CommandInFunctions.Remove(entity);
            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostCommandToFunction(string functionId, [FromBody] AddCommandToFunctionRequest request)
        {
            var commandInFunction = await _context.CommandInFunctions.FindAsync(request.CommandId, request.FunctionId);

            if (commandInFunction != null)
            {
                return(BadRequest($"This command has been added to function"));
            }

            var entity = new CommandInFunction()
            {
                CommandId  = request.CommandId,
                FunctionId = request.FunctionId
            };

            _context.CommandInFunctions.Add(entity);
            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                return(CreatedAtAction(nameof(GetById), new { commandId = request.CommandId, functionId = request.FunctionId }, request));
            }
            else
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PostCommandToFunction(string functionId, [FromBody] CommandAssignRequest request)
        {
            //var commandInFunction = await _context.CommandInFunctions.FindAsync(request.CommandId, request.FunctionId);
            //if (commandInFunction != null)
            //    return BadRequest(new ApiBadRequestResponse($"This command has been added to function"));

            //var entity = new CommandInFunction()
            //{
            //    CommandId = request.CommandId,
            //    FunctionId = request.FunctionId
            //};
            foreach (var commandId in request.CommandIds)
            {
                if (await _context.CommandInFunctions.FindAsync(commandId, functionId) != null)
                {
                    return(BadRequest(new ApiBadRequestResponse("This command is not existed in function")));
                }
                var entity = new CommandInFunction()
                {
                    CommandId  = commandId,
                    FunctionId = functionId
                };

                _context.CommandInFunctions.Add(entity);
            }
            if (request.AddToAllFunctions)
            {
                var ortherFunction = _context.Functions.Where(x => x.Id != functionId);
                foreach (var function in ortherFunction)
                {
                    foreach (var commandId in request.CommandIds)
                    {
                        if (await _context.CommandInFunctions.FindAsync(commandId, functionId) == null)
                        {
                            _context.CommandInFunctions.Add(new CommandInFunction()
                            {
                                CommandId  = commandId,
                                FunctionId = function.Id
                            });
                        }
                    }
                }
            }
            var result = await _context.SaveChangesAsync();

            //_context.CommandInFunctions.Add(entity);

            if (result > 0)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(new ApiBadRequestResponse("Add command to function failed")));
            }
        }
        public async Task <IActionResult> PostCommandToFunction(string functionId, [FromBody] CommandAssignRequest request)
        {
            //// ADD EACH COMMAND TO FUNCTION
            foreach (var commandId in request.CommandIds)
            {
                //// IF EXIST COMAND IN THIS FUNCTION, RETURN STATSU 400
                if (await _context.CommandInFunctions.FindAsync(commandId, functionId) != null)
                {
                    return(BadRequest(new ApiBadRequestResponse("This command has been existed in function")));
                }

                //// ADD NEW COMMAND TO THIS FUNCTION
                var entity = new CommandInFunction()
                {
                    CommandId  = commandId,
                    FunctionId = functionId
                };

                _context.CommandInFunctions.Add(entity);
            }

            //// IF WANT ADD COMMAND FOR ALL FUNCTIONS
            if (request.AddToAllFunctions)
            {
                var otherFunctions = _context.Functions.Where(x => x.Id != functionId);
                foreach (var function in otherFunctions)
                {
                    foreach (var commandId in request.CommandIds)
                    {
                        if (await _context.CommandInFunctions.FindAsync(request.CommandIds, function.Id) == null)
                        {
                            _context.CommandInFunctions.Add(new CommandInFunction()
                            {
                                CommandId  = commandId,
                                FunctionId = function.Id
                            });
                        }
                    }
                }
            }

            //// ADD COMMANDS AND SAVE CHANGES
            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                return(CreatedAtAction(nameof(GetById), new { request.CommandIds, functionId }));
            }
            else
            {
                return(BadRequest(new ApiBadRequestResponse("Add command to function failed")));
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PostCommandToFunction(string functionId, [FromBody] CommandAssignRequest request)
        {
            foreach (var commandId in request.CommandIds)
            {
                if (await _context.CommandInFunctions.FindAsync(commandId, functionId) != null)
                {
                    return(BadRequest(new ApiBadRequestResponse("This command has been existed in function")));
                }

                var entity = new CommandInFunction()
                {
                    CommandId  = commandId,
                    FunctionId = functionId
                };

                _context.CommandInFunctions.Add(entity);
            }

            if (request.AddToAllFunctions)
            {
                var otherFunctions = _context.Functions.Where(x => x.Id != functionId);
                foreach (var function in otherFunctions)
                {
                    foreach (var commandId in request.CommandIds)
                    {
                        if (await _context.CommandInFunctions.FindAsync(request.CommandIds, function.Id) == null)
                        {
                            _context.CommandInFunctions.Add(new CommandInFunction()
                            {
                                CommandId  = commandId,
                                FunctionId = function.Id
                            });
                        }
                    }
                }
            }
            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                return(CreatedAtAction(nameof(GetById), new { request.CommandIds, functionId }));
            }
            else
            {
                return(BadRequest(new ApiBadRequestResponse("Add command to function failed")));
            }
        }
Ejemplo n.º 6
0
        public async Task Seed()
        {
            #region Quyền

            if (!_roleManager.Roles.Any())
            {
                await _roleManager.CreateAsync(new IdentityRole
                {
                    Id             = AdminRoleName,
                    Name           = AdminRoleName,
                    NormalizedName = AdminRoleName.ToUpper(),
                });

                await _roleManager.CreateAsync(new IdentityRole
                {
                    Id             = UserRoleName,
                    Name           = UserRoleName,
                    NormalizedName = UserRoleName.ToUpper(),
                });
            }

            #endregion Quyền


            #region Người dùng

            if (!_userManager.Users.Any())
            {
                var result = await _userManager.CreateAsync(new User
                {
                    Id             = Guid.NewGuid().ToString(),
                    UserName       = "******",
                    FirstName      = "Quản trị",
                    LastName       = "1",
                    Email          = "*****@*****.**",
                    LockoutEnabled = false
                }, "Admin@123");

                if (result.Succeeded)
                {
                    var user = await _userManager.FindByNameAsync("admin");

                    await _userManager.AddToRoleAsync(user, AdminRoleName);
                }
            }

            #endregion Người dùng

            #region Chức năng

            if (!_context.Functions.Any())
            {
                _context.Functions.AddRange(new List <Function>
                {
                    new Function {
                        Id = "DASHBOARD", Name = "Thống kê", ParentId = null, SortOrder = 1, Url = "/dashboard"
                    },

                    new Function {
                        Id = "CONTENT", Name = "Nội dung", ParentId = null, Url = "/content"
                    },

                    new Function {
                        Id = "CONTENT_CATEGORY", Name = "Danh mục", ParentId = "CONTENT", Url = "/content/category"
                    },
                    new Function {
                        Id = "CONTENT_KNOWLEDGEBASE", Name = "Bài viết", ParentId = "CONTENT", SortOrder = 2, Url = "/content/kb"
                    },
                    new Function {
                        Id = "CONTENT_COMMENT", Name = "Trang", ParentId = "CONTENT", SortOrder = 3, Url = "/content/comment"
                    },
                    new Function {
                        Id = "CONTENT_REPORT", Name = "Báo xấu", ParentId = "CONTENT", SortOrder = 3, Url = "/content/report"
                    },

                    new Function {
                        Id = "STATISTIC", Name = "Thống kê", ParentId = null, Url = "/statistic"
                    },

                    new Function {
                        Id = "STATISTIC_MONTHLY_NEWMEMBER", Name = "Đăng ký từng tháng", ParentId = "STATISTIC", SortOrder = 1, Url = "/statistic/monthly-register"
                    },
                    new Function {
                        Id = "STATISTIC_MONTHLY_NEWKB", Name = "Bài đăng hàng tháng", ParentId = "STATISTIC", SortOrder = 2, Url = "/statistic/monthly-newkb"
                    },
                    new Function {
                        Id = "STATISTIC_MONTHLY_COMMENT", Name = "Comment theo tháng", ParentId = "STATISTIC", SortOrder = 3, Url = "/statistic/monthly-comment"
                    },

                    new Function {
                        Id = "SYSTEM", Name = "Hệ thống", ParentId = null, Url = "/system"
                    },

                    new Function {
                        Id = "SYSTEM_USER", Name = "Người dùng", ParentId = "SYSTEM", Url = "/system/user"
                    },
                    new Function {
                        Id = "SYSTEM_ROLE", Name = "Nhóm quyền", ParentId = "SYSTEM", Url = "/system/role"
                    },
                    new Function {
                        Id = "SYSTEM_FUNCTION", Name = "Chức năng", ParentId = "SYSTEM", Url = "/system/function"
                    },
                    new Function {
                        Id = "SYSTEM_PERMISSION", Name = "Quyền hạn", ParentId = "SYSTEM", Url = "/system/permission"
                    },
                });
                await _context.SaveChangesAsync();
            }

            if (!_context.Commands.Any())
            {
                _context.Commands.AddRange(new List <Command>()
                {
                    new Command()
                    {
                        Id = "VIEW", Name = "Xem"
                    },
                    new Command()
                    {
                        Id = "CREATE", Name = "Thêm"
                    },
                    new Command()
                    {
                        Id = "UPDATE", Name = "Sửa"
                    },
                    new Command()
                    {
                        Id = "DELETE", Name = "Xoá"
                    },
                    new Command()
                    {
                        Id = "APPROVE", Name = "Duyệt"
                    },
                });
            }

            #endregion Chức năng
            var functions = _context.Functions;

            if (!_context.CommandInFunctions.Any())
            {
                foreach (var function in functions)
                {
                    var createAction = new CommandInFunction()
                    {
                        CommandId  = "CREATE",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(createAction);

                    var updateAction = new CommandInFunction()
                    {
                        CommandId  = "UPDATE",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(updateAction);
                    var deleteAction = new CommandInFunction()
                    {
                        CommandId  = "DELETE",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(deleteAction);

                    var viewAction = new CommandInFunction()
                    {
                        CommandId  = "VIEW",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(viewAction);
                }
            }

            if (!_context.Permissions.Any())
            {
                var adminRole = await _roleManager.FindByNameAsync(AdminRoleName);

                foreach (var function in functions)
                {
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "CREATE"));
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "UPDATE"));
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "DELETE"));
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "VIEW"));
                }
            }

            await _context.SaveChangesAsync();
        }
        public CommandInFunctionControllerTest()
        {
            _context = new InMemoryDbContextFactory().GetApplicationDbContext();

            _context.Functions.AddRange(new List <Function>()
            {
                new Function()
                {
                    Id        = "GetFunctionsPaging_NoFilter_ReturnSuccess1",
                    ParentId  = null,
                    Name      = "GetFunctionsPaging_NoFilter_ReturnSuccess1",
                    SortOrder = 1,
                    Url       = "/test1"
                },
                new Function()
                {
                    Id        = "GetFunctionsPaging_NoFilter_ReturnSuccess2",
                    ParentId  = null,
                    Name      = "GetFunctionsPaging_NoFilter_ReturnSuccess2",
                    SortOrder = 2,
                    Url       = "/test2"
                },
                new Function()
                {
                    Id        = "GetFunctionsPaging_NoFilter_ReturnSuccess3",
                    ParentId  = null,
                    Name      = "GetFunctionsPaging_NoFilter_ReturnSuccess3",
                    SortOrder = 3,
                    Url       = "/test3"
                },
                new Function()
                {
                    Id        = "GetFunctionsPaging_NoFilter_ReturnSuccess4",
                    ParentId  = null,
                    Name      = "GetFunctionsPaging_NoFilter_ReturnSuccess4",
                    SortOrder = 4,
                    Url       = "/test4"
                }
            });
            _context.SaveChangesAsync();

            _context.Commands.AddRange(new List <Command>()
            {
                new Command()
                {
                    Id = "TEST1", Name = "Xem"
                },
                new Command()
                {
                    Id = "TEST2", Name = "Thêm"
                },
                new Command()
                {
                    Id = "TEST3", Name = "Sửa"
                },
                new Command()
                {
                    Id = "TEST4", Name = "Xoá"
                },
                new Command()
                {
                    Id = "TEST5", Name = "Duyệt"
                },
            });

            var functions = _context.Functions;

            if (!_context.CommandInFunctions.Any())
            {
                foreach (var function in functions)
                {
                    var createAction = new CommandInFunction()
                    {
                        CommandId  = "TEST2",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(createAction);

                    var updateAction = new CommandInFunction()
                    {
                        CommandId  = "TEST3",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(updateAction);
                    var deleteAction = new CommandInFunction()
                    {
                        CommandId  = "TEST4",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(deleteAction);

                    var viewAction = new CommandInFunction()
                    {
                        CommandId  = "TEST1",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(viewAction);
                }
            }

            _context.SaveChangesAsync();
        }
Ejemplo n.º 8
0
        public async Task Seed()
        {
            #region Quyền

            if (!_roleManager.Roles.Any())
            {
                await _roleManager.CreateAsync(new AppRole
                {
                    Id             = AdminRoleName,
                    Name           = AdminRoleName,
                    NormalizedName = AdminRoleName.ToUpper(),
                });

                await _roleManager.CreateAsync(new AppRole
                {
                    Id             = UserRoleName,
                    Name           = UserRoleName,
                    NormalizedName = UserRoleName.ToUpper(),
                });
            }

            #endregion Quyền

            #region Người dùng

            if (!_userManager.Users.Any())
            {
                var result = await _userManager.CreateAsync(new User
                {
                    Id             = Guid.NewGuid().ToString(),
                    UserName       = "******",
                    FirstName      = "Quản trị",
                    LastName       = "Web",
                    FullName       = "Nguyễn Sỹ Khánh",
                    Email          = "*****@*****.**",
                    LockoutEnabled = false
                }, "Admin@123");

                if (result.Succeeded)
                {
                    var user = await _userManager.FindByNameAsync("admin");

                    await _userManager.AddToRoleAsync(user, AdminRoleName);
                }
            }

            #endregion Người dùng

            #region Ngôn ngữ

            if (!_context.Languages.Any())
            {
                _context.Languages.AddRange(new List <Language>
                {
                    new Language
                    {
                        Id = "en", Name = "English", IsDefault = false, SortOrder = 1, Status = Status.Active
                    },
                    new Language {
                        Id = "vi", Name = "Việt Nam", IsDefault = true, SortOrder = 2, Status = Status.Active
                    }
                });
                await _context.SaveChangesAsync();
            }


            #endregion


            #region Chức năng

            if (!_context.Functions.Any())
            {
                _context.Functions.AddRange(new List <Function>
                {
                    new Function {
                        Id = "DASHBOARD", ParentId = null, NameTemp = "Thống kê", SortOrder = 1, Url = "/dashboard"
                    },

                    new Function {
                        Id = "PRODUCT", ParentId = null, NameTemp = "Sản phẩm", Url = "/products"
                    },

                    new Function {
                        Id = "CATEGORY", ParentId = null, NameTemp = "Thể loại", Url = "/categories"
                    },

                    new Function {
                        Id = "BILL", ParentId = null, NameTemp = "Hóa đơn", Url = "/bills"
                    },

                    new Function {
                        Id = "SYSTEM", ParentId = null, NameTemp = "Hệ thống", Url = "/systems"
                    },

                    new Function {
                        Id = "SYSTEM_USER", ParentId = "SYSTEM", NameTemp = "Người dùng", Url = "/systems/users"
                    },
                    new Function {
                        Id = "SYSTEM_ROLE", ParentId = "SYSTEM", NameTemp = "Nhóm Quyền", Url = "/systems/roles"
                    },
                    new Function {
                        Id = "SYSTEM_FUNCTION", ParentId = "SYSTEM", NameTemp = "Chức năng", Url = "/systems/functions"
                    },
                    new Function {
                        Id = "SYSTEM_PERMISSION", ParentId = "SYSTEM", NameTemp = "Quyền hạn", Url = "/systems/permissions"
                    }
                });
                await _context.SaveChangesAsync();
            }

            if (!_context.Commands.Any())
            {
                _context.Commands.AddRange(new List <Command>
                {
                    new Command()
                    {
                        Id = "VIEW", Name = "Xem"
                    },
                    new Command()
                    {
                        Id = "CREATE", Name = "Thêm"
                    },
                    new Command()
                    {
                        Id = "UPDATE", Name = "Sửa"
                    },
                    new Command()
                    {
                        Id = "DELETE", Name = "Xoá"
                    },
                    new Command()
                    {
                        Id = "APPROVE", Name = "Duyệt"
                    },
                });
            }

            #endregion Chức năng

            #region Tên chức năng

            if (!_context.FunctionTranslations.Any())
            {
                _context.FunctionTranslations.AddRange(new List <FunctionTranslation>
                {
                    new FunctionTranslation {
                        FunctionId = "DASHBOARD", LanguageId = "en", Name = "Dashboard", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "DASHBOARD", LanguageId = "vi", Name = "Bảng tin", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "PRODUCT", LanguageId = "en", Name = "Products", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "PRODUCT", LanguageId = "vi", Name = "Sản phẩm", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "CATEGORY", LanguageId = "en", Name = "Categories", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "CATEGORY", LanguageId = "vi", Name = "Loại hàng", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "BILL", LanguageId = "en", Name = "Orders", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "BILL", LanguageId = "vi", Name = "Đơn hàng", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "SYSTEM", LanguageId = "en", Name = "Systems", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "SYSTEM", LanguageId = "vi", Name = "Hệ thống", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "SYSTEM_USER", LanguageId = "en", Name = "Users", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "SYSTEM_USER", LanguageId = "vi", Name = "Người dùng", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "SYSTEM_ROLE", LanguageId = "en", Name = "Roles", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "SYSTEM_ROLE", LanguageId = "vi", Name = "Nhóm quyền", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "SYSTEM_FUNCTION", LanguageId = "en", Name = "Functions", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "SYSTEM_FUNCTION", LanguageId = "vi", Name = "Chức năng", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "SYSTEM_PERMISSION", LanguageId = "en", Name = "Permissions", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    },
                    new FunctionTranslation {
                        FunctionId = "SYSTEM_PERMISSION", LanguageId = "vi", Name = "Quyền hạn", CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now
                    }
                });
                await _context.SaveChangesAsync();
            }

            #endregion

            var functions = _context.Functions;

            if (!_context.CommandInFunctions.Any())
            {
                foreach (var function in functions)
                {
                    var createAction = new CommandInFunction()
                    {
                        CommandId  = "CREATE",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(createAction);

                    var updateAction = new CommandInFunction()
                    {
                        CommandId  = "UPDATE",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(updateAction);
                    var deleteAction = new CommandInFunction()
                    {
                        CommandId  = "DELETE",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(deleteAction);

                    var viewAction = new CommandInFunction()
                    {
                        CommandId  = "VIEW",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(viewAction);
                }
            }

            if (!_context.Permissions.Any())
            {
                var adminRole = await _roleManager.FindByNameAsync(AdminRoleName);

                foreach (var function in functions)
                {
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "CREATE"));
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "UPDATE"));
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "DELETE"));
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "VIEW"));
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "APPROVE"));
                }
            }
            await _context.SaveChangesAsync();
        }
Ejemplo n.º 9
0
        public async Task Seed()
        {
            #region Role

            if (!_roleManager.Roles.Any())
            {
                await _roleManager.CreateAsync(new IdentityRole
                {
                    Id             = AdminRoleName,
                    Name           = AdminRoleName,
                    NormalizedName = AdminRoleName.ToUpper(),
                });

                await _roleManager.CreateAsync(new IdentityRole
                {
                    Id             = UserRoleName,
                    Name           = UserRoleName,
                    NormalizedName = UserRoleName.ToUpper(),
                });
            }

            #endregion Quyền

            #region User

            if (!_userManager.Users.Any())
            {
                var result = await _userManager.CreateAsync(new User
                {
                    Id             = Guid.NewGuid().ToString(),
                    UserName       = "******",
                    FirstName      = "Admin",
                    LastName       = "1",
                    Email          = "*****@*****.**",
                    LockoutEnabled = false
                }, "Admin@123");

                if (result.Succeeded)
                {
                    var user = await _userManager.FindByNameAsync("admin");

                    await _userManager.AddToRoleAsync(user, AdminRoleName);
                }
            }

            #endregion User

            #region Function

            if (!_context.Functions.Any())
            {
                _context.Functions.AddRange(new List <Function>
                {
                    new Function {
                        Id = "DASHBOARD", Name = "Statistical", ParentId = null, SortOrder = 1, Url = "/dashboard"
                    },

                    new Function {
                        Id = "CONTENT", Name = "Content", ParentId = null, Url = "/content"
                    },

                    new Function {
                        Id = "CONTENT_CATEGORY", Name = "Category", ParentId = "CONTENT", Url = "/content/category"
                    },
                    new Function {
                        Id = "CONTENT_KNOWLEDGEBASE", Name = "Posts", ParentId = "CONTENT", SortOrder = 2, Url = "/content/kb"
                    },
                    new Function {
                        Id = "CONTENT_COMMENT", Name = "Page", ParentId = "CONTENT", SortOrder = 3, Url = "/content/comment"
                    },
                    new Function {
                        Id = "CONTENT_REPORT", Name = "Bad newspaper", ParentId = "CONTENT", SortOrder = 3, Url = "/content/report"
                    },

                    new Function {
                        Id = "STATISTIC", Name = "Statistical", ParentId = null, Url = "/statistic"
                    },

                    new Function {
                        Id = "STATISTIC_MONTHLY_NEWMEMBER", Name = "Sign up every month", ParentId = "STATISTIC", SortOrder = 1, Url = "/statistic/monthly-register"
                    },
                    new Function {
                        Id = "STATISTIC_MONTHLY_NEWKB", Name = "Monthly post", ParentId = "STATISTIC", SortOrder = 2, Url = "/statistic/monthly-newkb"
                    },
                    new Function {
                        Id = "STATISTIC_MONTHLY_COMMENT", Name = "Comment by month", ParentId = "STATISTIC", SortOrder = 3, Url = "/statistic/monthly-comment"
                    },

                    new Function {
                        Id = "SYSTEM", Name = "System", ParentId = null, Url = "/system"
                    },

                    new Function {
                        Id = "SYSTEM_USER", Name = "User", ParentId = "SYSTEM", Url = "/system/user"
                    },
                    new Function {
                        Id = "SYSTEM_ROLE", Name = "Role group", ParentId = "SYSTEM", Url = "/system/role"
                    },
                    new Function {
                        Id = "SYSTEM_FUNCTION", Name = "Function", ParentId = "SYSTEM", Url = "/system/function"
                    },
                    new Function {
                        Id = "SYSTEM_PERMISSION", Name = "Permission group", ParentId = "SYSTEM", Url = "/system/permission"
                    },
                });
                await _context.SaveChangesAsync();
            }

            if (!_context.Commands.Any())
            {
                _context.Commands.AddRange(new List <Command>()
                {
                    new Command()
                    {
                        Id = "VIEW", Name = "View"
                    },
                    new Command()
                    {
                        Id = "CREATE", Name = "Create"
                    },
                    new Command()
                    {
                        Id = "UPDATE", Name = "Update"
                    },
                    new Command()
                    {
                        Id = "DELETE", Name = "Delete"
                    },
                    new Command()
                    {
                        Id = "APPROVE", Name = "Approve"
                    },
                });
            }

            #endregion Function

            var functions = _context.Functions;

            if (!_context.CommandInFunctions.Any())
            {
                foreach (var function in functions)
                {
                    var createAction = new CommandInFunction()
                    {
                        CommandId  = "CREATE",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(createAction);

                    var updateAction = new CommandInFunction()
                    {
                        CommandId  = "UPDATE",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(updateAction);
                    var deleteAction = new CommandInFunction()
                    {
                        CommandId  = "DELETE",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(deleteAction);

                    var viewAction = new CommandInFunction()
                    {
                        CommandId  = "VIEW",
                        FunctionId = function.Id
                    };
                    _context.CommandInFunctions.Add(viewAction);
                }
            }

            if (!_context.Permissions.Any())
            {
                var adminRole = await _roleManager.FindByNameAsync(AdminRoleName);

                foreach (var function in functions)
                {
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "CREATE"));
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "UPDATE"));
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "DELETE"));
                    _context.Permissions.Add(new Permission(function.Id, adminRole.Id, "VIEW"));
                }
            }

            await _context.SaveChangesAsync();
        }