private SaleEntity ReadSaleInternal(string command, object param = null)
        {
            using (IGridReader reader = QueryMultiple(command, param))
            {
                SaleEntity sale = reader.Read <SaleEntity, ShippingEntity, AddressEntity, SaleEntity>((s, sh, a) =>
                {
                    s.Delivery = new Delivery();

                    if (sh != null)
                    {
                        s.Delivery.Shipping = sh;
                    }
                    else
                    {
                        s.Delivery.DeliveryType = DeliveryType.PickUpOnly;
                    }

                    s.Delivery.DeliveryAddress = a;

                    return(s);
                }, splitOn: "ShippingId,AddressId").First();

                sale.Items = reader.Read <SaleItemEntity>().ToList();

                return(sale);
            }
        }
 public CategoryEntity Read(int categoryId)
 {
     using (IGridReader reader = QueryMultiple("dbo.SPReadCategory", new { categoryId }))
     {
         CategoryEntity category = reader.Read <CategoryEntity>().SingleOrDefault();
         category.Thumb = reader.Read <FileEntity>().FirstOrDefault();
         return(category);
     }
 }
 public SaleEntity FindSale(string query)
 {
     using (IGridReader reader = QueryMultiple("dbo.SPFindSale", new { query = ToSqlSafe(query) }))
     {
         SaleEntity sale = reader.Read <SaleEntity>().First();
         sale.Items = reader.Read <SaleItemEntity>();
         return(sale);
     }
 }
Exemple #4
0
        /// <summary>
        /// Returns multiple recordsets for the provided types.
        /// </summary>
        /// <typeparam name="TFirst"></typeparam>
        /// <typeparam name="TSecond"></typeparam>
        /// <param name="sqlQuery"></param>
        /// <param name="sqlText"></param>
        /// <param name="onExecute"></param>
        /// <returns></returns>
        public static IEnumerable <IEnumerable> QueryMultiple <TFirst, TSecond>(this ISqlQuery sqlQuery, SqlText sqlText, Action <IDbConnection> onExecute = null)
        {
            using (IGridReader gridReader = sqlQuery.QueryMultiple(sqlText.Sql(), sqlText.Parameters, commandType: CommandType.Text, onExecute: onExecute))
            {
                yield return(gridReader.Read <TFirst>());

                yield return(gridReader.Read <TSecond>());
            }
        }
        private void QueryMultipleTest <T1, T2, T3, T4>(T1 value1, T2 value2, T3 value3 = default(T3), T4 value4 = default(T4))
        {
            // set-up
            ISqlQuery   sqlQuery   = A.Fake <ISqlQuery>();
            SqlText     sqlText    = A.Fake <SqlText>();
            IGridReader gridReader = A.Fake <IGridReader>();

            if (value1 != null)
            {
                A.CallTo(() => gridReader.Read <T1>()).Returns(new[] { value1 });
            }

            if (value2 != null)
            {
                A.CallTo(() => gridReader.Read <T2>()).Returns(new[] { value2 });
            }

            if (value3 != null)
            {
                A.CallTo(() => gridReader.Read <T3>()).Returns(new[] { value3 });
            }

            if (value4 != null)
            {
                A.CallTo(() => gridReader.Read <T4>()).Returns(new[] { value4 });
            }

            A.CallTo(() => sqlQuery.QueryMultiple(A <string> .Ignored, A <ParameterCollection> .Ignored, CommandType.Text, A <int?> .Ignored, A <Action <IDbConnection> > .Ignored)).Returns(gridReader);

            IEnumerable <IEnumerable> result;

            // call and assert

            if (value4 != null)
            {
                result = sqlQuery.QueryMultiple <T1, T2, T3, T4>(sqlText);
                ((IEnumerable <T1>)result.First()).First().MustBe(value1);
                ((IEnumerable <T2>)result.Skip(1).First()).First().MustBe(value2);
                ((IEnumerable <T3>)result.Skip(2).First()).First().MustBe(value3);
                ((IEnumerable <T4>)result.Skip(3).First()).First().MustBe(value4);
            }
            else if (value3 != null)
            {
                result = sqlQuery.QueryMultiple <T1, T2, T3>(sqlText);
                ((IEnumerable <T1>)result.First()).First().MustBe(value1);
                ((IEnumerable <T2>)result.Skip(1).First()).First().MustBe(value2);
                ((IEnumerable <T3>)result.Skip(2).First()).First().MustBe(value3);
            }
            else
            {
                result = sqlQuery.QueryMultiple <T1, T2>(sqlText);
                ((IEnumerable <T1>)result.First()).First().MustBe(value1);
                ((IEnumerable <T2>)result.Skip(1).First()).First().MustBe(value2);
            }
        }
Exemple #6
0
        /// <summary>
        /// Returns multiple recordsets for the provided types.
        /// </summary>
        /// <typeparam name="TFirst"></typeparam>
        /// <typeparam name="TSecond"></typeparam>
        /// <typeparam name="TThird"></typeparam>
        /// <param name="sqlQuery"></param>
        /// <param name="sqlText"></param>
        /// <returns></returns>
        public static IEnumerable <IEnumerable> QueryMultiple <TFirst, TSecond, TThird>(this ISqlQuery sqlQuery, SqlText sqlText)
        {
            using (IGridReader gridReader = sqlQuery.QueryMultiple(sqlText.Sql(), sqlText.Parameters, commandType: CommandType.Text))
            {
                yield return(gridReader.Read <TFirst>());

                yield return(gridReader.Read <TSecond>());

                yield return(gridReader.Read <TThird>());
            }
        }
        public ProductEntity Read(int productId)
        {
            using (IGridReader reader = QueryMultiple("dbo.SPReadProduct", new { productId }, onExecute: connection => LicenseHelper.SetContext(connection, DataContext.LicenseSettings)))
            {
                ProductEntity product = reader.Read <ProductEntity, ProductOptionEntity, ProductDetailEntity, CategoryEntity, FileEntity, ProductEntity>((p, o, d, c, f) => { p.MinOption = o; p.MinOption.Detail = d; p.Category = c; p.Thumb = f; return(p); }, splitOn: "ProductOptionId,ProductDetailId,CategoryId,FileId")
                                        .SingleOrDefault();

                if (product != null)
                {
                    product.Options  = new ModelCollection <ProductOptionEntity>(reader.Read <ProductOptionEntity, ProductDetailEntity, ProductOptionEntity>((o, d) => { o.Detail = d; return(o); }, splitOn: "ProductDetailId"));
                    product.MetaData = new MetaCollection(reader.Read <MetaEntity>());
                    product.Files    = new ModelCollection <FileEntity>(reader.Read <FileEntity>());
                }

                return(product);
            }
        }
        public void QueryPage_gets_count_from_data_count_when_includeCount_is_false()
        {
            // set-up
            ISqlQuery   sqlQuery   = A.Fake <ISqlQuery>();
            Select      select     = new Select(includeCount: false);
            IGridReader gridReader = A.Fake <IGridReader>();
            DateTime    now        = DateTime.Now;

            A.CallTo(() => gridReader.Read <DateTime>()).Returns(new[] { now });
            A.CallTo(() => gridReader.Read <int>()).Returns(new[] { 5 });
            A.CallTo(() => sqlQuery.QueryMultiple(select.Sql(), select.Parameters, CommandType.Text, A <int?> .Ignored, A <Action <IDbConnection> > .Ignored)).Returns(gridReader);

            // call
            DataPage <DateTime> dataPage = sqlQuery.QueryPage <DateTime>(select);

            // assert
            dataPage.Count.MustBe(1);
            dataPage.Data.First().MustBe(now);
        }
Exemple #9
0
        public TPropertyContact ReadPropertyContact <TPropertyContact, TAddress, TMarker>(int contactId)
            where TPropertyContact : PropertyContactEntity
            where TAddress : AddressEntity, new()
            where TMarker : Marker
        {
            const string commandName = "dbo.SPReadPropertyContact";

            using (IGridReader reader = QueryMultiple(commandName, new { contactId }))
            {
                TPropertyContact propertyContact = reader.Read <TPropertyContact, TAddress, TMarker, TPropertyContact>((p, a, m) =>
                {
                    p.Address        = a ?? new TAddress();
                    p.Address.Marker = m;
                    return(p);
                }, splitOn: "AddressId,Latitude").SingleOrDefault();

                propertyContact.MetaData = new MetaCollection(reader.Read <MetaEntity>());

                return(propertyContact);
            }
        }
Exemple #10
0
        private TProperty Read <TProperty, TAddress, TMarker>(IGridReader reader)
            where TProperty : IProperty
            where TAddress : AddressEntity, new()
            where TMarker : Marker
        {
            const string splitOn = "AddressId,Latitude,BranchGuid,DevelopmentId";

            TProperty property = reader.Read <TProperty, TAddress, TMarker, PropertyBranch, DevelopmentEntity, TProperty>((p, a, m, b, d) =>
            {
                p.Address        = a ?? new TAddress();
                p.Address.Marker = m;
                p.Branch         = b;
                p.Development    = d;
                return(p);
            }, splitOn: splitOn).SingleOrDefault();

            if (property != null)
            {
                property.Files = reader.Read <FileEntity>().ToList();

                // nasty hack here.  we have confusion over whether to use the iproperty.branchguid property or the nested one.  this makes sure they are both in sync
                // need to fix :!

                if (property.Branch != null && property.Branch.BranchGuid != property.BranchGuid)
                {
                    property.BranchGuid = property.Branch.BranchGuid;
                }

                if (property.Development != null && property.Development.DevelopmentId != property.DevelopmentId)
                {
                    property.DevelopmentId = property.Development.DevelopmentId;
                }
            }

            return(property);
        }
Exemple #11
0
        public ViewGridResponse Execute()
        {
            var cellValues = EmptyGrid();
            var grid       = _persistence.Read();

            for (int i = 0; i < cellValues.Length; i++)
            {
                if (grid.IsThereAnXInPosition(i))
                {
                    cellValues[i] = X;
                }
                if (grid.IsThereAnOInPosition(i))
                {
                    cellValues[i] = O;
                }
            }

            return(new ViewGridResponse
            {
                Grid = cellValues
            });
        }