コード例 #1
0
        public User CreateANCRUser(User user)
        {
            CriticalResultsEntityManager manager = new CriticalResultsEntityManager();
            UserEntity userEntity = manager.CreateUserEntity(user.ToEntity());

            AuditEvent("CreateUser:Success", user.UserName);

            LevelEntity[] levels = manager.GetLevels();
            List<string> levelNames = new List<string>();
            foreach (LevelEntity level in levels)
            {
                levelNames.Add(level.Name);
            }

            TransportEntity[] transports = manager.GetAllTransports();
            foreach (TransportEntity transport in transports)
            {
                bool addTransport = true;
                foreach (UserTransportEntity userTransport in userEntity.UserTransports)
                {
                    if (userTransport.Transport.Name == transport.Name)
                    {
                        addTransport = false;
                    }
                }
                if (addTransport)
                {
                    if (user.Transports != null)
                    {
                        bool transportFound = false;
                        for (int i = 0; i < user.Transports.Length; i++)
                        {
                            if (user.Transports[i].Transport.Name == transport.Name)
                            {
                                if (user.Transports[i].Address == null)
                                {
                                    user.Transports[i].Address = "";
                                }
                                manager.CreateUserTransport(userEntity.UserName, transport.Name, user.Transports[i].Address);
                                manager.UpdateLevelsToUserTransport(user.UserName, transport.Name, user.Transports[i].Address, levelNames.ToArray());
                                transportFound = true;

                            }
                        }
                        if (!transportFound)
                        {
                            manager.CreateUserTransport(userEntity.UserName, transport.Name, "");
                            manager.UpdateLevelsToUserTransport(user.UserName, transport.Name, "", levelNames.ToArray());
                        }
                    }
                    else
                    {
                        manager.CreateUserTransport(userEntity.UserName, transport.Name, "");
                        manager.UpdateLevelsToUserTransport(user.UserName, transport.Name, "", levelNames.ToArray());
                    }
                }
            }

            userEntity = manager.GetUser(user.UserName);

            //bool passwordFound = false;
            //foreach (UserEntryEntity uee in e.UserEntries)
            //{
            //    if (uee.Type == "AuthExt" && uee.Key == "ANCR")
            //        passwordFound = true;
            //}
            //if(!passwordFound)
            //    GeneratePassword(user.UserName);

            User u = new User(userEntity);
            u.ResolveRoles();
            u.ResolveTransports();
            u.ResolveEntries();
            return u;
        }