Ejemplo n.º 1
0
        public void initAdminClient()
        {
            ClientDao    dao  = new ClientDao();
            ClientEntity temp = dao.getClientByUsername("admin");

            if (temp != null)
            {
                dao.DeleteClient("admin");
            }


            ClientEntity  client        = new ClientEntity();
            RoleDao       roleDao       = new RoleDao();
            DepartmentDao departmentDao = new DepartmentDao();

            client.Username = "******";
            client.Password = "******";
            client.RealName = "yangtf";

            client.Role       = roleDao.getByName("superadmin");
            client.Department = departmentDao.getByName("6");
            client.encryptPassword();

            IList <CatalogEntity> catalogs = new CatalogDao().getAll();

            client.Catalogs = catalogs;


            dao.save(client);
        }
Ejemplo n.º 2
0
        public ActionResult Create(Role role)
        {
            if (ModelState.IsValid)
            {
                var dao     = new RoleDao();
                var getRole = dao.getByName(role.Name);

                //Check if new role exsits
                if (getRole != null)
                {
                    ModelState.AddModelError("Name", "Role " + role.Name + " exists in database.");
                    return(View(role));
                }

                var entity = new Role();
                entity.Id          = Guid.NewGuid();
                entity.Name        = role.Name;
                entity.Description = role.Description;
                Guid id = dao.create(entity);
                if (id != null)
                {
                    ViewBag.CreateRoleSuccessMessage = "Create " + role.Name + " successful";
                }
                else
                {
                    ViewBag.CreateRoleErrorMessage = "Create " + role.Name + " failed";
                }
            }
            return(View(role));
        }
Ejemplo n.º 3
0
 public RoleEntity GetRoleByName(string name)
 {
     return(roleDao.getByName(name));
 }