Пример #1
0
        /// <summary>
        /// Maps an EF model that inherits from ICreateAuditable into a CreateAuditData object. If the
        /// db record is null then an ArgumentNullException is thrown.
        /// </summary>
        /// <param name="model">ICreateAuditable EF database record.</param>
        public CreateAuditData MapCreateAuditData(ICreateAuditable model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            ValidateUserProperty(model.Creator, nameof(model.Creator));

            var auditData = new CreateAuditData();

            auditData.CreateDate = model.CreateDate;
            auditData.Creator    = _userMicroSummaryMapper.Map(model.Creator);

            return(auditData);
        }
        public async Task <UserMicroSummary> ExecuteAsync(GetUserMicroSummaryByEmailQuery query, IExecutionContext executionContext)
        {
            if (string.IsNullOrWhiteSpace(query.Email))
            {
                return(null);
            }

            var email = _userDataFormatter.NormalizeEmail(query.UserAreaCode, query.Email);

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

            var dbResult = await _dbContext
                           .Users
                           .AsNoTracking()
                           .FilterByUserArea(query.UserAreaCode)
                           .Where(u => u.Email == email)
                           .SingleOrDefaultAsync();

            var user = _userMicroSummaryMapper.Map(dbResult);

            return(user);
        }
Пример #3
0
        public virtual UserSummary Map(User dbUser)
        {
            if (dbUser == null)
            {
                return(null);
            }

            if (dbUser.Role == null)
            {
                throw new ArgumentException("dbUser.Role must be included in the query to map to use the UserSummaryMapper");
            }

            var user = _userMicroSummaryMapper.Map <UserSummary>(dbUser);

            user.Email          = dbUser.Email;
            user.FirstName      = dbUser.FirstName;
            user.LastName       = dbUser.LastName;
            user.Username       = dbUser.Username;
            user.LastSignInDate = dbUser.LastSignInDate;

            user.AuditData = new CreateAuditData()
            {
                CreateDate = dbUser.CreateDate
            };

            if (dbUser.Creator != null)
            {
                user.AuditData.Creator = _userMicroSummaryMapper.Map(dbUser.Creator);
            }

            var userArea = _userAreaRepository.GetRequiredByCode(dbUser.UserAreaCode);

            EntityNotFoundException.ThrowIfNull(userArea, dbUser.UserAreaCode);

            user.UserArea = new UserAreaMicroSummary()
            {
                UserAreaCode = dbUser.UserAreaCode,
                Name         = userArea.Name
            };

            user.Role = _roleMicroSummaryMapper.Map(dbUser.Role);

            return(user);
        }
Пример #4
0
        public async Task <UserMicroSummary> ExecuteAsync(GetUserMicroSummaryByIdQuery query, IExecutionContext executionContext)
        {
            var dbResult = await Query(query).SingleOrDefaultAsync();

            var user = _userMicroSummaryMapper.Map(dbResult);

            ValidatePermission(query, executionContext, user);

            return(user);
        }
        public async Task <UserMicroSummary> ExecuteAsync(GetUserMicroSummaryByEmailQuery query, IExecutionContext executionContext)
        {
            if (string.IsNullOrWhiteSpace(query.Email))
            {
                return(null);
            }

            var dbResult = await Query(query).SingleOrDefaultAsync();

            var user = _userMicroSummaryMapper.Map(dbResult);

            return(user);
        }
Пример #6
0
        public virtual UserDetails Map(User dbUser)
        {
            if (dbUser == null)
            {
                return(null);
            }

            if (dbUser.Role == null)
            {
                throw new ArgumentException("dbUser.Role must be included in the query to map to use the UserDetailsMapper");
            }

            var user = _userMicroSummaryMapper.Map <UserDetails>(dbUser);

            user.Email                  = dbUser.Email;
            user.FirstName              = dbUser.FirstName;
            user.LastName               = dbUser.LastName;
            user.Username               = dbUser.Username;
            user.LastSignInDate         = dbUser.LastSignInDate;
            user.LastPasswordChangeDate = dbUser.LastPasswordChangeDate;
            user.RequirePasswordChange  = dbUser.RequirePasswordChange;
            user.AccountVerifiedDate    = dbUser.AccountVerifiedDate;

            user.AuditData = new CreateAuditData()
            {
                CreateDate = dbUser.CreateDate
            };

            if (dbUser.Creator != null)
            {
                user.AuditData.Creator = _userMicroSummaryMapper.Map(dbUser.Creator);
            }

            user.Role = _roleDetailsMapper.Map(dbUser.Role);

            return(user);
        }
        /// <summary>
        /// Maps an EF user record from the db into a UserDetails object. If the
        /// db record is null then null is returned.
        /// </summary>
        /// <param name="dbUser">User record from the database.</param>
        public UserDetails Map(User dbUser)
        {
            if (dbUser == null)
            {
                return(null);
            }

            if (dbUser.Role == null)
            {
                throw new ArgumentException("dbUser.Role must be included in the query to map to use the UserDetailsMapper");
            }

            var user = new UserDetails()
            {
                Email                  = dbUser.Email,
                FirstName              = dbUser.FirstName,
                LastName               = dbUser.LastName,
                UserId                 = dbUser.UserId,
                Username               = dbUser.Username,
                LastLoginDate          = DbDateTimeMapper.AsUtc(dbUser.LastLoginDate),
                LastPasswordChangeDate = DbDateTimeMapper.AsUtc(dbUser.LastPasswordChangeDate),
                RequirePasswordChange  = dbUser.RequirePasswordChange
            };

            user.AuditData = new CreateAuditData()
            {
                CreateDate = DbDateTimeMapper.AsUtc(dbUser.CreateDate)
            };

            if (dbUser.Creator != null)
            {
                user.AuditData.Creator = _userMicroSummaryMapper.Map(dbUser.Creator);
            }

            var userArea = _userAreaRepository.GetByCode(dbUser.UserAreaCode);

            EntityNotFoundException.ThrowIfNull(userArea, dbUser.UserAreaCode);

            user.UserArea = new UserAreaMicroSummary()
            {
                UserAreaCode = dbUser.UserAreaCode,
                Name         = userArea.Name
            };

            user.Role = _roleDetailsMapper.Map(dbUser.Role);

            return(user);
        }
Пример #8
0
        /// <summary>
        /// Maps an EF user record from the db into a UserAccountDetails object. If the
        /// db record is null then null is returned.
        /// </summary>
        /// <param name="dbUser">User record from the database.</param>
        public UserAccountDetails Map(User dbUser)
        {
            if (dbUser == null)
            {
                return(null);
            }

            var user = new UserAccountDetails()
            {
                Email                  = dbUser.Email,
                FirstName              = dbUser.FirstName,
                LastName               = dbUser.LastName,
                UserId                 = dbUser.UserId,
                Username               = dbUser.Username,
                LastLoginDate          = dbUser.LastLoginDate,
                LastPasswordChangeDate = dbUser.LastPasswordChangeDate,
                PreviousLoginDate      = dbUser.PreviousLoginDate,
                RequirePasswordChange  = dbUser.RequirePasswordChange
            };

            user.AuditData = new CreateAuditData()
            {
                CreateDate = dbUser.CreateDate
            };

            if (dbUser.Creator != null)
            {
                user.AuditData.Creator = _userMicroSummaryMapper.Map(dbUser.Creator);
            }

            var userArea = _userAreaRepository.GetByCode(dbUser.UserAreaCode);

            EntityNotFoundException.ThrowIfNull(userArea, dbUser.UserAreaCode);

            user.UserArea = new UserAreaMicroSummary()
            {
                UserAreaCode = dbUser.UserAreaCode,
                Name         = userArea.Name
            };

            return(user);
        }