/// <summary>
 /// 转换为组织机构实体
 /// </summary>
 /// <param name="dto">组织机构数据传输对象</param>
 public static Organizations ToEntity2(this OrganizationsDto dto)
 {
     if (dto == null)
     {
         return(new Organizations());
     }
     return(new Organizations(dto.Id.ToGuid(), "", 1)
     {
         MerchantId = dto.MerchantId,
         Name = dto.Name,
         Type = dto.Type,
         State = dto.State,
         IsOpen = dto.IsOpen,
         IsLeave = dto.IsLeave,
         ParentId = dto.ParentId.ToGuidOrNull(),
         Enabled = dto.Enabled.HasValue,
         SortId = dto.SortId,
         PinYin = dto.PinYin,
         CreationTime = dto.CreationTime,
         CreatorId = dto.CreatorId,
         LastModificationTime = dto.LastModificationTime,
         LastModifierId = dto.LastModifierId,
         FullPath = dto.FullPath,
         IsDeleted = dto.IsDeleted,
         OrgChargeUid = dto.OrgChargeUid,
         AddressId = dto.AddressId,
         AddressDetail = dto.AddressDetail,
         AddressName = dto.AddressName,
         Longitude = dto.Longitude,
         Latitude = dto.Latitude,
         GPSLongitude = dto.GPSLongitude,
         GPSLatitude = dto.GPSLatitude,
         Version = dto.Version,
     });
 }
 /// <summary>
 /// 转换为组织机构实体
 /// </summary>
 /// <param name="dto">组织机构数据传输对象</param>
 public static Organizations ToEntity(this OrganizationsDto dto)
 {
     if (dto == null)
     {
         return(new Organizations());
     }
     return(dto.MapTo(new Organizations(dto.Id.ToGuid(), "", 1)));
 }
 /// <summary>
 /// 转换为组织机构实体
 /// </summary>
 /// <param name="dto">组织机构数据传输对象</param>
 public static Organizations ToEntity3(this OrganizationsDto dto)
 {
     if (dto == null)
     {
         return(new Organizations());
     }
     return(OrganizationsFactory.Create(
                organizationsId: dto.Id.ToGuid(),
                merchantId: dto.MerchantId,
                name: dto.Name,
                type: dto.Type,
                state: dto.State,
                isOpen: dto.IsOpen,
                isLeave: dto.IsLeave,
                parentId: dto.ParentId.ToGuidOrNull(),
                path: dto.Path,
                level: dto.Level.Value,
                enabled: dto.Enabled.Value,
                sortId: dto.SortId.Value,
                pinYin: dto.PinYin,
                creationTime: dto.CreationTime,
                creatorId: dto.CreatorId,
                lastModificationTime: dto.LastModificationTime,
                lastModifierId: dto.LastModifierId,
                fullPath: dto.FullPath,
                isDeleted: dto.IsDeleted,
                orgChargeUid: dto.OrgChargeUid,
                addressId: dto.AddressId,
                addressDetail: dto.AddressDetail,
                addressName: dto.AddressName,
                longitude: dto.Longitude,
                latitude: dto.Latitude,
                gPSLongitude: dto.GPSLongitude,
                gPSLatitude: dto.GPSLatitude,
                version: dto.Version
                ));
 }
        public object Get(OrganizationsDto request)
        {
            var orgs = new List<OrganizationDto>();
            string query;

            if (request.CategoryId.HasValue)
            {
                //var query = string.Format("select o.*, oc.Id as OrganizationCategoryId, oc.Name as OrganizationCategoryName " +
                //                     "from Organization o " +
                //                     "left join OrganizationCategory oc " +
                //                     "on o.OrganizationCategoryId = oc.Id " +
                //                     "where o.OrganizationCategoryId = {0}", request.CategoryId);

                //orgs = Db.Select<OrganizationDto>("select * from Organization");
            }
            else
            {
                query = string.Format("select o.*, sp.Name as StateProvinceName, sp.Abbreviation as StateProvinceAbbreviation, oc.Id as OrganizationCategoryId, oc.Name as OrganizationCategoryName " +
                                     "from Organization o " +
                                     "left join StateProvince sp " +
                                     "on o.StateProvinceId = sp.Id " +
                                     "left join OrganizationCategory oc " +
                                     "on o.OrganizationCategoryId = oc.Id");

                orgs = Db.Select<OrganizationDto>(query);
            }

            foreach (var org in orgs)
            {
                var alliesCountQuery = string.Format("select count(*) from OrganizationAlly where OrganizationId = {0}", org.Id);
                org.OrganizationAlliesCount = Db.Scalar<int>(alliesCountQuery);
            }

            return new OrganizationsResponse
            {
                Organizations = orgs
            };
        }