コード例 #1
0
        public void Map_UserGroupSave_To_IUserGroup()
        {
            var userModelMapper = new UserModelMapper();

            Mapper.Initialize(configuration => userModelMapper.ConfigureMappings(configuration, ApplicationContext.Current));

            var        userService = ApplicationContext.Services.UserService;
            IUserGroup userGroup   = new UserGroup(0, "alias", "name", new List <string> {
                "c"
            }, "icon");

            userService.Save(userGroup);

            // userGroup.permissions is System.Collections.Generic.List`1[System.String]

            userGroup = userService.GetUserGroupById(userGroup.Id);

            // userGroup.permissions is System.Linq.Enumerable+WhereSelectArrayIterator`2[System.Char, System.String]
            // fixed: now System.Collections.Generic.List`1[System.String]

            const string json          = "{\"id\":@@@ID@@@,\"alias\":\"perm1\",\"name\":\"Perm1\",\"icon\":\"icon-users\",\"sections\":[\"content\"],\"users\":[],\"defaultPermissions\":[\"F\",\"C\",\"A\"],\"assignedPermissions\":{},\"startContentId\":-1,\"startMediaId\":-1,\"action\":\"save\",\"parentId\":-1}";
            var          userGroupSave = JsonConvert.DeserializeObject <UserGroupSave>(json.Replace("@@@ID@@@", userGroup.Id.ToString()));

            // failed, AutoMapper complained, "Unable to cast object of type 'WhereSelectArrayIterator`2[System.Char,System.String]' to type 'System.Collections.IList'".
            // fixmed: added ToList() in UserGroupFactory
            Mapper.Map(userGroupSave, userGroup);
        }
コード例 #2
0
        public UserDbModel Login(UserDbModel dbModel)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                var login = (from user in db.SEC_USER
                             where user.EMAIL.ToUpper().Equals(dbModel.Email.ToUpper()) && user.USER_PASSWORD.Equals(dbModel.Password)
                             select user).FirstOrDefault();

                if (login == null)
                {
                    return(null);
                }

                var         date    = dbModel.CurrentDate;
                SEC_SESSION session = new SEC_SESSION()
                {
                    USERID       = login.ID,
                    LOGIN_DATE   = date,
                    TOKEN_STATUS = true,
                    TOKEN        = this.GetToken(String.Concat(login.ID, date)),
                    IP_ADDRESS   = this.GetIpAddress()
                };

                db.SEC_SESSION.Add(session);
                db.SaveChanges();
                UserModelMapper mapper = new UserModelMapper();
                return(mapper.MapperT1T2(login));
            }
        }
コード例 #3
0
        public async Task <UserDto> GetOneUserAsync(string id)
        {
            _logger.LogMessage("Retrieved a user from db.");
            UserDb userdb = await _dbmanager.GetUserAsync(id);

            UserDto userdto = UserModelMapper.UserDbToDtoModel(userdb);

            return(userdto);
        }
コード例 #4
0
        public async Task UpdateExistingUserAsync(string id, string person)
        {
            var userDto = _parsingManager.ParseData(person);

            UserDb userdb = UserModelMapper.UserDtoToDbModel(userDto);

            await _dbmanager.UpdateUserAsync(id, userdb);

            _logger.LogMessage("Updated a user in db.");
        }
コード例 #5
0
        public async Task SaveNewPersonAsync(string person)
        {
            var userDto = _parsingManager.ParseData(incomingData: person);

            UserDb userdb = UserModelMapper.UserDtoToDbModel(userDto);

            await _dbmanager.InsertUserAsync(userdb);

            _logger.LogMessage("Saved a user to db."); // if this is not here, the test should fail
        }
コード例 #6
0
        public static async Task <DbUserModel> GetUserFromGuid(string guid)
        {
            UserModelMapper user = (await MongoConnector.GetUserCollection()
                                    .FindAsync(it => it.Id == guid))
                                   .FirstOrDefault();

            if (user == null)
            {
                return(null);
            }
            return(new DbUserModel(user.ToProto()));
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public IEnumerable <UserDbModel> RecordList(string filter)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                var lista = from role in db.SEC_USER
                            where !role.REMOVED && role.NAME.ToUpper().Contains(filter.ToUpper())
                            select role;

                UserModelMapper mapper     = new UserModelMapper();
                var             listaFinal = mapper.MapperT1T2(lista);

                return(listaFinal);
            }
        }
コード例 #8
0
        /// <summary>
        /// Se agrega un nuevo registro a los roles
        /// </summary>
        /// <param name="dbModel">Representa un objeto con la información del rol</param>
        /// <returns>entero con la respuesta: 1. OK, 2. KO, 3. Ya existe</returns>
        public int RecordCreation(UserDbModel dbModel)
        {
            using (DesarrolloDocenteBDEntities db = new DesarrolloDocenteBDEntities())
            {
                try
                {
                    UserModelMapper mapper = new UserModelMapper();
                    SEC_USER        record = mapper.MapperT2T1(dbModel);
                    record.CREATE_DATE    = dbModel.CurrentDate;
                    record.CREATE_USER_ID = dbModel.UserInSessionId;

                    db.SEC_USER.Add(record);
                    db.SaveChanges();
                    return(1);
                }
                catch
                {
                    return(2);
                }
            }
        }