public ResponseBo <PersonProductBo> Get(PersonProductGetCriteriaBo criteriaBo)
        {
            ResponseBo <PersonProductBo> responseBo = new ResponseBo <PersonProductBo>();

            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("@PersonProductId", criteriaBo.PersonProductId, DbType.Int64, ParameterDirection.Input);

                    p.Add("@ProductId", criteriaBo.ProductId, DbType.Int64, ParameterDirection.Input);
                    p.Add("@ProductCode", criteriaBo.ProductCode, DbType.String, ParameterDirection.Input, 50);

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

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

                    p.Add("@MyPersonId", criteriaBo.Session.MyPerson.Id, DbType.Int64, ParameterDirection.Input);
                    p.Add("@OperatorRealId", criteriaBo.Session.RealPerson.Id, DbType.Int64, ParameterDirection.Input);
                    p.Add("@LanguageId", criteriaBo.Session.RealPerson.LanguageId, DbType.Int32, ParameterDirection.Input);

                    responseBo.Bo        = conn.Query <PersonProductBo>("spPersonProductGet", p, commandType: CommandType.StoredProcedure).FirstOrDefault();
                    responseBo.Message   = p.Get <string>("@Message");
                    responseBo.IsSuccess = p.Get <bool>("@IsSuccess");

                    if (responseBo.Bo != null)
                    {
                        if (responseBo.Bo.CodeListRawJson.IsNotNull())
                        {
                            responseBo.Bo.CodeList = JsonConvert.DeserializeObject <List <ProductCodeBo> >(responseBo.Bo.CodeListRawJson);
                        }

                        if (responseBo.Bo.PriceRawJson.IsNotNull())
                        {
                            responseBo.Bo.Price = JsonConvert.DeserializeObject <ProductPriceBo>(responseBo.Bo.PriceRawJson);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                responseBo = base.SaveExLog(ex, this.GetType(), MethodBase.GetCurrentMethod().Name, criteriaBo).ToResponse <PersonProductBo>();
            }

            return(responseBo);
        }
        public ResponseDto <PersonProductDto> Get(PersonProductGetCriteriaDto criteriaDto)
        {
            PersonProductGetCriteriaBo criteriaBo = new PersonProductGetCriteriaBo()
            {
                PersonProductId = criteriaDto.PersonProductId,

                ProductId   = criteriaDto.ProductId,
                ProductCode = criteriaDto.ProductCode,

                PersonId = criteriaDto.PersonId,

                CurrencyId = criteriaDto.CurrencyId,

                Session = Session
            };

            ResponseBo <PersonProductBo> responseBo = personProductBusiness.Get(criteriaBo);

            if (criteriaBo.ProductCode != null && criteriaBo.ProductId == null && responseBo.IsSuccess && responseBo.Bo == null)
            {
                using (ProductController productController = new ProductController(new ProductBusiness()))
                {
                    ResponseDto t_responseDto = productController.AddFromExternalSource(criteriaBo.ProductCode, Session, Session.MyPerson.Id);

                    if (t_responseDto.IsSuccess)
                    {
                        responseBo = personProductBusiness.Get(criteriaBo);
                    }
                }
            }

            ResponseDto <PersonProductDto> responseDto = responseBo.ToResponseDto <PersonProductDto, PersonProductBo>();

            if (responseBo.IsSuccess && responseBo.Bo != null)
            {
                responseDto.Dto = new PersonProductDto()
                {
                    Id = responseBo.Bo.Id,
                    PurchaseVatRate = responseBo.Bo.PurchaseVatRate,
                    SaleVatRate     = responseBo.Bo.SaleVatRate,
                    CategoryId      = responseBo.Bo.CategoryId,
                    Balance         = responseBo.Bo.Balance,

                    ProductId     = responseBo.Bo.ProductId,
                    ProductName   = responseBo.Bo.ProductName,
                    ProductTypeId = responseBo.Bo.ProductTypeId,

                    PortraitImageUniqueIdStr = responseBo.Bo.PortraitImageUniqueId == null ? null : responseBo.Bo.PortraitImageUniqueId.ToStringNull().ToUpperNull()
                                               + "." + responseBo.Bo.PortraitImageFileTypeId.ToStringNull().ToLowerNull(),

                    // itemBo.CodeList should not be null
                    // at least there must be an item that contaions product Id value.
                    CodeList = (from pc in responseBo.Bo.CodeList
                                select new ProductCodeDto
                    {
                        Code = pc.Code,
                        ProductCodeTypeId = pc.ProductCodeTypeId
                    }).ToList(),

                    // itemBo.PriceList should not be null
                    // every product must have price in every currency.
                    // if a price was not specified in given currency, bussiness will convert the price to given currency.
                    Price = new ProductPriceDto
                    {
                        PurhasePrice    = responseBo.Bo.Price.PurhasePrice,
                        SalePrice       = responseBo.Bo.Price.SalePrice,
                        OnlineSalePrice = responseBo.Bo.Price.OnlineSalePrice,

                        CurrencyId = responseBo.Bo.Price.CurrencyId,

                        FromPool = responseBo.Bo.Price.FromPool
                    }
                };
            }

            return(responseDto);
        }