Esempio n. 1
0
        public virtual async Task <Tax> CalculateCheckoutAttributeTaxAsync(
            CheckoutAttributeValue attributeValue,
            bool?inclusive    = null,
            Customer customer = null,
            Currency currency = null)
        {
            Guard.NotNull(attributeValue, nameof(attributeValue));

            await _db.LoadReferenceAsync(attributeValue, x => x.CheckoutAttribute);

            var attribute = attributeValue.CheckoutAttribute;

            if (attribute.IsTaxExempt)
            {
                return(new Tax(TaxRate.Zero, 0m, 0m, true, true, currency));
            }

            return(await CalculateTaxAsync(null, attributeValue.PriceAdjustment, _taxSettings.PricesIncludeTax, attribute.TaxCategoryId, inclusive, customer, currency));
        }
Esempio n. 2
0
        public virtual async Task DeleteExportProfileAsync(ExportProfile profile, bool force = false)
        {
            Guard.NotNull(profile, nameof(profile));

            if (!force && profile.IsSystemProfile)
            {
                throw new SmartException(T("Admin.DataExchange.Export.CannotDeleteSystemProfile"));
            }

            await _db.LoadCollectionAsync(profile, x => x.Deployments);

            await _db.LoadReferenceAsync(profile, x => x.Task);

            var folder      = profile.GetExportDirectory();
            var deployments = profile.Deployments.Where(x => !x.IsTransientRecord()).ToList();

            if (profile.Deployments.Any())
            {
                _db.ExportDeployments.RemoveRange(deployments);
            }

            if (profile.Task != null)
            {
                _db.TaskDescriptors.Remove(profile.Task);
            }

            _db.ExportProfiles.Remove(profile);

            await _db.SaveChangesAsync();

            if (Directory.Exists(folder)) // TODO: (mg) (core) Use IDirectory.Exists
            {
                var fs = new LocalFileSystem(folder);

                // TODO: (mg) (core) find out how to correctly use LocalFileSystem.ClearDirectory.
                // RE: If profile.GetExportDirectory() returns IDirectory, just pass it to ClearDirectory().
                IDirectory whatever = null;
                fs.ClearDirectory(whatever, true, TimeSpan.Zero);
            }
        }