public ResponseBo <List <PersonRelationListBo> > GetList(PersonRelationGetListCriteriaBo criteriaBo)
        {
            ResponseBo <List <PersonRelationListBo> > responseBo = new ResponseBo <List <PersonRelationListBo> >();

            try
            {
                using (SqlConnection conn = DbAccess.Connection.GetConn())
                {
                    var p = new DynamicParameters();
                    p.Add("@Message", dbType: DbType.String, direction: ParameterDirection.Output, size: 255);
                    p.Add("@IsSuccess", dbType: DbType.Boolean, direction: ParameterDirection.Output);

                    p.Add("@PersonId", criteriaBo.PersonId, DbType.Int64, ParameterDirection.Input);
                    p.Add("@CurrencyId", criteriaBo.CurrencyId, DbType.Int32, ParameterDirection.Input);

                    p.Add("@RelationTypeIdList", criteriaBo.RelationTypeIdList.ToStrSeparated(), DbType.String, ParameterDirection.Input, 255);
                    p.Add("@LanguageId", criteriaBo.Session.RealPerson.LanguageId, DbType.Int32, ParameterDirection.Input);

                    p.Add("@IsOppositeOperation", criteriaBo.IsOppositeOperation, DbType.Boolean, ParameterDirection.Input);
                    p.Add("@SearchRelationTypeOpp", criteriaBo.SearchRelationTypeOpp, DbType.Boolean, ParameterDirection.Input);
                    p.Add("@OperatorRealId", criteriaBo.Session.RealPerson.Id, DbType.Int64, ParameterDirection.Input);

                    p.Add("@Name", criteriaBo.Name, DbType.String, ParameterDirection.Input, 50);

                    p.Add("@PageOffSet", criteriaBo.PageOffSet, DbType.Int32, ParameterDirection.Input);

                    p.Add("@PersonRelationId", criteriaBo.PersonRelationId, DbType.Int64, ParameterDirection.Input);

                    p.Add("@BalanceStatIdList", criteriaBo.BalanceStatIdList.ToStrSeparated(), DbType.String, ParameterDirection.Input, 50);

                    responseBo.Bo        = conn.Query <PersonRelationListBo>("spPersonRelationList", p, commandType: CommandType.StoredProcedure).ToList();
                    responseBo.Message   = p.Get <string>("@Message");
                    responseBo.IsSuccess = p.Get <bool>("@IsSuccess");
                }
            }
            catch (Exception ex)
            {
                responseBo = base.SaveExLog(ex, this.GetType(), MethodBase.GetCurrentMethod().Name, criteriaBo).ToResponse <List <PersonRelationListBo> >();
            }

            return(responseBo);
        }
        public static SessionMyPerson GetMyPerson(PersonChangeMyPersonDto myPersonDto, Session session)
        {
            // Getting my person //
            // Code below must return just one row.
            PersonRelationBusiness          personRelationBusiness = new PersonRelationBusiness();
            PersonRelationGetListCriteriaBo criteriaBo             = new PersonRelationGetListCriteriaBo();

            criteriaBo.PersonId         = session.RealPerson.Id;
            criteriaBo.PersonRelationId = myPersonDto.PersonRelationId;
            criteriaBo.CurrencyId       = myPersonDto.DefaultCurrencyId;
            criteriaBo.Session          = session;
            PersonRelationListBo myPersonRelationBo = personRelationBusiness.GetList(criteriaBo).Bo[0];

            SessionMyPerson myPerson = new SessionMyPerson();

            myPerson.Id                 = myPersonDto.MyPersonId;
            myPerson.FullName           = myPersonRelationBo.RelatedPersonFullName;
            myPerson.PersonTypeId       = myPersonRelationBo.RelatedPersonTypeId;
            myPerson.RelationTypeId     = myPersonRelationBo.RelationTypeId;
            myPerson.DefaultCurrencyId  = myPersonRelationBo.RelatedPersonDefaultCurrencyId;
            myPerson.SelectedCurrencyId = myPerson.DefaultCurrencyId;

            return(myPerson);
        }
        public ResponseDto <List <PersonRelationListDto> > GetList(PersonRelationGetListCriteriaDto criteriaDto)
        {
            PersonRelationGetListCriteriaBo criteriaBo = new PersonRelationGetListCriteriaBo()
            {
                PersonId              = criteriaDto.PersonId,
                RelationTypeIdList    = criteriaDto.RelationTypeIdList,
                IsOppositeOperation   = criteriaDto.IsOppositeOperation,
                SearchRelationTypeOpp = criteriaDto.SearchRelationTypeOpp,
                CurrencyId            = criteriaDto.CurrencyId,

                Name = criteriaDto.Name.IsNull() ? null : criteriaDto.Name.Trim(),

                PageOffSet = criteriaDto.PageOffSet,

                PersonRelationId = criteriaDto.PersonRelationId,

                BalanceStatIdList = criteriaDto.BalanceStatIdList,

                Session = Session
            };

            criteriaBo.Name = criteriaBo.Name.IsNull() ? null : criteriaBo.Name;
            if (criteriaBo.Name != null)
            {
                criteriaBo.Name = criteriaBo.Name.Trim();
            }

            ResponseBo <List <PersonRelationListBo> > responseBo = personRelationBusiness.GetList(criteriaBo);

            ResponseDto <List <PersonRelationListDto> > responseDto = responseBo.ToResponseDto <List <PersonRelationListDto>, List <PersonRelationListBo> >();

            if (responseBo.IsSuccess && responseBo.Bo != null)
            {
                responseDto.Dto = new List <PersonRelationListDto>();

                responseDto.Dto = responseBo.Bo.GroupBy(x => x.RelatedPersonId).Select(x => x.First()).
                                  Select(
                    x => new PersonRelationListDto()
                {
                    Id = x.Id,
                    RelatedPersonId                = x.RelatedPersonId,
                    RelatedPersonTypeId            = x.RelatedPersonTypeId,
                    RelatedPersonFullName          = x.RelatedPersonFullName,
                    RelatedPersonDefaultCurrencyId = x.RelatedPersonDefaultCurrencyId,
                    RelatedPersonUrlName           = x.RelatedPersonUrlName,

                    IsMaster = x.IsMaster,
                    IsAlone  = x.IsAlone,

                    Balance       = x.Balance,
                    BalanceStatId = x.BalanceStatId,

                    //ApprovalStatId = x.ApprovalStatId,

                    //RelationTypeIdList = responseBo.Bo.Where(y => y.RelatedPersonId == x.RelatedPersonId).Select(y => y.RelationTypeId).ToList(),

                    RelationSubList = (from y in responseBo.Bo
                                       where y.RelatedPersonId == x.RelatedPersonId
                                       select new PersonRelationSubListDto
                    {
                        PersonRelationId = y.Id,
                        ApprovalStatId = y.ApprovalStatId,
                        RelationTypeId = y.RelationTypeId,
                        ApprovalRelationId = y.ApprovalRelationId
                    }).ToList()
                }).ToList();


                // responseDto.Dto = Business.Stc.EnumShopTypeList.
                //GroupBy(x => x.GroupId).Select(x => x.First()).
                //Select(
                //x => new ShopTypeGroupDto()
                //{
                //    Id = x.GroupId,
                //    Name = x.GroupName,
                //    TypeList = Business.Stc.EnumShopTypeList.Where(y => y.GroupId == x.GroupId).Select(
                //        y => new ShopTypeDto()
                //        {
                //            Id = y.Id,
                //            Name = y.TypeName
                //        }).ToList()
                //}).ToList();

                //foreach (PersonRelationListBo itemBo in responseBo.Bo)
                //{

                //    responseDto.Dto.Add(new PersonRelationListDto()
                //    {
                //        Id = itemBo.Id,
                //        RelatedPersonId = itemBo.RelatedPersonId,
                //        RelatedPersonTypeId = itemBo.RelatedPersonTypeId,
                //        RelatedPersonFullName = itemBo.RelatedPersonFullName,
                //        IsMaster = itemBo.IsMaster,

                //        RelationTypeId = itemBo.RelationTypeId,
                //        RelationStateId = itemBo.RelationStateId
                //    });
                //}
            }

            return(responseDto);
        }