Ejemplo n.º 1
0
        public async Task <UserEntity> GetOrAddUserAsync(
            string email,
            CancellationToken token)
        {
            using (var entityContext = _entityContextFactory.Create())
            {
                var entities = await entityContext
                               .Users
                               .Where(x => x.Email.ToLower() == email.ToLower())
                               .ToListAsync(token);

                if (entities.Count > 1)
                {
                    throw new InvalidOperationException("There duplicate users with this email address.");
                }

                var entity = entities.FirstOrDefault();
                if (entity == null)
                {
                    entity = new UserEntity {
                        Email = email
                    };

                    await entityContext.Users.AddAsync(entity, token);

                    await entityContext.SaveChangesAsync(token);
                }

                return(entity);
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public virtual IUnitOfWorkContext BeginContext()
        {
            var entityContext = EntityContextFactory.Create();

            return(new UnitOfWorkContext(entityContext, RepoProvider));
        }