Ejemplo n.º 1
0
        /// <summary>
        /// Gets all <see cref="IShipCountry"/>.
        /// </summary>
        /// <param name="keys">
        /// The keys.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IShipCountry}"/>.
        /// </returns>
        protected override IEnumerable <IShipCountry> PerformGetAll(params Guid[] keys)
        {
            var dtos = new List <ShipCountryDto>();

            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 <ShipCountryDto>(GetBaseQuery(false).WhereIn <ShipCountryDto>(x => x.Key, keyList, SqlSyntax)));
                }
            }
            else
            {
                dtos = Database.Fetch <ShipCountryDto>(GetBaseQuery(false));
            }

            var factory = new ShipCountryFactory(_storeSettingService);

            foreach (var dto in dtos)
            {
                yield return(factory.BuildEntity(dto));
            }
        }
        /// <summary>
        /// Updates an existing item in the database.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        protected override void PersistUpdatedItem(IShipCountry entity)
        {
            ((Entity)entity).UpdatingEntity();

            var factory = new ShipCountryFactory(_storeSettingService);

            var dto = factory.BuildDto(entity);

            Database.Update(dto);

            entity.ResetDirtyProperties();
        }
        /// <summary>
        /// Gets a <see cref="IShipCountry"/> by it's key.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <returns>
        /// The <see cref="IShipCountry"/>.
        /// </returns>
        protected override IShipCountry PerformGet(Guid key)
        {
            var sql = GetBaseQuery(false)
                      .Where(GetBaseWhereClause(), new { Key = key });

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

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

            var factory = new ShipCountryFactory(_storeSettingService);

            return(factory.BuildEntity(dto));
        }
 /// <summary>
 /// Gets all <see cref="IShipCountry"/>.
 /// </summary>
 /// <param name="keys">
 /// The keys.
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{IShipCountry}"/>.
 /// </returns>
 protected override IEnumerable <IShipCountry> PerformGetAll(params Guid[] keys)
 {
     if (keys.Any())
     {
         foreach (var key in keys)
         {
             yield return(Get(key));
         }
     }
     else
     {
         var factory = new ShipCountryFactory(_storeSettingService);
         var dtos    = Database.Fetch <ShipCountryDto>(GetBaseQuery(false));
         foreach (var dto in dtos)
         {
             yield return(factory.BuildEntity(dto));
         }
     }
 }
        /// <summary>
        /// Saves a new item to the database.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        protected override void PersistNewItem(IShipCountry entity)
        {
            // TODO : revisit how this constraint is implemented
            // Assert that a ShipCountry for a given WarehouseCatalog does not already exist with this country code
            if (Exists(entity.CatalogKey, entity.CountryCode))
            {
                throw new ConstraintException("A merchShipCountry record already exists with the CatalogKey and CountryCode");
            }

            ((Entity)entity).AddingEntity();

            var factory = new ShipCountryFactory(_storeSettingService);
            var dto     = factory.BuildDto(entity);

            Database.Insert(dto);

            entity.Key = dto.Key;

            entity.ResetDirtyProperties();
        }