Esempio n. 1
0
        /// <summary>
        /// Gets a collection of all shipments with the option to pass an array of shipment keys
        /// </summary>
        /// <param name="keys">
        /// The keys.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IShipment}"/>.
        /// </returns>
        protected override IEnumerable <IShipment> PerformGetAll(params Guid[] keys)
        {
            var dtos = new List <ShipmentDto>();

            if (keys.Any())
            {
                // This is to get around the WhereIn max limit of 2100 parameters and to help with performance of each WhereIn query
                var keyLists = keys.Split(400).ToList();

                // Loop the split keys and get them
                foreach (var keyList in keyLists)
                {
                    dtos.AddRange(Database.Fetch <ShipmentDto, ShipmentStatusDto>(GetBaseQuery(false).WhereIn <ShipmentDto>(x => x.Key, keyList, SqlSyntax)));
                }
            }
            else
            {
                dtos = Database.Fetch <ShipmentDto, ShipmentStatusDto>(GetBaseQuery(false));
            }

            var factory = new ShipmentFactory();

            foreach (var dto in dtos)
            {
                var shipment = factory.BuildEntity(dto);
                ((Shipment)shipment).Items = this.GetLineItems(dto.Key);
                yield return(shipment);
            }

            //if (keys.Any())
            //{
            //    foreach (var key in keys)
            //    {
            //        yield return Get(key);
            //    }
            //}
            //else
            //{
            //    var factory = new ShipmentFactory();
            //    var dtos = Database.Fetch<ShipmentDto, ShipmentStatusDto>(GetBaseQuery(false));
            //    foreach (var dto in dtos)
            //    {
            //        yield return this.Get(dto.Key);
            //    }
            //}
        }
Esempio n. 2
0
        protected override IShipment PerformGet(Guid key)
        {
            var sql = GetBaseQuery(false)
                      .Where(GetBaseWhereClause(), new { Key = key });

            var dto = Database.Fetch <ShipmentDto>(sql).FirstOrDefault();

            if (dto == null)
            {
                return(null);
            }

            var factory = new ShipmentFactory();

            var shipment = factory.BuildEntity(dto);

            return(shipment);
        }
Esempio n. 3
0
 protected override IEnumerable <IShipment> PerformGetAll(params Guid[] keys)
 {
     if (keys.Any())
     {
         foreach (var key in keys)
         {
             yield return(Get(key));
         }
     }
     else
     {
         var factory = new ShipmentFactory();
         var dtos    = Database.Fetch <ShipmentDto>(GetBaseQuery(false));
         foreach (var dto in dtos)
         {
             yield return(factory.BuildEntity(dto));
         }
     }
 }