Esempio n. 1
0
        public async Task <IEnumerable <Organization> > GetSubOrgs(long orgId)
        {
            var orgInfo = await _organizationRepository.GetAsync(orgId);

            var organizations = await _organizationRepository.GetAllAsync(p => p.Code.Contains(orgInfo.Code));

            return(organizations);
        }
Esempio n. 2
0
        public async Task <GetCorporationOutput> GetCorporation(long orgId)
        {
            var orgInfo = await _organizationRepository.GetAsync(orgId);

            var corporation = await _corporationRepository.SingleAsync(p => p.OrgId == orgId);

            var output = corporation.MapTo <GetCorporationOutput>();

            output = orgInfo.MapTo(output);
            return(output);
        }
Esempio n. 3
0
        public async Task <IEnumerable <Menu> > GetParents(long menuId, bool isIncludeSelf = true)
        {
            var parentMenus = new List <Menu>();
            var menu        = await _menuRepository.GetAsync(menuId);

            if (isIncludeSelf)
            {
                parentMenus.Add(menu);
            }
            return(await GetParentMenus(menu.ParentId, parentMenus));
        }
Esempio n. 4
0
 public async Task<GetCorporationOutput> GetCorporation(long orgId)
 {
     var orgInfo = await _organizationRepository.GetAsync(orgId);
     var corporation = await _corporationRepository.SingleOrDefaultAsync(p => p.OrgId == orgId);
     if (corporation == null) 
     {
         throw new BusinessException($"不存在orgid为{orgId}的公司信息");
     }
     var output = corporation.MapTo<GetCorporationOutput>();
     output = orgInfo.MapTo(output);
     return output;
 }
Esempio n. 5
0
        public async Task <UpdateMenuOutput> Update(UpdateMenuInput input)
        {
            var menu = await _menuRepository.SingleOrDefaultAsync(p => p.Id == input.Id);

            if (menu == null)
            {
                throw new BusinessException($"不存在Id为{input.Id}的菜单信息");
            }
            var permission = await _permissionRepository.GetAsync(menu.PermissionId);

            menu       = input.MapTo(menu);
            permission = input.MapTo(permission);
            using (var locker = await _lockerProvider.CreateLockAsync("UpdateMenu"))
            {
                return(await locker.Lock(async() =>
                {
                    await UnitOfWorkAsync(async(conn, trans) =>
                    {
                        await _permissionRepository.UpdateAsync(permission, conn, trans);
                        await _menuRepository.UpdateAsync(menu, conn, trans);
                    }, Connection);
                    return new UpdateMenuOutput {
                        Id = menu.Id, PermissionId = menu.PermissionId, Tips = "更新菜单成功"
                    };
                }));
            }
        }
Esempio n. 6
0
        public async Task <GetUserNormOutput> GetUserNormInfoById(long id)
        {
            var userInfo = await _userRepository.GetAsync(id);

            var userInfoOutput = userInfo.MapTo <GetUserNormOutput>();

            if (userInfoOutput.OrgId.HasValue)
            {
                userInfoOutput.DeptId   = (await GetService <IDepartmentAppService>().GetByOrgId(userInfoOutput.OrgId.Value)).Id;
                userInfoOutput.DeptName = (await GetService <IDepartmentAppService>().GetByOrgId(userInfoOutput.OrgId.Value)).Name;
            }
            if (userInfoOutput.PositionId.HasValue)
            {
                userInfoOutput.PositionName = (await GetService <IPositionAppService>().Get(userInfoOutput.PositionId.Value)).Name;
            }
            if (userInfoOutput.LastModifierUserId.HasValue)
            {
                var modifyUserInfo = await _userRepository.SingleOrDefaultAsync(p => p.Id == userInfoOutput.LastModifierUserId.Value);

                if (modifyUserInfo != null)
                {
                    userInfoOutput.LastModificationUserName = modifyUserInfo.ChineseName;
                }
            }
            userInfoOutput.Roles = (await GetUserRoles(id)).MapTo <IEnumerable <GetDisplayRoleOutput> >();
            return(userInfoOutput);
        }
Esempio n. 7
0
        public async Task UpdatePosition(UpdatePositionInput input)
        {
            var position = await _positionRepository.GetAsync(input.Id);

            var workbookAppServiceProxy = GetService <IWordbookAppService>();

            if (!await workbookAppServiceProxy.Check(new CheckWordbookInput()
            {
                WordbookCode = SystemPresetWordbookCode.Organization.PositionFunction, WordbookItemId = input.FunctionId
            }))
            {
                throw new BusinessException($"系统中不存在指定的岗位职能类型");
            }
            if (!await workbookAppServiceProxy.Check(new CheckWordbookInput()
            {
                WordbookCode = SystemPresetWordbookCode.Organization.PositionLevel, WordbookItemId = input.PositionLevelId
            }))
            {
                throw new BusinessException($"系统中不存在指定的岗位级别");
            }
            if (input.IsLeadingOfficial && !position.IsLeadingOfficial)
            {
                var positions = await _positionRepository.GetAllAsync(p => p.DeptId == position.DeptId);

                if (positions.Any(p => p.IsLeadingOfficial))
                {
                    throw new BusinessException($"该部门已经设置负责人岗位,一个部门只允许设置一个负责人岗位");
                }
            }

            position = input.MapTo(position);
            await _positionRepository.UpdateAsync(position);
        }
Esempio n. 8
0
        public async Task Update(UpdateRoleInput input)
        {
            var role = await _roleRepository.GetAsync(input.Id);

            if (input.Name != role.Name)
            {
                var exsitRole = await _roleRepository.FirstOrDefaultAsync(p => p.Name == input.Name);

                if (exsitRole != null)
                {
                    throw new BusinessException($"系统中已经存在{input.Name}的角色");
                }
            }
            role = input.MapTo(role);
            await _roleRepository.UpdateAsync(role);
        }
Esempio n. 9
0
        public async Task <string> GetUserName(int id)
        {
            var text = await GetService <IManagerService>().SayHello("");

            var userInfo = await _userRepository.GetAsync(id);

            return(await Task.FromResult <string>(text + userInfo.ChineseName));
        }
        public async Task execute_method_for_void_sqls_should_work()
        {
            int blogId = await _blogDapperRepository.InsertAndGetIdAsync(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" });

            (await _blogDapperRepository.GetAsync(blogId)).Name.ShouldBe("Oguzhan_New_Blog");
            (await _blogRepository.GetAsync(blogId)).Name.ShouldBe("Oguzhan_New_Blog");
        }
Esempio n. 11
0
        //public async Task<IEnumerable<GetUserRoleOutput>> QueryUserRoles(QueryUserRoleInput query)
        //{
        //    var userRoleOutputs = new List<GetUserRoleOutput>();

        //    var roles = await _roleRepository.GetAllAsync();
        //    if (query.UserId.HasValue && query.UserId.Value != 0)
        //    {
        //        var userInfo = await _userDomainService.GetUserNormInfoById(query.UserId.Value);

        //        foreach (var role in roles)
        //        {
        //            userRoleOutputs.Add(new GetUserRoleOutput()
        //            {
        //                RoleId = role.Id,
        //                Name = role.Name,
        //                Checked = userInfo.Roles.Any(p => p.Id == role.Id) ? CheckStatus.Checked : CheckStatus.UnChecked
        //            });
        //        }
        //    }

        //    foreach (var role in roles)
        //    {
        //        userRoleOutputs.Add(new GetUserRoleOutput()
        //        {
        //            RoleId = role.Id,
        //            Name = role.Name,
        //            Checked = CheckStatus.UnChecked
        //        });
        //    }
        //    return userRoleOutputs;
        //}

        public async Task <bool> ResetUserOrgInfo(long id)
        {
            var userInfo = await _userRepository.GetAsync(id);

            userInfo.OrgId      = null;
            userInfo.PositionId = null;
            await _userRepository.UpdateAsync(userInfo);

            return(true);
        }
Esempio n. 12
0
        public async Task Update(UpdateRoleInput input)
        {
            var role = await _roleRepository.GetAsync(input.Id);

            if (input.Name != role.Name)
            {
                var exsitRole = await _roleRepository.FirstOrDefaultAsync(p => p.Name == input.Name);

                if (exsitRole != null)
                {
                    throw new BusinessException($"系统中已经存在{input.Name}的角色");
                }
            }
            role = input.MapTo(role);
            await UnitOfWorkAsync(async (conn, trans) =>
            {
                await _roleRepository.UpdateAsync(role, conn, trans);
                //var queryOperationSql = "SELECT o.* FROM `Operation` as o LEFT JOIN Permission as p ON o.PermissionId = p.Id AND p.IsDeleted = 0 AND o.IsDeleted = 0 WHERE o.PermissionId IN @PermissionIds";

                //var operations = await conn.QueryAsync<Operation>(queryOperationSql, new { PermissionIds = input.PermissionIds }, transaction: trans);
                //if (!operations.Any(p => p.Mold == Shared.Operations.OperationMold.Query || p.Mold == Shared.Operations.OperationMold.Look))
                //{
                //    throw new BusinessException($"分配的权限至少要包含查询或是查看类型操作");
                //}
                await _rolePermissionRepository.DeleteAsync(p => p.RoleId == input.Id, conn, trans);
                foreach (var permissionId in input.PermissionIds)
                {
                    var permission = await _permissionRepository.SingleOrDefaultAsync(p => p.Id == permissionId);
                    if (permission == null)
                    {
                        throw new BusinessException($"不存在Id为{permissionId}的权限信息");
                    }
                    await _rolePermissionRepository.InsertAsync(new RolePermission()
                    {
                        PermissionId = permissionId, RoleId = input.Id
                    }, conn, trans);
                }
            }, Connection);
        }
Esempio n. 13
0
        public async Task <GetWordbookItemOutput> GetWordbookItem(long id)
        {
            var wordbookItem = await _wordbookItemRepository.GetAsync(id);

            var wordbook = await _wordbookRepository.SingleOrDefaultAsync(p => p.Id == wordbookItem.WordbookId);

            if (wordbook == null)
            {
                throw new BusinessException($"系统中不存在Id为{wordbookItem.WordbookId}的字典类型");
            }
            var wordbookItemOutput = wordbookItem.MapTo <GetWordbookItemOutput>();

            wordbookItemOutput.WordbookCode = wordbook.Code;
            return(wordbookItemOutput);
        }
Esempio n. 14
0
        public async Task <GetUserNormOutput> GetUserNormInfoById(long id)
        {
            var userInfo = await _userRepository.GetAsync(id);

            var userInfoOutput = userInfo.MapTo <GetUserNormOutput>();

            if (userInfoOutput.OrgId.HasValue)
            {
                userInfoOutput.DeptName = (await GetService <IDepartmentAppService>().GetByOrgId(userInfoOutput.OrgId.Value)).Name;
            }
            if (userInfoOutput.PositionId.HasValue)
            {
                userInfoOutput.PositionName = (await GetService <IPositionAppService>().Get(userInfoOutput.PositionId.Value)).Name;
            }
            userInfoOutput.Roles = (await GetUserRoles(id)).MapTo <IEnumerable <GetDisplayRoleOutput> >();
            return(userInfoOutput);
        }
Esempio n. 15
0
        public async Task <string> UpdateMenu(UpdateMenuInput input)
        {
            input.CheckDataAnnotations().CheckValidResult();
            var menu = await _menuRepository.SingleOrDefaultAsync(p => p.Id == input.Id);

            if (menu == null)
            {
                throw new BusinessException($"不存在Id为{input.Id}的菜单信息");
            }
            menu = input.MapTo(menu);
            var permission = await _permissionRepository.GetAsync(menu.PermissionId);

            permission.Memo = input.Memo;
            await _menuManager.UpdateMenu(menu, permission);

            return("更新菜单成功");
        }
Esempio n. 16
0
        public async Task Update(UpdateMenuInput input)
        {
            var menu = await _menuRepository.SingleOrDefaultAsync(p => p.Id == input.Id);

            if (menu == null)
            {
                throw new BusinessException($"不存在Id为{input.Id}的菜单信息");
            }
            var permission = await _permissionRepository.GetAsync(menu.PermissionId);

            menu       = input.MapTo(menu);
            permission = input.MapTo(permission);
            await UnitOfWorkAsync(async (conn, trans) => {
                await _permissionRepository.UpdateAsync(permission, conn, trans);
                await _menuRepository.UpdateAsync(menu, conn, trans);
            }, Connection);
        }
Esempio n. 17
0
        public async Task DeleteMenu(long id)
        {
            var menu = await _menuRepository.GetAsync(id);

            var childrenMenus = await _menuRepository.GetAllAsync(p => p.ParentId == id);

            if (childrenMenus.Any())
            {
                throw new BusinessException("存在子菜单,请先删除子菜单");
            }
            var rolePermissions = await _rolePermissionRepository.GetAllAsync(p => p.PerssionId == menu.PermissionId);

            if (rolePermissions.Any())
            {
                throw new BusinessException("该菜单被分配给角色,请先删除关系后再尝试");
            }
            await UnitOfWorkAsync(async (conn, trans) => {
                await _permissionRepository.DeleteAsync(p => p.Id == menu.PermissionId, conn, trans);
                await _menuRepository.DeleteAsync(menu, conn, trans);
            }, Connection);
        }
Esempio n. 18
0
        public async Task CreatePosition(CreatePositionInput input)
        {
            await CheckPosition(input);

            var position          = input.MapTo <Position>();
            var departPositionMax = (await _positionRepository.GetAllAsync(p => p.DeptId == input.DeptId)).FirstOrDefault();
            var department        = await _departmentRepository.GetAsync(input.DeptId);

            var orgInfo = await _organizationRepository.GetAsync(department.OrgId);

            var positionCode = string.Empty;

            if (departPositionMax == null)
            {
                positionCode = "1".PadLeft(HeroConstants.CodeRuleRestrain.CodeCoverBit, HeroConstants.CodeRuleRestrain.CodeCoverSymbol);
            }
            else
            {
                positionCode = (Convert.ToInt32(departPositionMax.Code.TrimStart('0')) + 1).ToString().PadLeft(HeroConstants.CodeRuleRestrain.CodeCoverBit, HeroConstants.CodeRuleRestrain.CodeCoverSymbol);
            }

            position.Code = orgInfo.Code + positionCode;
            await _positionRepository.InsertAsync(position);
        }
Esempio n. 19
0
        public async Task Update(UpdateRoleInput input)
        {
            CheckUserDefinedDataPermission(input.DataPermissionType, input.DataPermissionOrgIds);
            using (var locker = await _lockerProvider.CreateLockAsync("UpdateRole"))
            {
                await locker.Lock(async() =>
                {
                    var role = await _roleRepository.GetAsync(input.Id, false);
                    if (role.DataPermissionType == DataPermissionType.UserDefined &&
                        _session.UserId != role.CreatorUserId)
                    {
                        throw new BusinessException("自定义数据权限的角色只允许用户创建者自己修改");
                    }

                    if (input.Identification != role.Identification)
                    {
                        var exsitRole =
                            await _roleRepository.FirstOrDefaultAsync(p => p.Identification == input.Identification,
                                                                      false);
                        if (exsitRole != null)
                        {
                            throw new BusinessException($"系统中已经存在{input.Identification}的角色");
                        }
                    }

                    role = input.MapTo(role);
                    await UnitOfWorkAsync(async(conn, trans) =>
                    {
                        await _roleRepository.UpdateAsync(role, conn, trans);
                        var deleteSql = "DELETE FROM RolePermission WHERE RoleId=@RoleId AND TenantId=@TenantId";
                        await conn.ExecuteAsync(deleteSql, new { RoleId = role.Id, TenantId = _session.TenantId }, trans);
                        await _rolePermissionRepository.DeleteAsync(p => p.RoleId == role.Id, conn, trans);
                        await _roleDataPermissionOrgRelationRepository.DeleteAsync(p => p.RoleId == role.Id, conn,
                                                                                   trans);
                        await _roleOrganizationRepository.DeleteAsync(p => p.RoleId == role.Id, conn, trans);
                        var insertSql =
                            "INSERT INTO RolePermission(PermissionId,RoleId,CreateTime,CreateBy,TenantId) VALUES(@PermissionId,@RoleId,@CreationTime,@CreatorUserId,@TenantId)";
                        var rolePermissions = new List <RolePermission>();
                        foreach (var permissionId in input.PermissionIds)
                        {
                            rolePermissions.Add(new RolePermission
                            {
                                PermissionId  = permissionId,
                                RoleId        = role.Id,
                                CreationTime  = DateTime.Now,
                                CreatorUserId = _session.UserId,
                                TenantId      = _session.TenantId
                            });
                        }
                        await conn.ExecuteAsync(insertSql, rolePermissions, trans);
                        if (!input.IsAllOrg)
                        {
                            foreach (var orgId in input.OrgIds)
                            {
                                var roleOrg = new RoleOrganization()
                                {
                                    RoleId = role.Id, OrgId = orgId
                                };
                                await _roleOrganizationRepository.InsertAsync(roleOrg, conn, trans);
                            }
                        }

                        if (input.DataPermissionType == DataPermissionType.UserDefined)
                        {
                            var insertDataPermissionOrgSql =
                                "INSERT INTO RoleDataPermissionOrgRelation(RoleId,OrgId,CreateTime,CreateBy,TenantId) VALUES(@RoleId,@OrgId,@CreationTime,@CreatorUserId,@TenantId)";
                            var dataPermissionOrgDatas = new List <RoleDataPermissionOrgRelation>();
                            foreach (var orgId in input.DataPermissionOrgIds)
                            {
                                dataPermissionOrgDatas.Add(new RoleDataPermissionOrgRelation()
                                {
                                    RoleId        = role.Id,
                                    OrgId         = orgId,
                                    CreationTime  = DateTime.Now,
                                    CreatorUserId = _session.UserId,
                                    TenantId      = _session.TenantId
                                });
                            }

                            await conn.ExecuteAsync(insertDataPermissionOrgSql, dataPermissionOrgDatas, trans);
                        }

                        await RemoveRoleCheckPemissionCache(role.Id);
                    }, Connection);
                });
            }
        }
Esempio n. 20
0
        public async virtual Task <TEntityDto> Get(TPrimaryKey id)
        {
            var entity = await Repository.GetAsync(id);

            return(MapToEntityDto(entity));
        }
Esempio n. 21
0
 public async Task <UserInfo> GetUserInfoByUserId(long userId)
 {
     return(await _userRepository.GetAsync(userId));
 }
Esempio n. 22
0
        public async Task <UpdateDepartmentOutput> UpdateDepartment(UpdateDepartmentInput input)
        {
            var department = await _departmentRepository.SingleOrDefaultAsync(p => p.Id == input.Id);

            if (department == null)
            {
                throw new BusinessException($"系统中不存在Id为{input.Id}的部门信息");
            }
            var orgInfo = await _organizationRepository.SingleOrDefaultAsync(p => p.Id == department.OrgId);

            if (orgInfo == null)
            {
                throw new BusinessException($"系统中不存在Id为{department.Id}的部门信息");
            }

            if (!input.Identification.Equals(orgInfo.Identification))
            {
                var exsitOrg =
                    await _organizationRepository.FirstOrDefaultAsync(p => p.Identification == input.Identification);

                if (exsitOrg != null)
                {
                    throw new BusinessException($"系统中已经存在标识为{input.Identification}的组织机构");
                }
            }

            if (input.DeptTypeKey.IsNullOrEmpty())
            {
                throw new BusinessException("请选择部门类型");
            }

            var workbookAppServiceProxy = GetService <IWordbookAppService>();
            var checkDeptTypeResult     = await workbookAppServiceProxy.Check(new CheckWordbookInput
                                                                              { WordbookCode = SystemPresetWordbookCode.Organization.DeptType, WordbookItemKey = input.DeptTypeKey });

            if (!checkDeptTypeResult)
            {
                throw new BusinessException("部门类型Id不正确,请选择正确的部门类型");
            }
            department = input.MapTo(department);
            orgInfo    = input.MapTo(orgInfo);
            Debug.Assert(_session.UserId.HasValue, "登录用户的UserId不会为空");
            await UnitOfWorkAsync(async (conn, trans) =>
            {
                await _organizationRepository.UpdateAsync(orgInfo, conn, trans);
                await _departmentRepository.UpdateAsync(department, conn, trans);

                if (input.Positions != null && input.Positions.Any())
                {
                    if (input.Positions.Count(p => p.IsLeadingOfficial) > 1)
                    {
                        throw new BusinessException("部门只允许设置一个负责人岗位");
                    }
                    var positionIds       = input.Positions.Where(p => p.Id != 0 && p.Id.HasValue).Select(p => p.Id);
                    var deletePositionSql =
                        "UPDATE `Position` SET IsDeleted=@IsDeleted,DeleteBy=@DeleteBy,DeleteTime=@DeleteTime WHERE DeptId=@DeptId AND Id NOT in @Id AND TenantId=@TenantId";
                    await conn.ExecuteAsync(deletePositionSql,
                                            new
                    {
                        IsDeleted  = HeroConstants.DeletedFlag, DeleteBy = _session.UserId.Value,
                        DeleteTime = DateTime.Now, DeptId = department.Id, Id = positionIds,
                        TenantId   = _session.TenantId
                    }, trans);
                    var sort = 1;
                    foreach (var positionInput in input.Positions)
                    {
                        var positionCode = orgInfo.Code + HeroConstants.CodeRuleRestrain.CodeSeparator + sort.ToString()
                                           .PadLeft(HeroConstants.CodeRuleRestrain.CodeCoverBit,
                                                    HeroConstants.CodeRuleRestrain.CodeCoverSymbol);
                        if (positionInput.Id.HasValue && positionInput.Id != 0)
                        {
                            var position = await _positionRepository.GetAsync(positionInput.Id.Value);
                            position.CheckDataAnnotations().CheckValidResult();
                            position      = positionInput.MapTo(position);
                            position.Code = positionCode;
                            await _positionRepository.UpdateAsync(position, conn, trans);
                        }
                        else
                        {
                            var position    = positionInput.MapTo <Position>();
                            position.DeptId = department.Id;
                            position.CheckDataAnnotations().CheckValidResult();
                            position.Code = positionCode;
                            await _positionRepository.InsertAsync(position, conn, trans);
                        }

                        sort++;
                    }
                }
            }, Connection);

            return(new UpdateDepartmentOutput
            {
                OrgId = orgInfo.Id,
                DeptId = department.Id,
                Tips = "更新部门信息成功"
            });
        }
        public async Task Dapper_Repository_Tests()
        {
            using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin())
            {
                //---Insert operation should work and tenant, creation audit properties must be set---------------------
                await _productDapperRepository.InsertAsync(new Product("TShirt"));

                Product insertedProduct = await _productDapperRepository.FirstOrDefaultAsync(x => x.Name == "TShirt");

                insertedProduct.ShouldNotBeNull();
                insertedProduct.TenantId.ShouldBe(AbpSession.TenantId);
                ((DateTime?)insertedProduct.CreationTime).ShouldNotBe(null);
                insertedProduct.CreatorUserId.ShouldBe(AbpSession.UserId);

                //----Update operation should work and Modification Audits should be set---------------------------
                await _productDapperRepository.InsertAsync(new Product("TShirt"));

                Product productToUpdate = await _productDapperRepository.FirstOrDefaultAsync(x => x.Name == "TShirt");

                productToUpdate.Name = "Pants";
                await _productDapperRepository.UpdateAsync(productToUpdate);

                productToUpdate.ShouldNotBeNull();
                productToUpdate.TenantId.ShouldBe(AbpSession.TenantId);
                ((DateTime?)productToUpdate.CreationTime).ShouldNotBe(null);
                productToUpdate.LastModifierUserId.ShouldBe(AbpSession.UserId);

                //---Get method should return single-------------------------------------------------------------------
                await _productDapperRepository.InsertAsync(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---------------------------------
                var queryResult = await _productDapperRepository.QueryAsync("select * from Products");

                IEnumerable <Product> products = queryResult;

                products.Count().ShouldBeGreaterThan(0);

                //------------Ef and Dapper should work under same transaction---------------------
                Product productFromEf = await _productRepository.FirstOrDefaultAsync(x => x.Name == "TShirt");

                Product productFromDapper = await _productDapperRepository.SingleAsync(productFromEf.Id);

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

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

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

                await _productDapperRepository.DeleteAsync(toSoftDeleteProduct);

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

                Product softDeletedProduct = await _productRepository
                                             .FirstOrDefaultAsync(x => x.Name == "SoftDeletableProduct");

                softDeletedProduct.ShouldBeNull();

                Product softDeletedProductFromDapper = await _productDapperRepository
                                                       .FirstOrDefaultAsync(x => x.Name == "SoftDeletableProduct");

                softDeletedProductFromDapper.ShouldBeNull();

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

                    softDeletedProductWhenFilterDisabled.ShouldNotBeNull();

                    Product softDeletedProductFromDapperWhenFilterDisabled = await _productDapperRepository
                                                                             .SingleAsync(x => x.Name == "SoftDeletableProduct");

                    softDeletedProductFromDapperWhenFilterDisabled.ShouldNotBeNull();
                }

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

                    var productWithTenant2 = await _productRepository.GetAsync(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 = await _productDapperRepository
                                               .InsertAndGetIdAsync(new Product("ProductWithTenant3"));

                    Product productWithTenant3 = await _productRepository.GetAsync(productWithTenant3Id);

                    productWithTenant3.TenantId.ShouldBe(3);
                }

                Product productWithTenantId3FromDapper = await _productDapperRepository
                                                         .FirstOrDefaultAsync(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 = await _productDapperRepository
                                                                              .FirstOrDefaultAsync(x => x.Name == "ProductWithTenant3");

                    productWithTenantId3FromDapperInsideTenantScope.ShouldNotBeNull();
                }

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

                    Product productWithTenant40 = await _productRepository.GetAsync(productWithTenantId40);

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

                //Second DbContext tests
                var productDetailId = await _productDetailRepository
                                      .InsertAndGetIdAsync(new ProductDetail("Woman"));

                (await _productDetailDapperRepository.GetAsync(productDetailId)).ShouldNotBeNull();

                await uow.CompleteAsync();
            }
        }
Esempio n. 24
0
        public async Task <GetPositionOutput> Get(long id)
        {
            var position = await _positionRepository.GetAsync(id);

            return(position.MapTo <GetPositionOutput>());
        }
Esempio n. 25
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;
            }
        }
Esempio n. 26
0
 public Task <UserInfo> GetAsync(int userId)
 {
     return(_userDapperRepository.GetAsync(userId));
 }