Exemple #1
0
        public async Task <PagedResultDto <HomeInfoListDto> > GetPagedNoReadNotice(GetHomeInfosInput input)
        {
            long userID = (long)AbpSession.UserId;
            Expression <Func <HomeInfo, bool> >   predicate  = p => (p.Id != 1);
            Expression <Func <AbpUsersEx, bool> > predicate2 = p => (p.Id == userID);

            if (_userRepository.Count(predicate2).Equals(1))
            {
                input.LastDate = _userRepository.Get(userID).ReadLastNoticeTime;
                predicate      = predicate.And(p => p.CreationTime >= input.LastDate);
            }

            var totalCount = _entityRepository.Count(predicate);

            var entityList = await _entityRepository.GetAll()
                             .Where(r => r.Id != 1)
                             .WhereIf(!input.FilterText.IsNullOrWhiteSpace(), r => (r.Title.Contains(input.FilterText) || r.Description.Contains(input.FilterText)))
                             .WhereIf(input.LastDate.HasValue, r => r.CreationTime > input.LastDate)
                             .OrderByDescending(t => t.Id)
                             //.OrderBy(input.Sorting).AsNoTracking()
                             .PageBy(input)
                             .ToListAsync();

            var entityListDtos = ObjectMapper.Map <List <HomeInfoListDto> >(entityList);

            return(new PagedResultDto <HomeInfoListDto>(totalCount, entityListDtos)); // 第一条记录给 HomeInfo 用
        }
Exemple #2
0
        public void TextUpdate()
        {
            var user = userInfoRepository.Get(1);

            user.GmtModified = DateTime.Now;
            var result = userInfoRepository.Update(user);
        }
Exemple #3
0
        public void Dapper_and_EfCore_should_work_under_same_unitofwork_and_when_any_exception_appears_then_rollback_should_be_consistent_for_two_orm()
        {
            The <IEventBus>().Register <BlogCreatedEvent>(
                (@event, headers) =>
            {
                @event.Name.ShouldBe("Oguzhan_Same_Uow");

                throw new Exception("Uow Rollback");
            });

            try
            {
                using (IUnitOfWorkCompleteHandle uow = The <IUnitOfWorkManager>().Begin())
                {
                    int blogId = _blogRepository.InsertAndGetId(new Blog("Oguzhan_Same_Uow", "www.oguzhansoykan.com"));

                    Blog person = _blogDapperRepository.Get(blogId);

                    person.ShouldNotBeNull();

                    uow.Complete();
                }
            }
            catch (Exception exception)
            {
                //no handling.
            }

            using (IUnitOfWorkCompleteHandle uow = The <IUnitOfWorkManager>().Begin())
            {
                _blogDapperRepository.FirstOrDefault(x => x.Name == "Oguzhan_Same_Uow").ShouldBeNull();
                _blogRepository.FirstOrDefault(x => x.Name == "Oguzhan_Same_Uow").ShouldBeNull();
                uow.Complete();
            }
        }
        public void Should_Trigger_Domain_Events_For_Aggregate_Root()
        {
            var isTriggered = false;

            using (IUnitOfWorkCompleteHandle uow = The <IUnitOfWorkManager>().Begin())
            {
                _eventBus.Register <BlogUrlChangedEventData>(data =>
                {
                    data.Url.ShouldBe("http://testblog1-changed.myblogs.com");
                    isTriggered = true;
                });

                //Act

                Blog blog1 = _blogRepository.Single(b => b.Name == "test-blog-1");
                blog1.ChangeUrl("http://testblog1-changed.myblogs.com");
                _blogRepository.Update(blog1);

                _blogDapperRepository.Get(blog1.Id).ShouldNotBeNull();

                uow.Complete();
            }

            //Arrange

            //Assert
            isTriggered.ShouldBeTrue();
        }
Exemple #5
0
        public void Should_Trigger_Domain_Events_For_Aggregate_Root()
        {
            var    isTriggered   = false;
            string correlationId = Guid.NewGuid().ToString();

            using (The <IStoveCommandContextAccessor>().Use(correlationId))
            {
                using (IUnitOfWorkCompleteHandle uow = The <IUnitOfWorkManager>().Begin())
                {
                    _eventBus.Register <BlogUrlChangedEvent>((@event, headers) =>
                    {
                        @event.Url.ShouldBe("http://testblog1-changed.myblogs.com");
                        headers["CausationId"].ShouldBe(correlationId);
                        isTriggered = true;
                    });

                    //Act
                    Blog blog1 = _blogRepository.Single(b => b.Name == "test-blog-1");
                    blog1.ChangeUrl("http://testblog1-changed.myblogs.com");
                    _blogRepository.Update(blog1);

                    _blogDapperRepository.Get(blog1.Id).ShouldNotBeNull();

                    uow.Complete();
                }
            }

            //Arrange

            //Assert
            isTriggered.ShouldBeTrue();
        }
        public async Task <AuthenticateResultModelEx> AuthenticateEx([FromBody] AuthenticateModel model)
        {
            var loginResult = await GetLoginResultAsync(
                model.UserNameOrEmailAddress,
                model.Password,
                GetTenancyNameOrNull()
                );

            var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity));

            long userID = loginResult.User.Id;
            Expression <Func <AbpUsersEx, bool> > predicate2 = p => (p.Id == userID);
            DateTime?lastReadNoticeTime = null;

            if (_userRepository.Count(predicate2).Equals(1))
            {
                lastReadNoticeTime = _userRepository.Get(userID).ReadLastNoticeTime;
            }

            List <string[]> roleNames = _roleNameAppService.GetRoleNames(userID);

            return(new AuthenticateResultModelEx
            {
                AccessToken = accessToken,
                EncryptedAccessToken = GetEncryptedAccessToken(accessToken),
                ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds,
                UserId = userID,
                SurName = loginResult.User.Surname,
                LastReadNoticeTime = lastReadNoticeTime,
                Roles = roleNames[0],     //  { },
                RoleNames = roleNames[1]  //{ }
            });
        }
Exemple #7
0
        public async Task execute_method_for_void_sqls_should_work()
        {
            int blogId = _blogDapperRepository.InsertAndGetId(new Blog("Oguzhan_Blog", "wwww.aspnetboilerplate.com"));

            await _blogDapperRepository.ExecuteAsync("Update Blogs Set Name = @name where Id =@id", new { id = blogId, name = "Oguzhan_New_Blog" });

            _blogDapperRepository.Get(blogId).Name.ShouldBe("Oguzhan_New_Blog");
            _blogRepository.Get(blogId).Name.ShouldBe("Oguzhan_New_Blog");
        }
Exemple #8
0
        public async Task ExecuteMethodForVoidSqlShouldWork()
        {
            var blogId = blogDapperRepository.InsertAndGetId(new Blog("LongBlog", "wwww.studiox.com"));

            await blogDapperRepository.ExecuteAsync("Update Blogs Set Name = @name where Id =@id",
                                                    new { id = blogId, name = "LongNewBlog" });

            blogDapperRepository.Get(blogId).Name.ShouldBe("LongNewBlog");
            blogRepository.Get(blogId).Name.ShouldBe("LongNewBlog");
        }
Exemple #9
0
        public async Task execute_method_for_void_sqls_should_work()
        {
            using (IUnitOfWorkCompleteHandle uow = The <IUnitOfWorkManager>().Begin())
            {
                int blogId = _blogDapperRepository.InsertAndGetId(new Blog("Oguzhan_Blog", "wwww.stove.com"));

                await _blogDapperRepository.ExecuteAsync("Update Blogs Set Name = @name where Id =@id", new { id = blogId, name = "Oguzhan_New_Blog" });

                _blogDapperRepository.Get(blogId).Name.ShouldBe("Oguzhan_New_Blog");
                _blogRepository.Get(blogId).Name.ShouldBe("Oguzhan_New_Blog");
                uow.Complete();
            }
        }
Exemple #10
0
        public void DoSomeStuff()
        {
            using (IUnitOfWorkCompleteHandle uow = UnitOfWorkManager.Begin())
            {
                using (StoveSession.Use(266))
                {
                    _productDapperRepository.Insert(new Product("TShirt"));
                    int gomlekId = _productDapperRepository.InsertAndGetId(new Product("Gomlek"));

                    Product gomlekFromEf = _productRepository.FirstOrDefault(gomlekId);

                    _productDapperRepository.Execute("update products set Name = @name where Id = @id", new { name = "TShirt_From_ExecuteQuery", @id = gomlekId });

                    Product firstProduct = _productDapperRepository.Get(gomlekId);

                    _animalRepository.InsertAndGetId(new Animal("Bird"));

                    _animalDapperRepository.GetAll(x => x.Name == "Bird");

                    _productDapperRepository.GetAll(x => x.Id == 1 || x.Name == "Gomlek" || x.CreationTime == DateTime.Now);

                    _productDapperRepository.GetAll(x => (x.Id == 1 && x.Name == "Gomlek") || x.CreationTime == DateTime.Now);

                    _productDapperRepository.GetAll(x => ((x.Id == 1 || x.Name == "Gomlek") && x.CreationTime == DateTime.Now) ||
                                                    (x.Id == 1 || x.Name == "Gomlek") && x.CreationTime == DateTime.Now);

                    IEnumerable <Product> products = _productDapperRepository.GetAll();

                    firstProduct.Name = "Something";

                    _productDapperRepository.Update(firstProduct);

                    _mailDapperRepository.Insert(new Mail("New Product Added"));
                    Guid mailId = _mailDapperRepository.InsertAndGetId(new Mail("Second Product Added"));

                    IEnumerable <Mail> mails = _mailDapperRepository.GetAll();

                    Mail firstMail = mails.First();

                    firstMail.Subject = "Sorry wrong email!";

                    _mailDapperRepository.Update(firstMail);
                }

                uow.Complete();
            }
        }
 /// <summary>
 /// 保存
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public async Task <AjaxResponse> SaveFormDapperModel(TempTableDto model)
 {
     if (model.Id == null)
     {
         model.Id = await _dapperRepositoryTableInfo.InsertAndGetIdAsync(ObjectMapper.Map <TempTable>(model));
     }
     else
     {
         //获取需要更新的数据
         var data = _dapperRepositoryTableInfo.Get(model.Id.Value);
         //映射需要修改的数据对象
         var m = ObjectMapper.Map(model, data);
         //提交修改
         await _dapperRepositoryTableInfo.UpdateAsync(m);
     }
     return(new AjaxResponse {
         Success = true, Result = model.Id
     });
 }
Exemple #12
0
        public void Update_With_Action_Test()
        {
            Person userBefore = UsingSession(session => session.Query <Person>().Single(p => p.Name == "Oguzhan_Initial"));

            Person updatedUser = _personRepository.Update(userBefore.Id, user => user.Name = "Oguzhan_Updated_With_NH");

            updatedUser.Id.ShouldBe(userBefore.Id);
            updatedUser.Name.ShouldBe("Oguzhan_Updated_With_NH");

            Person userAfter = UsingSession(session => session.Get <Person>(userBefore.Id));

            userAfter.Name.ShouldBe("Oguzhan_Updated_With_NH");

            Person updatedWithNh = _personDapperRepository.FirstOrDefault(x => x.Name == "Oguzhan_Updated_With_NH");

            updatedWithNh.Name = "Oguzhan_Updated_With_Dapper";
            _personDapperRepository.Update(updatedWithNh);

            Person updatedWithDapper = _personDapperRepository.Get(updatedWithNh.Id);

            updatedWithDapper.Name.ShouldBe("Oguzhan_Updated_With_Dapper");
        }
Exemple #13
0
        public void DoSomeStuff()
        {
            using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
            {
                _personRepository.Insert(new Person("Oğuzhan"));
                _personRepository.Insert(new Person("Ekmek"));

                _animalRepository.Insert(new Animal("Kuş"));
                _animalRepository.Insert(new Animal("Kedi"));

                _animalDbContextProvider.GetDbContext().Animals.Add(new Animal("Kelebek"));

                _unitOfWorkManager.Current.SaveChanges();

                Animal animal = _animalRepository.FirstOrDefault(x => x.Name == "Kuş");

                Person person = _personDapperRepository.Get(1);

                Person anotherPerson = _personRepository.Nolocking(persons => persons.FirstOrDefault(x => x.Name == "Ekmek"));

                uow.Complete();
            }
        }
Exemple #14
0
        public void Should_Trigger_Domain_Events_For_Aggregate_Root()
        {
            //Arrange

            var isTriggered = false;

            _eventBus.Register <BlogUrlChangedEventData>(data =>
            {
                data.OldUrl.ShouldBe("http://testblog1.myblogs.com");
                isTriggered = true;
            });

            //Act

            Blog blog1 = _blogRepository.Single(b => b.Name == "test-blog-1");

            blog1.ChangeUrl("http://testblog1-changed.myblogs.com");
            _blogRepository.Update(blog1);


            //Assert
            _blogDapperRepository.Get(blog1.Id).ShouldNotBeNull();
            isTriggered.ShouldBeTrue();
        }
Exemple #15
0
 /// <summary>
 /// 是否存在该记录
 /// </summary>
 public bool Exists(int article_id)
 {
     return(_article.Get(article_id) != null ? true : false);
 }
Exemple #16
0
        public void DoSomeStuff()
        {
            try
            {
                using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
                {
                    Logger.Debug("Uow Began!");

                    int persionId1 = _personRepository.InsertAndGetId(new Person("Oğuzhan"));
                    _personRepository.Insert(new Person("Ekmek"));

                    int animalId1 = _animalRepository.InsertAndGetId(new Animal("Kuş"));
                    _animalRepository.Insert(new Animal("Kedi"));

                    _animalDbContextProvider.GetDbContext().Animals.Add(new Animal("Kelebek"));

                    _unitOfWorkManager.Current.SaveChanges();

                    Person personCache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                    Person person = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");
                    Animal animal = _animalRepository.FirstOrDefault(x => x.Name == "Kuş");

                    using (StoveSession.Use(266))
                    {
                        _productDapperRepository.Insert(new Product("TShirt1"));
                        int gomlekId = _productDapperRepository.InsertAndGetId(new Product("Gomlek1"));

                        Product firstProduct           = _productDapperRepository.FirstOrDefault(x => x.Name == "TShirt1");
                        IEnumerable <Product> products = _productDapperRepository.GetAll();

                        firstProduct.Name = "Something";

                        _productDapperRepository.Update(firstProduct);

                        _mailDapperRepository.Insert(new Mail("New Product Added"));
                        Guid mailId = _mailDapperRepository.InsertAndGetId(new Mail("Second Product Added"));

                        IEnumerable <Mail> mails = _mailDapperRepository.GetAll();

                        Mail firstMail = mails.First();

                        firstMail.Subject = "Sorry wrong email!";

                        _mailDapperRepository.Update(firstMail);
                    }

                    Animal oneAnimal      = _animalDapperRepository.Get(animalId1);
                    Animal oneAnimalAsync = _animalDapperRepository.GetAsync(animalId1).Result;

                    Person onePerson      = _personDapperRepository.Get(persionId1);
                    Person onePersonAsync = _personDapperRepository.GetAsync(persionId1).Result;

                    IEnumerable <Animal> birdsSet = _animalDapperRepository.GetSet(x => x.Name == "Kuş", 0, 10, "Id");

                    using (_unitOfWorkManager.Current.DisableFilter(StoveDataFilters.SoftDelete))
                    {
                        IEnumerable <Person> personFromDapperNotFiltered = _personDapperRepository.GetAll(x => x.Name == "Oğuzhan");
                    }

                    IEnumerable <Person> personFromDapperFiltered = _personDapperRepository.GetAll(x => x.Name == "Oğuzhan");

                    IEnumerable <Animal> birdsFromExpression = _animalDapperRepository.GetSet(x => x.Name == "Kuş", 0, 10, "Id");

                    IEnumerable <Animal> birdsPagedFromExpression = _animalDapperRepository.GetAllPaged(x => x.Name == "Kuş", 0, 10, "Name");

                    IEnumerable <Person> personFromDapperExpression = _personDapperRepository.GetAll(x => x.Name.Contains("Oğuzhan"));

                    int birdCount = _animalDapperRepository.Count(x => x.Name == "Kuş");

                    var personAnimal = _animalDapperRepository.Query <PersonAnimal>("select Name as PersonName,'Zürafa' as AnimalName from Persons with(nolock) where name=@name", new { name = "Oğuzhan" })
                                       .MapTo <List <PersonAnimalDto> >();

                    birdsFromExpression.ToList();
                    birdsPagedFromExpression.ToList();
                    birdsSet.ToList();

                    IEnumerable <Person> person2FromDapper = _personDapperRepository.Query("select * from Persons with(nolock) where name =@name", new { name = "Oğuzhan" });

                    _personDapperRepository.Insert(new Person("oğuzhan2"));
                    int    id      = _personDapperRepository.InsertAndGetId(new Person("oğuzhan3"));
                    Person person3 = _personDapperRepository.Get(id);
                    person3.Name = "oğuzhan4";
                    _personDapperRepository.Update(person3);
                    _personDapperRepository.Delete(person3);

                    Person person2Cache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                    //Person oguzhan = _personRepository.Nolocking(persons => persons.FirstOrDefault(x => x.Name == "Oğuzhan"));

                    Person oguzhan2 = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");

                    uow.Complete();

                    _messageBus.Publish <IPersonAddedMessage>(new PersonAddedMessage
                    {
                        Name          = "Oğuzhan",
                        CorrelationId = NewId.NextGuid()
                    });

                    //_hangfireBackgroundJobManager.EnqueueAsync<SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                    //{
                    //    Message = "Oğuzhan"
                    //});

                    //_hangfireScheduleJobManager.ScheduleAsync<SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                    //{
                    //    Message = "Oğuzhan"
                    //}, Cron.Minutely());

                    Logger.Debug("Uow End!");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw ex;
            }
        }
Exemple #17
0
 public virtual TEntity Get(string id, bool @readonly = false)
 {
     return(@readonly
         ? _dapperRepository.Get(id)
         : _repository.Get(id));
 }
Exemple #18
0
        public async Task Dapper_Repository_Tests()
        {
            using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
            {
                //---Insert operation should work and tenant, creation audit properties must be set---------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Product insertedProduct = _productDapperRepository.GetAll(x => x.Name == "TShirt").FirstOrDefault();

                insertedProduct.ShouldNotBeNull();
                insertedProduct.TenantId.ShouldBe(AbpSession.TenantId);
                insertedProduct.CreationTime.ShouldNotBeNull();
                insertedProduct.CreatorUserId.ShouldBe(AbpSession.UserId);

                //----Update operation should work and Modification Audits should be set---------------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Product productToUpdate = _productDapperRepository.GetAll(x => x.Name == "TShirt").FirstOrDefault();
                productToUpdate.Name = "Pants";
                _productDapperRepository.Update(productToUpdate);

                productToUpdate.ShouldNotBeNull();
                productToUpdate.TenantId.ShouldBe(AbpSession.TenantId);
                productToUpdate.CreationTime.ShouldNotBeNull();
                productToUpdate.LastModifierUserId.ShouldBe(AbpSession.UserId);

                //---Get method should return single-------------------------------------------------------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Action getAction = () => _productDapperRepository.Single(x => x.Name == "TShirt");

                getAction.ShouldThrow <InvalidOperationException>("Sequence contains more than one element");

                //----Select * from syntax should work---------------------------------
                IEnumerable <Product> products = _productDapperRepository.Query("select * from Products");

                products.Count().ShouldBeGreaterThan(0);

                //------------Ef and Dapper should work under same transaction---------------------
                Product productFromEf     = _productRepository.FirstOrDefault(x => x.Name == "TShirt");
                Product productFromDapper = _productDapperRepository.Single(productFromEf.Id);

                productFromDapper.Name.ShouldBe(productFromEf.Name);
                productFromDapper.TenantId.ShouldBe(productFromEf.TenantId);

                //------Soft Delete should work for Dapper--------------
                _productDapperRepository.Insert(new Product("SoftDeletableProduct"));

                Product toSoftDeleteProduct = _productDapperRepository.Single(x => x.Name == "SoftDeletableProduct");

                _productDapperRepository.Delete(toSoftDeleteProduct);

                toSoftDeleteProduct.IsDeleted.ShouldBe(true);
                toSoftDeleteProduct.DeleterUserId.ShouldBe(AbpSession.UserId);
                toSoftDeleteProduct.TenantId.ShouldBe(AbpSession.TenantId);

                Product softDeletedProduct = _productRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                softDeletedProduct.ShouldBeNull();

                Product softDeletedProductFromDapper = _productDapperRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                softDeletedProductFromDapper.ShouldBeNull();

                using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
                {
                    Product softDeletedProductWhenFilterDisabled = _productRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                    softDeletedProductWhenFilterDisabled.ShouldNotBeNull();

                    Product softDeletedProductFromDapperWhenFilterDisabled = _productDapperRepository.Single(x => x.Name == "SoftDeletableProduct");
                    softDeletedProductFromDapperWhenFilterDisabled.ShouldNotBeNull();
                }

                using (AbpSession.Use(2, 266))
                {
                    int productWithTenant2Id = _productDapperRepository.InsertAndGetId(new Product("ProductWithTenant2"));

                    Product productWithTenant2 = _productRepository.Get(productWithTenant2Id);

                    productWithTenant2.TenantId.ShouldBe(1); //Not sure about that?,Because we changed TenantId to 2 in this scope !!! Abp.TenantId = 2 now NOT 1 !!!
                }

                using (_unitOfWorkManager.Current.SetTenantId(3))
                {
                    int productWithTenant3Id = _productDapperRepository.InsertAndGetId(new Product("ProductWithTenant3"));

                    Product productWithTenant3 = _productRepository.Get(productWithTenant3Id);

                    productWithTenant3.TenantId.ShouldBe(3);
                }

                Product productWithTenantId3FromDapper = _productDapperRepository.FirstOrDefault(x => x.Name == "ProductWithTenant3");
                productWithTenantId3FromDapper.ShouldBeNull();

                Product p = await _productDapperRepository.FirstOrDefaultAsync(x => x.Status == Status.Active);

                p.ShouldNotBeNull();

                using (_unitOfWorkManager.Current.SetTenantId(3))
                {
                    Product productWithTenantId3FromDapperInsideTenantScope = _productDapperRepository.FirstOrDefault(x => x.Name == "ProductWithTenant3");
                    productWithTenantId3FromDapperInsideTenantScope.ShouldNotBeNull();
                }

                //About issue-#2091
                using (_unitOfWorkManager.Current.SetTenantId(AbpSession.TenantId))
                {
                    int productWithTenantId40 = _productDapperRepository.InsertAndGetId(new Product("ProductWithTenantId40"));

                    Product productWithTenant40 = _productRepository.Get(productWithTenantId40);

                    productWithTenant40.TenantId.ShouldBe(AbpSession.TenantId);
                    productWithTenant40.CreatorUserId.ShouldBe(AbpSession.UserId);
                }

                //Second DbContext tests
                int productDetailId = _productDetailRepository.InsertAndGetId(new ProductDetail("Woman"));
                _productDetailDapperRepository.Get(productDetailId).ShouldNotBeNull();

                uow.Complete();
            }
        }
        public void Dapper_Repository_Tests()
        {
            using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
            {
                //---Insert operation should work and tenant, creation audit properties must be set---------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Product insertedProduct = _productDapperRepository.GetAll(x => x.Name == "TShirt").FirstOrDefault();

                Guid mailId = _mailRepository.InsertAndGetId(new Mail("Hi There !"));
                _unitOfWorkManager.Current.SaveChanges();
                Mail mail = _mailDapperRepository.Get(mailId);
                mail.ShouldNotBeNull();
                mail.CreatorUserId.ShouldNotBeNull();
                mail.CreatorUserId.ShouldBe(StoveSession.UserId);

                Mail mailFromCustomRepository = _mailCustomDapperRepository.GetMailById(mailId);
                mailFromCustomRepository.ShouldNotBeNull();

                insertedProduct.ShouldNotBeNull();
                insertedProduct.CreationTime.ShouldNotBeNull();
                insertedProduct.CreatorUserId.ShouldNotBeNull();
                insertedProduct.CreatorUserId.ShouldBe(StoveSession.UserId);

                //----Update operation should work and Modification Audits should be set---------------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Product productToUpdate = _productDapperRepository.GetAll(x => x.Name == "TShirt").FirstOrDefault();
                productToUpdate.Name = "Pants";
                _productDapperRepository.Update(productToUpdate);

                productToUpdate.ShouldNotBeNull();

                productToUpdate.CreationTime.ShouldNotBeNull();
                productToUpdate.LastModifierUserId.ShouldBe(StoveSession.UserId);
                productToUpdate.CreatorUserId.ShouldBe(StoveSession.UserId);

                //---Get method should return single-------------------------------------------------------------------
                _productDapperRepository.Insert(new Product("TShirt"));
                Action getAction = () => _productDapperRepository.Single(x => x.Name == "TShirt");

                getAction.ShouldThrow <InvalidOperationException>("Sequence contains more than one element");

                //----Select * from syntax should work---------------------------------
                IEnumerable <Product> products = _productDapperRepository.Query("select * from Products");

                products.Count().ShouldBeGreaterThan(0);

                //------------Ef and Dapper should work under same transaction---------------------
                Product productFromEf     = _productRepository.FirstOrDefault(x => x.Name == "TShirt");
                Product productFromDapper = _productDapperRepository.Single(productFromEf.Id);

                productFromDapper.Name.ShouldBe(productFromEf.Name);

                //------Soft Delete should work for Dapper--------------
                _productDapperRepository.Insert(new Product("SoftDeletableProduct"));

                Product toSoftDeleteProduct = _productDapperRepository.Single(x => x.Name == "SoftDeletableProduct");

                _productDapperRepository.Delete(toSoftDeleteProduct);

                toSoftDeleteProduct.IsDeleted.ShouldBe(true);
                toSoftDeleteProduct.DeleterUserId.ShouldBe(StoveSession.UserId);

                Product softDeletedProduct = _productRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                softDeletedProduct.ShouldBeNull();

                Product softDeletedProductFromDapper = _productDapperRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                softDeletedProductFromDapper.ShouldBeNull();

                using (_unitOfWorkManager.Current.DisableFilter(StoveDataFilters.SoftDelete))
                {
                    Product softDeletedProductWhenFilterDisabled = _productRepository.FirstOrDefault(x => x.Name == "SoftDeletableProduct");
                    softDeletedProductWhenFilterDisabled.ShouldNotBeNull();

                    Product softDeletedProductFromDapperWhenFilterDisabled = _productDapperRepository.Single(x => x.Name == "SoftDeletableProduct");
                    softDeletedProductFromDapperWhenFilterDisabled.ShouldNotBeNull();
                }

                using (StoveSession.Use(266))
                {
                    _productDapperRepository.Insert(new Product("InsertedProductWith266Id"));
                    Product InsertedProductWith266Id = _productDapperRepository.GetAll(x => x.Name == "InsertedProductWith266Id").FirstOrDefault();

                    InsertedProductWith266Id.ShouldNotBeNull();
                    InsertedProductWith266Id.CreationTime.ShouldNotBeNull();
                    InsertedProductWith266Id.CreatorUserId.ShouldNotBeNull();
                    InsertedProductWith266Id.CreatorUserId.ShouldBe(StoveSession.UserId);
                }

                _productDapperRepository.Insert(new Product("InsertedProductAfterSpecifiedUserId"));
                Product InsertedProductAfterSpecifiedUserId = _productDapperRepository.GetAll(x => x.Name == "InsertedProductAfterSpecifiedUserId").FirstOrDefault();

                InsertedProductAfterSpecifiedUserId.ShouldNotBeNull();
                InsertedProductAfterSpecifiedUserId.CreationTime.ShouldNotBeNull();
                InsertedProductAfterSpecifiedUserId.CreatorUserId.ShouldNotBeNull();
                InsertedProductAfterSpecifiedUserId.CreatorUserId.ShouldBe(StoveSession.UserId);

                uow.Complete();
            }
        }
 public void Get()
 {
     _dapperRepository.Get("");
 }
Exemple #21
0
 private DateTime?GetReadLastNoticeTime()
 {
     return(_userRepository.Get((long)AbpSession.UserId).ReadLastNoticeTime);
 }
Exemple #22
0
 public virtual TEntity Get(string id)
 {
     return(_dapperRepository.Get(id));
 }
Exemple #23
0
        public void DoSomeStuff()
        {
            using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
            {
                Logger.Debug("Uow Began!");

                _personRepository.Insert(new Person("Oğuzhan"));
                _personRepository.Insert(new Person("Ekmek"));

                _animalRepository.Insert(new Animal("Kuş"));
                _animalRepository.Insert(new Animal("Kedi"));

                _animalDbContextProvider.GetDbContext().Animals.Add(new Animal("Kelebek"));

                _unitOfWorkManager.Current.SaveChanges();

                Person personCache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                Person person = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");
                Animal animal = _animalRepository.FirstOrDefault(x => x.Name == "Kuş");

                #region DAPPER

                var list = new List <string>
                {
                    "elma", "armut"
                };

                ExpressionStarter <Animal> predicate = PredicateBuilder.New <Animal>();
                predicate.And(x => x.Name == "Kuş");

                IEnumerable <Animal> birdsSet = _animalDapperRepository.GetSet(new { Name = "Kuş" }, 0, 10, "Id");

                IEnumerable <Person> personFromDapper = _personDapperRepository.GetList(new { Name = "Oğuzhan" });

                IEnumerable <Animal> birdsFromExpression = _animalDapperRepository.GetSet(predicate, 0, 10, "Id");

                IEnumerable <Animal> birdsPagedFromExpression = _animalDapperRepository.GetListPaged(x => x.Name == "Kuş", 0, 10, "Name");

                IEnumerable <Person> personFromDapperExpression = _personDapperRepository.GetList(x => x.Name.Contains("Oğuzhan"));

                int birdCount = _animalDapperRepository.Count(x => x.Name == "Kuş");

                var personAnimal = _animalDapperRepository.Query <PersonAnimal>("select Name as PersonName,'Zürafa' as AnimalName from Person with(nolock) where name=@name", new { name = "Oğuzhan" })
                                   .MapTo <List <PersonAnimalDto> >();

                birdsFromExpression.ToList();
                birdsPagedFromExpression.ToList();
                birdsSet.ToList();

                IEnumerable <Person> person2FromDapper = _personDapperRepository.Query("select * from Person with(nolock) where name =@name", new { name = "Oğuzhan" });

                _personDapperRepository.Insert(new Person("oğuzhan2"));
                int    id      = _personDapperRepository.InsertAndGetId(new Person("oğuzhan3"));
                Person person3 = _personDapperRepository.Get(id);
                person3.Name = "oğuzhan4";
                _personDapperRepository.Update(person3);
                _personDapperRepository.Delete(person3);

                #endregion

                Person person2Cache = _cacheManager.GetCache(DemoCacheName.Demo).Get("person", () => _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan"));

                Person oguzhan = _personRepository.Nolocking(persons => persons.FirstOrDefault(x => x.Name == "Oğuzhan"));

                Person oguzhan2 = _personRepository.FirstOrDefault(x => x.Name == "Oğuzhan");

                uow.Complete();

                _messageBus.Publish <IPersonAddedMessage>(new PersonAddedMessage
                {
                    Name          = "Oğuzhan",
                    CorrelationId = NewId.NextGuid()
                });

                //_hangfireBackgroundJobManager.EnqueueAsync<SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                //{
                //    Message = "Oğuzhan"
                //});

                _hangfireScheduleJobManager.ScheduleAsync <SimpleBackgroundJob, SimpleBackgroundJobArgs>(new SimpleBackgroundJobArgs
                {
                    Message = "Oğuzhan"
                }, Cron.Minutely());

                Logger.Debug("Uow End!");
            }
        }