Exemplo n.º 1
0
        public void CheckSjmxJdzt(int id)
        {
            string strSQL = "select 0 as y, 0 as m, qzyjs as count, id as bm from YQSF_SJD where ID = (select sjdid from YQSF_SJMX as b where b.id = {0}";
            STATS  st     = _DapperRepository.Query(string.Format(strSQL, id)).FirstOrDefault();
            int    yqjs   = st.count;
            int    wtdid  = st.bm;

            strSQL = @"SELECT 0 as y, 0 as m, qzyjs as count, 0 as bm
        FROM dbo.YQSF_SJMX AS a LEFT JOIN
        dbo.YQSF_SJD as e on a.sjdid = e.id LEFT JOIN
        dbo.JCXX_XHGG_BM AS b ON a.XHGGBM = b.XHGGBM LEFT JOIN
        dbo.JCXX_QJMC_BM AS d ON b.QJMCBM = d.QJMCBM								
        where d.QJMCBM = 1000 and e.djrq>'2019-04-21' and jdzt=222 and e.sjdid={0}";
            st     = _DapperRepository.Query(string.Format(strSQL, wtdid)).FirstOrDefault();
            int yqjs1 = st.count;

            strSQL = "select 0 as y, 0 as m, count(0) as count,0 as bm from YQSF_SJMX where jdzt = '检完' and ID = {0}";
            st     = _DapperRepository.Query(string.Format(strSQL, id)).FirstOrDefault();
            int yqjs2 = st.count;

            if (yqjs == yqjs1 || yqjs == yqjs2)
            {
                strSQL = "update YQSF_SJD set qzyjdzt = N'检定完毕' where id = {0}";
                st     = _DapperRepository.Query(string.Format(strSQL, wtdid)).FirstOrDefault();
            }
        }
Exemplo n.º 2
0
 public Task <Contact.Image.GetSystemImageListResponse> GetSystemImageListAsync(Contact.Image.GetSystemImageList dto)
 {
     return(Task.Run(() =>
     {
         List <SelectProjectImageModel> list;
         int total = 0;
         if (dto.project_id == null)
         {
             list = _dapperRepository.Query <SelectProjectImageModel>(
                 string.Format(ImageServiceConst.SELECT_SYSTEM_IMG_SQL, ""), new{ start = dto.start, length = dto.length }).ToList();
             total = _dapperRepository.QuerySingleOrDefault <int>(string.Format(ImageServiceConst.SELECT_SYSTEM_IMG_COUNT_SQL, ""));
         }
         else
         {
             list = _dapperRepository.Query <SelectProjectImageModel>(
                 string.Format(ImageServiceConst.SELECT_SYSTEM_IMG_SQL,
                               ImageServiceConst.SELECT_SYSTEM_IMG_WHERE_SQL), new { projectId = dto.project_id, start = dto.start, length = dto.length }).ToList();
             total = _dapperRepository.QuerySingleOrDefault <int>(string.Format(ImageServiceConst.SELECT_SYSTEM_IMG_COUNT_SQL, ImageServiceConst.SELECT_SYSTEM_IMG_WHERE_SQL), new { projectId = dto.project_id });
         }
         GetSystemImageListResponse resp = new GetSystemImageListResponse();
         resp.data = Mapper.Map <List <SystemImageDto> >(list);
         resp.total = total;
         return resp;
     }));
 }
Exemplo n.º 3
0
        public void QueryingWithTEntityTPrimaryKeyShouldWorkOnDapperRepositories()
        {
            commentRepository.Insert(new Comment("hey!"));

            var comments  = commentDapperRepository.Query("select * from Comments").ToList();
            var comments2 = commentDapperRepository.Query <Comment>("select * from Comments").ToList();

            comments2.Count.ShouldBe(1);
            comments.Count.ShouldBe(1);
        }
        public void querying_with_TEntity_TPrimaryKey_should_work_on_dapper_repositories()
        {
            _commentRepository.Insert(new Comment("hey!"));

            List <Comment> comments  = _commentDapperRepository.Query("select * from Comments").ToList();
            List <Comment> comments2 = _commentDapperRepository.Query <Comment>("select * from Comments").ToList();

            comments2.Count.ShouldBe(1);
            comments.Count.ShouldBe(1);
        }
Exemplo n.º 5
0
        private IEnumerable <RoleNames> GetRoles()
        {
            if (!AbpSession.UserId.HasValue)
            {
                return(null);
            }
            long id    = (long)AbpSession.UserId;
            var  param = new { Id = id };
            var  ret   = _roleNamesRepository.Query("select b.id,b.DisplayName,b.NormalizedName from AbpRoles b where b.Id in (select RoleId from AbpUserRoles a where a.UserId = @Id)", param);

            return(ret);
        }
Exemplo n.º 6
0
        public string[] GetRoles(long userid)
        {
            var param = new { Id = userid };
            var ret   = _roleRepository.Query("select b.NormalizedName from AbpRoles b where b.Id in (select RoleId from AbpUserRoles a where a.UserId = @Id)", param);

            List <string> list = new List <string>();

            foreach (Role r in ret)
            {
                list.Add(r.NormalizedName);
            }
            return(list.ToArray());
        }
Exemplo n.º 7
0
        /// <summary>
        /// 取证书编号
        /// LB
        /// M01 GPS
        /// M02 全站仪
        /// </summary>
        /// <param name="LB"></param>
        /// <returns></returns>
        private string GetZSBH(string LB, double ID)
        //public dynamic GetZSBH(string LB, double ID)
        {
            string strSQL1 = @"
            Update YQSF_SJMX
            set jdzt='在检' 
            where ID=" + ID;

            _sjmxDapperRepository.Execute(strSQL1);

            StringBuilder strSQL = new StringBuilder(100);

            strSQL.Append("declare @SQL VARCHAR(255)");
            strSQL.Append("\r\n");
            strSQL.Append("DECLARE @Year decimal");
            strSQL.Append("\r\n");
            strSQL.Append("DECLARE @Zsbh VARCHAR(12)");
            strSQL.Append("\r\n");
            strSQL.Append("set @Year = (select LEFT(Right(MAX(zsbh), 8), 4) from YQSF_SJMX where zsbh like '" + LB + "-%')");
            strSQL.Append("\r\n");
            strSQL.Append("if (year(getdate()) > @Year) ");
            strSQL.Append("\r\n");
            strSQL.Append("set @Zsbh = '" + LB + "-" + DateTime.Now.Year + "0001'");
            strSQL.Append("\r\n");
            strSQL.Append("else");
            strSQL.Append("\r\n");
            strSQL.Append("set @Zsbh = '" + LB + "-'+str((select Right(MAX(zsbh),8)+1 from YQSF_SJMX where zsbh like '" + LB + "-%'),8,0)");
            strSQL.Append("\r\n");
            strSQL.Append("update yqsf_sjmx set zsbh=@Zsbh where ID=" + ID + "  and len(zsbh)=0");
            strSQL.Append("\r\n");
            strSQL.Append("select zsbh from YQSF_SJMX where ID=" + ID);
            return(_sjmxDapperRepository.Query(strSQL.ToString()).FirstOrDefault().ZSBH);
        }
Exemplo n.º 8
0
        public dynamic GetLastSJMX()
        {
            string strSQL = @"select top 3 * from  VW_DPII_SJD Order By ID Desc";
            IEnumerable <RecentSJMX> ret = _sjmxRecentDapperRepository.Query(strSQL);

            return(ret);
        }
Exemplo n.º 9
0
        public void Test()
        {
            UserIdentifier userIdentifier = new UserIdentifier(0, 35);

            _notificationPublisher.PublishAsync("NewTask", new NotificationData(), null,
                                                NotificationSeverity.Info, new[] { userIdentifier });
            _backgroundJobManager.EnqueueAsync <TestJob, int>(42);
            var people = _dapperRepository.Query("select * from AbpUsers");
        }
Exemplo n.º 10
0
        public int Add(int id, string jdy) //string jdy = (Int32.Parse(context.Request.Form["jdy"].ToString())-100000).ToString();
        {
            int    ret    = 0;
            string strSQL = "select top 1 ID from  YQSF_DPII_JDRQ where ID=" + id;

            if (_jdrqDapperRepository.Query(strSQL).Count() == 0) //确保不存在再 插入
            {
                using (var unitOfWork = _unitOfWorkManager.Begin())
                {
                    strSQL = "insert into YQSF_DPII_JDRQ(id,jdrq,jdzt,jdy) values(" + id + ",'" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "'," + 100 + ",'" + jdy + "')";
                    _jdrqDapperRepository.Execute(strSQL);
                    strSQL = "update YQSF_SJD set qzyjdzt = '正在检定' where ID = (select sjdid from YQSF_SJMX as b where b.id = " + id + ")";
                    _jdrqDapperRepository.Execute(strSQL);
                    unitOfWork.Complete();
                    ret = 1;
                }
            }
            return(ret);
        }
Exemplo n.º 11
0
        public Pessoa BuscarPessoa(int pessoaId)
        {
            var sql = @"
                SELECT
                    [Id]
	                ,[Nome]
	                ,[CpfCnpj]
	                ,[Email]
                FROM
                    [dbo].[Pessoa]
                WHERE
                    [Id] = @PessoaId";

            var param = new {
                PessoaId = pessoaId
            };

            return(_dapperRepository.Query <Pessoa>(sql, param).FirstOrDefault());
        }
Exemplo n.º 12
0
        // 1xxxx 1000 1010 ...
        private string GetJDRoles(long userid)
        {
            var param = new { Id = userid };
            var ret   = _roleRepository.Query("select b.NormalizedName from AbpRoles b where b.Id in (select RoleId from AbpUserRoles a where a.UserId = @Id)", param);

            List <int> list = new List <int>();

            foreach (Role r in ret)
            {
                if (r.NormalizedName.StartsWith("1"))
                {
                    //System.Diagnostics.Debug.WriteLine(r.NormalizedName);
                    list.Add(int.Parse(r.NormalizedName));
                }
            }
            //return list.ToArray(); // string[]

            return(String.Join(",", list.ToArray()));
        }
Exemplo n.º 13
0
        public string ShowResults(int ID)
        {
            string strSQL = @"select Data from ZSH_Data where ID=@ID";
            var    param  = new
            {
                ID = ID
            };

            return(_zshDapperRepository.Query(strSQL, param).FirstOrDefault().Data);
        }
Exemplo n.º 14
0
        public dynamic GetRecentWTD()
        {
            /*
             * string strSQL = @"
             * UPDATE YQSF_SJD
             * SET q z yjs = (
             *  SELECT COUNT(*) FROM VW_SJMX WHERE[器具名称] = '全站仪' and 送检单号 = YQSF_SJD.sjdid
             * )";
             * _wtdDapperRepository.Execute(strSQL);
             */

            string            strSQL = @"SELECT TOP(10) a.ID, a.SJDID , f.DWMC , a.SJRQ,YQJS
                              FROM dbo.YQSF_SJD AS a INNER JOIN 
                                   dbo.YQSF_KH AS f ON f.khid = a.khid
                              ORDER BY a.ID DESC";
            IEnumerable <WTD> ret    = _wtdDapperRepository.Query(strSQL);

            return(ret);
        }
Exemplo n.º 15
0
        public void querying_with_TEntity_TPrimaryKey_should_work_on_dapper_repositories()
        {
            List <Comment> comments;
            List <Comment> comments2;

            using (IUnitOfWorkCompleteHandle uow = The <IUnitOfWorkManager>().Begin())
            {
                _commentRepository.Insert(new Comment("hey!"));

                uow.Complete();
            }

            using (IUnitOfWorkCompleteHandle uow = The <IUnitOfWorkManager>().Begin())
            {
                comments  = _commentDapperRepository.Query("select * from Comments").ToList();
                comments2 = _commentDapperRepository.Query <Comment>("select * from Comments").ToList();

                uow.Complete();
            }

            comments2.Count.ShouldBe(1);
            comments.Count.ShouldBe(1);
        }
Exemplo n.º 16
0
        public JBCS GetJbcs(string bm)
        {
            string strSQL = "select top 1 * from JCXX_QZY_JDZB where xhggbm=" + bm;

            IEnumerable <JBCS> ret = _jbcsDapperRepository.Query(strSQL);

            if (ret != null)
            {
                return(ret.FirstOrDefault());
            }
            else
            {
                return(null); // AddNew
            }
        }
Exemplo n.º 17
0
        public void DoSomeStuff()
        {
            var people = _personDapperRepository.Query("select * from AppPersons");

            _personDapperRepository.Execute("Insert into AppPersons (Id,Name,CreationTime) values ('" + Guid.NewGuid() + "','Name_" + Guid.NewGuid().ToString().Substring(10) + "','" + Clock.Now.ToString() + "')");
            _personDapperRepository.Execute("UPDATE AppPersons set Name=@name where Id=@Id", new { name = "Name_" + Guid.NewGuid().ToString().Substring(10), Id = people.FirstOrDefault()?.Id });
            var person = people.FirstOrDefault();

            person.Name = "Yebin_" + Guid.NewGuid().ToString().Substring(15);
            _personDapperRepository.Update(person);
            person = _personDapperRepository.Single(people.Skip(1).Take(1).First().Id);
            _personDapperRepository.Insert(new Person {
                Name = "Yebin_" + Guid.NewGuid().ToString().Substring(15), Id = Guid.NewGuid(), CreationTime = Clock.Now
            });
            _personDapperRepository.Delete(people.Skip(2).Take(1).First().Id);
        }
Exemplo n.º 18
0
        /*
         * public string[] getDisplayName() {
         *  List<string> list = new List<string>();
         *  var ret = GetRoles();
         *  foreach (RoleNames r in ret)
         *  {
         *    list.Add(r.DisplayName);
         *  }
         *  return list.ToArray(); // string[]
         * }
         */

        public string[] GetJDRolesList(long userid)
        {
            var           param = new { Id = userid };
            var           ret   = _roleRepository.Query("select b.NormalizedName from AbpRoles b where b.Id in (select RoleId from AbpUserRoles a where a.UserId = @Id)", param);
            List <string> list  = new List <string>();

            foreach (Role r in ret)
            {
                if (r.NormalizedName.StartsWith("1"))
                {
                    //System.Diagnostics.Debug.WriteLine(r.NormalizedName);
                    list.Add(r.NormalizedName);
                }
            }
            return(list.ToArray()); // string[]
        }
Exemplo n.º 19
0
        public void DoSomeStuff()
        {
            IEnumerable <StorefrontProductCurrencyDto> storefrontProductPriceDto = new List <StorefrontProductCurrencyDto>
            {
                new StorefrontProductCurrencyDto {
                    CurrencyId = 1, ProductId = 10001, StorefrontId = 1
                }
            };

            using (IUnitOfWorkCompleteHandle uow = UnitOfWorkManager.Begin())
            {
                IEnumerable <StorefrontProductPriceDto> test = _storefrontStorefrontProductPriceDapperRepository.Query <StorefrontProductPriceDto>("dbo.[GetProductPrice]", new TableValueParameter("@ProductPrice", "ProductPrice", storefrontProductPriceDto), CommandType.StoredProcedure).ToList();

                Console.WriteLine(test.Count());


                uow.Complete();
            }
        }
Exemplo n.º 20
0
        public async Task <ListResultDto <TaskListDto> > GetAll(GetAllTasksInput input)
        {
            //var tasks = await _taskRepository
            //    .GetAll().Include(c=>c.AssignedPerson)
            //    .WhereIf(input.State.HasValue, t => t.State == input.State.Value)
            //    .OrderByDescending(t => t.CreationTime)
            //    .ToListAsync();


            var people = _meetingRoomDapperRepository.Query("select * from meetingrooms");

            var tasks = await _taskRepository
                        .GetAll()
                        .ToListAsync();

            // EventBus.Trigger(new TaskCompletedEventData { Task= tasks.FirstOrDefault() });

            return(new ListResultDto <TaskListDto>(
                       ObjectMapper.Map <List <TaskListDto> >(tasks)
                       ));
        }
Exemplo n.º 21
0
        // 待检定列表
        public IEnumerable <VW_SJCL_100> ListDjmxs(string q)
        {
            if (!AbpSession.UserId.HasValue)
            {
                return(null);
            }

            long id    = (long)AbpSession.UserId;
            var  roles = GetJDRoles(id);

            string strSQL = @"select * from VW_SJCL_100 where jdzt = 100 and qjmcbm in (" + roles + ")";

            if (!string.IsNullOrEmpty(q))
            {
                strSQL += " and (ccbh like '%" + q + "%' or xhggmc like '%" + q + "%'";
                strSQL += ")";
            }

            IEnumerable <VW_SJCL_100> ret = _vwsjclDapperRepository.Query(strSQL);

            return(ret);
        }
Exemplo n.º 22
0
        public SJMX Get(int id)
        {
            string strSQL = @"SELECT a.ID, e.sjdid ,e.djrq ,d.QJMC , b.XHGGMC , a.ccbh ,a.jdzt
                            FROM dbo.YQSF_SJMX AS a INNER JOIN											
                            dbo.YQSF_SJD as e on a.sjdid = e.id INNER JOIN
                            dbo.JCXX_XHGG_BM AS b ON a.XHGGBM = b.XHGGBM LEFT JOIN
                            dbo.JCXX_QJMC_BM AS d ON b.QJMCBM = d.QJMCBM
                            where a.ID={0}";

            strSQL = string.Format(strSQL, id);
            IEnumerable <SJMX> ret = _sjmxDapperRepository.Query(strSQL);

            if (ret != null)
            {
                return(ret.FirstOrDefault());
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 23
0
        public IEnumerable <AbpUsers> DoSomeStuff3()
        {
            var people = _userDapperRepository.Query("select * from AbpUsers");

            return(people);
        }
Exemplo n.º 24
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" });

                #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"
                });

                Logger.Debug("Uow End!");
            }
        }
Exemplo n.º 25
0
 public IEnumerable <USER_NAME> GetCacheUserData()
 {
     return(_userNamesRepository.Query("select id,Surname from AbpUsers"));
 }
Exemplo n.º 26
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();
            }
        }
Exemplo n.º 27
0
 public IEnumerable <TEntity> Query(string sql, object param = null)
 {
     return(_dapperRepository.Query(sql, param));
 }
Exemplo n.º 28
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;
            }
        }
Exemplo n.º 29
0
        private double[] _getStatsData()
        {
            /*
             * 1000 全站仪
             * 1030 GPS接收机
             * 1010 经纬仪
             * 1100 电子经纬仪
             * 1020 水准仪
             * 1040 手持测距仪
             */
            double[] StatsData = new double[12];

            // 全部记录
            string strSQL           = @"select 0 as y, 0 as m,count(0) as count ,b.qjmcbm as bm from YQSF_SJMX as a 
            left join JCXX_XHGG_BM as b on a.xhggbm = b.XHGGBM GROUP BY b.QJMCBM ORDER BY b.QJMCBM ";
            IEnumerable <STATS> ret = _sjmxDapperRepository.Query(strSQL);

            if (ret.Count() > 0)
            {
                StatsData[0]  = ret.Where(c => c.bm == 1000).FirstOrDefault().count;
                StatsData[2]  = ret.Where(c => c.bm == 1030).FirstOrDefault().count;
                StatsData[4]  = ret.Where(c => (new int?[] { 1010, 1100 }).Contains(c.bm)).Sum(p => p.count);
                StatsData[6]  = ret.Where(c => c.bm == 1020).FirstOrDefault().count;
                StatsData[8]  = ret.Where(c => c.bm == 1040).FirstOrDefault().count;
                StatsData[10] = ret.Where(c => !(new int?[] { 1000, 1010, 1100, 1020, 1030, 1040 }).Contains(c.bm)).FirstOrDefault().count;
            }

            // 今年记录
            strSQL = @"select 0 as y, 0 as m, count(0) as count,c.qjmcbm as bm from YQSF_SJMX as a 
            left join YQSF_SJD as b on a.sjdid = b.ID left join JCXX_XHGG_BM as c on a.xhggbm = c.XHGGBM 
            WHERE b.sjrq > dateadd(year, datediff(year, 0, getdate()), 0)
            GROUP BY c.QJMCBM ORDER BY c.QJMCBM";
            ret    = _sjmxDapperRepository.Query(strSQL);
            if (ret.Count() > 0)
            {
                StatsData[1]  = ret.Where(c => c.bm == 1000).FirstOrDefault().count;
                StatsData[3]  = ret.Where(c => c.bm == 1030).FirstOrDefault().count;
                StatsData[5]  = ret.Where(c => (new int?[] { 1010, 1100 }).Contains(c.bm)).Sum(p => p.count);
                StatsData[7]  = ret.Where(c => c.bm == 1020).FirstOrDefault().count;
                StatsData[9]  = ret.Where(c => c.bm == 1040).FirstOrDefault().count;
                StatsData[11] = ret.Where(c => !(new int?[] { 1000, 1010, 1100, 1020, 1030, 1040 }).Contains(c.bm)).FirstOrDefault().count;
            }
            double[] Datas = new double[] { StatsData[0], StatsData[1], StatsData[2], StatsData[3], StatsData[4], StatsData[5], StatsData[6], StatsData[7], StatsData[8], StatsData[9], StatsData[10], StatsData[11] };
            return(Datas);
        }
Exemplo n.º 30
0
        public dynamic DoSomeStuff1() // 虽然 _personDapperRepository 是 Person,但 dynamic 是运行后判断类型,此处 OK
        {
            var people = _personDapperRepository.Query("select * from AbpUsers");

            return(people);
        }