Пример #1
0
        public void TestEntityRepository()
        {
            var stopwatch = Stopwatch.StartNew();

            using (var uow = new EntityUnitOfWork <TestDbContext>())
            {
                var users = uow.Repository <User>().All();
                stopwatch.Stop();
                Console.WriteLine(stopwatch.ElapsedMilliseconds);

                foreach (var user in users)
                {
                    Console.WriteLine($"{user.Id} {user.Login}");
                }

                var entity = new User
                {
                    Login    = "******",
                    Password = "******"
                };

                entity = uow.Repository <User>().Insert(entity);
                uow.SaveChanges();
                Assert.AreNotEqual(entity.Id, 0);
                Console.WriteLine(entity.Id);
                entity.Password = "******";
                uow.Repository <User>().Update(entity, entity.Id);
                uow.SaveChanges();
                Assert.AreEqual(entity.Password, uow.Repository <User>().Entity(entity.Id).Password);
                uow.Repository <User>().Delete(entity.Id);
                uow.SaveChanges();
                Assert.IsNull(uow.Repository <User>().Entity(entity.Id));
            }
        }
Пример #2
0
        public void TestCustomRepository()
        {
            var stopwatch = Stopwatch.StartNew();

            using (var uow = new EntityUnitOfWork <TestDbContext>())
            {
                var users = uow.CustomRepository <UserRepository>().NewList();
                stopwatch.Stop();
                Console.WriteLine(stopwatch.ElapsedMilliseconds);
                foreach (var user in users)
                {
                    Console.WriteLine($"{user.Id} {user.Login}");
                }
                var dto = new UserDTO
                {
                    Login    = "******",
                    Password = "******"
                };

                dto = uow.CustomRepository <UserRepository>().Insert(dto);
                uow.SaveChanges();
                var login = dto.Login;
                dto = uow.CustomRepository <UserRepository>().DTO(d => d.Login == login);
                Assert.IsNotNull(dto);
                Assert.AreNotEqual(dto.Id, 0);
                Console.WriteLine(dto.Id);
                dto.Password = "******";
                uow.CustomRepository <UserRepository>().Update(dto, dto.Id);
                uow.SaveChanges();
                Assert.AreEqual(dto.Password, uow.CustomRepository <UserRepository>().DTO(dto.Id).Password);
                uow.CustomRepository <UserRepository>().Delete(dto.Id);
                uow.SaveChanges();
                Assert.IsNull(uow.CustomRepository <UserRepository>().DTO(dto.Id));
            }
        }
Пример #3
0
        /// <summary>
        /// Gets the current realm of the application.
        /// </summary>
        /// <returns>Returns the current realm of the application.</returns>
        public static Realm GetCurrentRealm()
        {
            Realm currentRealm = null;

            using (IUnitOfWork unitOfWork = new EntityUnitOfWork(new ApplicationDbContext()))
            {
                currentRealm = unitOfWork.RealmRepository.Get(r => r.ObsoletionTime == null).Single();
            }

            return(currentRealm);
        }
        private void UpdateControls_1()
        {
            EntityUnitOfWork u = new EntityUnitOfWork("DbConnection");

            Mapper.Reset();
            Mapper.Initialize(cfg => cfg.CreateMap <Group, GroupViewModel>());
            IEnumerable <Group> l = u.Groups.GetAll();

            lbGroup.DataContext = Mapper.Map <IEnumerable <GroupViewModel> >(l);
            //lbGroup.DataContext = Mapper.Map<IEnumerable<GroupViewModel>>(l);
        }
Пример #5
0
        public ChatHubService(EntityUnitOfWork unitOfWork,
                              IChatRequestValidator requestValidator,
                              HttpContextAccessor contextAccessor,
                              IChatEntityRepositoryProxy <ChatUser, ChatDbContext> repo)
        {
            _unitOfWork       = unitOfWork;
            _requestValidator = requestValidator;

            var token = (JwtSecurityToken)contextAccessor.HttpContext.Items["UserToken"];

            _user = repo.Find(token.Id);
        }
        private void UpdateControls()
        {
            int index = lbGroup_1.SelectedIndex;

            EntityUnitOfWork u = new EntityUnitOfWork("DbConnection");

            Mapper.Reset();
            Mapper.Initialize(cfg => cfg.CreateMap <Group, GroupViewModel>());
            IEnumerable <Group> l = u.Groups.GetAll();

            lbGroup_1.DataContext   = Mapper.Map <IEnumerable <GroupViewModel> >(l);
            lbGroup_1.SelectedIndex = index;
        }
Пример #7
0
        /// <summary>
        /// Determines whether the application is joined to a realm.
        /// </summary>
        /// <returns>Returns true if the application is joined to a realm.</returns>
        public static bool IsJoinedToRealm()
        {
            var isJoinedToRealm = Convert.ToBoolean(MvcApplication.MemoryCache.Get(RealmCacheKey));

            if (isJoinedToRealm)
            {
                return(isJoinedToRealm);
            }

            using (IUnitOfWork unitOfWork = new EntityUnitOfWork(new ApplicationDbContext()))
            {
                isJoinedToRealm = unitOfWork.RealmRepository.AsQueryable().Count(r => r.ObsoletionTime == null) > 0;
            }

            return(isJoinedToRealm);
        }
Пример #8
0
        /// <summary>
        /// Gets the service client configuration.
        /// </summary>
        /// <returns>Returns the service client configuration.</returns>
        internal static ServiceClientConfigurationSection GetServiceClientConfiguration()
        {
            Realm realm = null;

            using (IUnitOfWork unitOfWork = new EntityUnitOfWork(new ApplicationDbContext()))
            {
                realm = unitOfWork.RealmRepository.Get(r => r.ObsoletionTime == null).SingleOrDefault();
            }

            if (realm == null)
            {
                return(new ServiceClientConfigurationSection());
            }

            ServiceClientConfigurationSection configurationSection = new ServiceClientConfigurationSection
            {
                Clients = new List <ServiceClientDescription>
                {
                    new ServiceClientDescription
                    {
                        Binding = new ServiceClientBinding
                        {
                            Security = new ServiceClientSecurity
                            {
                                Mode = SecurityScheme.Basic
                            }
                        },
                        Endpoint = new List <ServiceClientEndpoint>
                        {
                            new ServiceClientEndpoint
                            {
                                Address = $"{realm.Address}/auth/oauth2_token",
                                Timeout = 30000
                            }
                        },
                        Name = Constants.Acs
                    },
                    new ServiceClientDescription
                    {
                        Binding = new ServiceClientBinding
                        {
                            Security = new ServiceClientSecurity
                            {
                                Mode = SecurityScheme.Bearer
                            }
                        },
                        Endpoint = new List <ServiceClientEndpoint>
                        {
                            new ServiceClientEndpoint
                            {
                                Address = $"{realm.Address}/ami",
                                Timeout = 30000
                            }
                        },
                        Name = Constants.Ami
                    },
                    new ServiceClientDescription
                    {
                        Binding = new ServiceClientBinding
                        {
                            Security = new ServiceClientSecurity
                            {
                                Mode = SecurityScheme.Bearer
                            },
                            Optimize = true
                        },
                        Endpoint = new List <ServiceClientEndpoint>
                        {
                            new ServiceClientEndpoint
                            {
                                Address = $"{realm.Address}/imsi",
                                Timeout = 30000
                            }
                        },
                        Name = Constants.Imsi
                    },
                    new ServiceClientDescription
                    {
                        Binding = new ServiceClientBinding
                        {
                            Security = new ServiceClientSecurity
                            {
                                Mode = SecurityScheme.Bearer
                            },
                            Optimize = true
                        },
                        Endpoint = new List <ServiceClientEndpoint>
                        {
                            new ServiceClientEndpoint
                            {
                                Address = $"{realm.Address}/risi",
                                Timeout = 30000
                            }
                        },
                        Name = Constants.Risi
                    }
                }
            };

            return(configurationSection);
        }
Пример #9
0
 public EntityRepository(EntityUnitOfWork unitOfWork)
 {
     Context = unitOfWork.GetContext <TContext>();
 }
 protected EntityRepository()
 {
     _unitOfWork = EntityUnitOfWork.GetOpenEntityUnitOfWork();
 }