예제 #1
0
        /// <summary>
        /// Creates a note and saves it to the database
        /// </summary>
        /// <param name="entityKey">
        /// The entity key.
        /// </param>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="INote"/>.
        /// </returns>
        public INote CreateNoteWithKey(Guid entityKey, Guid entityTfKey, string message, bool raiseEvents = true)
        {
            var note = CreateNote(entityKey, entityTfKey, message, raiseEvents);

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <INote>(note), this))
                {
                    ((Note)note).WasCancelled = true;
                    return(note);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateNoteRepository(uow))
                {
                    repository.AddOrUpdate(note);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <INote>(note), this);

            return(note);
        }
예제 #2
0
        /// <summary>
        /// Creates a <see cref="IProductVariant"/> of the <see cref="IProduct"/> passed defined by the collection of <see cref="IProductAttribute"/>
        /// </summary>
        /// <param name="product">The <see cref="IProduct"/></param>
        /// <param name="name">The name of the product variant</param>
        /// <param name="sku">The unique sku of the product variant</param>
        /// <param name="price">The price of the product variant</param>
        /// <param name="attributes">The <see cref="IProductVariant"/></param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns>Either a new <see cref="IProductVariant"/> or, if one already exists with associated attributes, the existing <see cref="IProductVariant"/></returns>
        public IProductVariant CreateProductVariantWithKey(IProduct product, string name, string sku, decimal price, ProductAttributeCollection attributes, bool raiseEvents = true)
        {
            var productVariant = CreateProductVariant(product, name, sku, price, attributes);

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IProductVariant>(productVariant), this))
                {
                    ((ProductVariant)productVariant).WasCancelled = true;
                    return(productVariant);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateProductVariantRepository(uow))
                {
                    repository.AddOrUpdate(productVariant);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IProductVariant>(productVariant), this);
            }

            product.ProductVariants.Add(productVariant);

            return(productVariant);
        }
예제 #3
0
        /// <summary>
        /// Creates an <see cref="IMedia"/> object using the alias of the <see cref="IMediaType"/>
        /// that this Media should based on.
        /// </summary>
        /// <remarks>
        /// This method returns an <see cref="IMedia"/> object that has been persisted to the database
        /// and therefor has an identity.
        /// </remarks>
        /// <param name="name">Name of the Media object</param>
        /// <param name="parent">Parent <see cref="IMedia"/> for the new Media item</param>
        /// <param name="mediaTypeAlias">Alias of the <see cref="IMediaType"/></param>
        /// <param name="userId">Optional id of the user creating the media item</param>
        /// <returns><see cref="IMedia"/></returns>
        public IMedia CreateMediaWithIdentity(string name, IMedia parent, string mediaTypeAlias, int userId = 0)
        {
            var mediaType = FindMediaTypeByAlias(mediaTypeAlias);
            var media     = new Models.Media(name, parent, mediaType);

            if (Creating.IsRaisedEventCancelled(new NewEventArgs <IMedia>(media, mediaTypeAlias, parent), this))
            {
                media.WasCancelled = true;
                return(media);
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateMediaRepository(uow))
                {
                    media.CreatorId = userId;
                    repository.AddOrUpdate(media);
                    uow.Commit();

                    var xml = media.ToXml();
                    CreateAndSaveMediaXml(xml, media.Id, uow.Database);
                }
            }

            Created.RaiseEvent(new NewEventArgs <IMedia>(media, false, mediaTypeAlias, parent), this);

            Audit.Add(AuditTypes.New, "", media.CreatorId, media.Id);

            return(media);
        }
예제 #4
0
        /// <summary>
        /// Creates a <see cref="IOrder"/> without saving it to the database
        /// </summary>
        /// <param name="orderStatusKey">
        /// The <see cref="IOrderStatus"/> key
        /// </param>
        /// <param name="invoiceKey">
        /// The invoice key
        /// </param>
        /// <param name="orderNumber">
        /// The order Number.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IOrder"/>.
        /// </returns>
        /// <remarks>
        /// Order number must be a positive integer value or zero
        /// </remarks>
        public IOrder CreateOrder(Guid orderStatusKey, Guid invoiceKey, int orderNumber, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(!Guid.Empty.Equals(orderStatusKey), "orderStatusKey");
            Mandate.ParameterCondition(!Guid.Empty.Equals(invoiceKey), "invoiceKey");
            Mandate.ParameterCondition(orderNumber >= 0, "orderNumber must be greater than or equal to 0");

            var status = GetOrderStatusByKey(orderStatusKey);

            var order = new Order(status, invoiceKey)
            {
                VersionKey  = Guid.NewGuid(),
                OrderNumber = orderNumber,
                OrderDate   = DateTime.Now
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IOrder>(order), this))
                {
                    order.WasCancelled = true;
                    return(order);
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IOrder>(order), this);
            }

            return(order);
        }
예제 #5
0
        /// <summary>
        /// Creates an <see cref="IOfferRedeemed"/> record
        /// </summary>
        /// <param name="offerSettings">
        /// The offer settings.
        /// </param>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IOfferRedeemed"/>.
        /// </returns>
        public IOfferRedeemed CreateOfferRedeemedWithKey(IOfferSettings offerSettings, IInvoice invoice, bool raiseEvents = true)
        {
            var redemption = new OfferRedeemed(
                offerSettings.OfferCode,
                offerSettings.OfferProviderKey,
                invoice.Key,
                offerSettings.Key);

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IOfferRedeemed>(redemption), this))
                {
                    redemption.WasCancelled = true;
                    return(redemption);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateOfferRedeemedRepository(uow))
                {
                    repository.AddOrUpdate(redemption);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IOfferRedeemed>(redemption), this);
            }

            return(redemption);
        }
예제 #6
0
        /// <summary>
        /// Creates and saves a <see cref="IProduct"/> to the database
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="sku">
        /// The SKU.
        /// </param>
        /// <param name="price">
        /// The price.
        /// </param>
        /// <returns>
        /// The <see cref="IProduct"/>.
        /// </returns>
        public IProduct CreateProductWithKey(string name, string sku, decimal price)
        {
            var templateVariant = new ProductVariant(name, sku, price);
            var product         = new Product(templateVariant);

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IProduct>(product), this))
            {
                product.WasCancelled = true;
                return(product);
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateProductRepository(uow))
                {
                    repository.AddOrUpdate(product);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <IProduct>(product), this);

            return(product);
        }
        /// <summary>
        /// Creates a <see cref="IProductOption"/> without saving it to the database.
        /// </summary>
        /// <param name="name">
        /// The option name.
        /// </param>
        /// <param name="shared">
        /// A value indicating whether or not this is a shared option (usable by multiple products).
        /// </param>
        /// <param name="required">
        /// The required.
        /// </param>
        /// <param name="raiseEvents">
        ///  Optional boolean indicating whether or not to raise events.
        /// </param>
        /// <returns>
        /// The <see cref="IProductOption"/>.
        /// </returns>
        public IProductOption CreateProductOption(string name, bool shared = false, bool required = true, bool raiseEvents = true)
        {
            var option = new ProductOption(name)
            {
                UseName  = name,
                Shared   = shared,
                Required = required
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IProductOption>(option), this))
                {
                    option.WasCancelled = true;
                    return(option);
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IProductOption>(option), this);
            }

            return(option);
        }
예제 #8
0
        /// <summary>
        /// Creates and saves a payment
        /// </summary>
        /// <param name="paymentTfKey">The payment typefield key</param>
        /// <param name="amount">The amount of the payment</param>
        /// <param name="paymentMethodKey">The optional paymentMethodKey</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns>Returns <see cref="IPayment"/></returns>
        internal IPayment CreatePaymentWithKey(Guid paymentTfKey, decimal amount, Guid?paymentMethodKey, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(!Guid.Empty.Equals(paymentTfKey), "paymentTfKey");


            var payment = new Payment(paymentTfKey, amount, paymentMethodKey, new ExtendedDataCollection());

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IPayment>(payment), this))
                {
                    payment.WasCancelled = true;
                    return(payment);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreatePaymentRepository(uow))
                {
                    repository.AddOrUpdate(payment);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IPayment>(payment), this);
            }

            return(payment);
        }
예제 #9
0
        /// <summary>
        /// Creates a customer and saves the record to the database
        /// </summary>
        /// <param name="loginName">
        /// The login Name.
        /// </param>
        /// <param name="firstName">
        /// The first name of the customer
        /// </param>
        /// <param name="lastName">
        /// The last name of the customer
        /// </param>
        /// <param name="email">
        /// the email address of the customer
        /// </param>
        /// <returns>
        /// <see cref="ICustomer"/>
        /// </returns>
        public ICustomer CreateCustomerWithKey(string loginName, string firstName, string lastName, string email)
        {
            Mandate.ParameterNotNullOrEmpty(loginName, "loginName");

            var customer = new Customer(loginName)
            {
                FirstName = firstName,
                LastName  = lastName,
                Email     = email
            };

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <ICustomer>(customer), this))
            {
                customer.WasCancelled = true;
                return(customer);
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateCustomerRepository(uow))
                {
                    repository.AddOrUpdate(customer);
                    uow.Commit();
                }
            }

            SaveAddresses(customer);

            Created.RaiseEvent(new Events.NewEventArgs <ICustomer>(customer), this);

            return(customer);
        }
예제 #10
0
        /// <summary>
        /// Creates an audit record and saves it to the database
        /// </summary>
        /// <param name="entityKey">
        /// The entity key.
        /// </param>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="extendedData">
        /// The extended data.
        /// </param>
        /// <param name="isError">
        /// Designates whether or not this is an error log record
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IAuditLog"/>.
        /// </returns>
        public IAuditLog CreateAuditLogWithKey(Guid?entityKey, Guid?entityTfKey, string message, ExtendedDataCollection extendedData, bool isError = false, bool raiseEvents = true)
        {
            var auditLog = new AuditLog()
            {
                EntityKey    = entityKey,
                EntityTfKey  = entityTfKey,
                Message      = message,
                ExtendedData = extendedData,
                IsError      = isError
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IAuditLog>(auditLog), this))
                {
                    auditLog.WasCancelled = true;
                    return(auditLog);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateAuditLogRepository(uow))
                {
                    repository.AddOrUpdate(auditLog);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <IAuditLog>(auditLog), this);

            return(auditLog);
        }
예제 #11
0
        /// <summary>
        /// Creates a customer and saves the record to the database
        /// </summary>
        /// <param name="firstName">The first name of the customer</param>
        /// <param name="lastName">The last name of the customer</param>
        /// <param name="email">the email address of the customer</param>
        /// <param name="memberId">The Umbraco member Id of the customer</param>
        /// <returns><see cref="ICustomer"/></returns>
        internal ICustomer CreateCustomerWithKey(string firstName, string lastName, string email, int?memberId = null)
        {
            var customer = new Customer(0, 0, null)
            {
                FirstName = firstName,
                LastName  = lastName,
                Email     = email,
                MemberId  = memberId
            };

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <ICustomer>(customer), this))
            {
                customer.WasCancelled = true;
                return(customer);
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateCustomerRepository(uow))
                {
                    repository.AddOrUpdate(customer);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <ICustomer>(customer), this);

            return(customer);
        }
예제 #12
0
        /// <summary>
        /// Creates a <see cref="IInvoice"/> without saving it to the database
        /// </summary>
        /// <param name="invoiceStatusKey">The <see cref="IInvoiceStatus"/> key</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns><see cref="IInvoice"/></returns>
        public IInvoice CreateInvoice(Guid invoiceStatusKey, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(Guid.Empty != invoiceStatusKey, "invoiceStatusKey");

            var status = GetInvoiceStatusByKey(invoiceStatusKey);

            var invoice = new Invoice(status)
            {
                VersionKey  = Guid.NewGuid(),
                InvoiceDate = DateTime.Now
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IInvoice>(invoice), this))
                {
                    invoice.WasCancelled = true;
                    return(invoice);
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IInvoice>(invoice), this);
            }

            return(invoice);
        }
예제 #13
0
        /// <summary>
        /// Creates a <see cref="IDigitalMedia"/> and saves it to the database.
        /// </summary>
        /// <param name="productVariantKey">
        /// Tkey for the item to work
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IDigitalMedia"/>.
        /// </returns>
        public IDigitalMedia CreateDigitalMediaForProductVariant(Guid productVariantKey, bool raiseEvents = true)
        {
            var digitalMedia = new DigitalMedia()
            {
                FirstAccessed     = null,
                ProductVariantKey = productVariantKey
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IDigitalMedia>(digitalMedia), this))
                {
                    digitalMedia.WasCancelled = true;
                    return(digitalMedia);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateDigitalMediaRepository(uow))
                {
                    repository.AddOrUpdate(digitalMedia);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IDigitalMedia>(digitalMedia), this);
            }

            return(digitalMedia);
        }
예제 #14
0
        /// <summary>
        /// Creates a Product without saving it to the database
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="sku">
        /// The SKU.
        /// </param>
        /// <param name="price">
        /// The price.
        /// </param>
        /// <returns>
        /// The <see cref="IProduct"/>.
        /// </returns>
        public IProduct CreateProduct(string name, string sku, decimal price)
        {
            var templateVariant = new ProductVariant(name, sku, price);
            var product         = new Product(templateVariant);

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IProduct>(product), this))
            {
                product.WasCancelled = true;
                return(product);
            }

            Created.RaiseEvent(new Events.NewEventArgs <IProduct>(product), this);

            return(product);
        }
예제 #15
0
        /// <summary>
        /// The create ship country with key.
        /// </summary>
        /// <param name="warehouseCatalogKey">
        /// The warehouse catalog key.
        /// </param>
        /// <param name="country">
        /// The country.
        /// </param>
        /// <param name="raiseEvents">
        /// The raise events.
        /// </param>
        /// <returns>
        /// The <see cref="Attempt"/>.
        /// </returns>
        internal Attempt <IShipCountry> CreateShipCountryWithKey(Guid warehouseCatalogKey, ICountry country, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(warehouseCatalogKey != Guid.Empty, "warehouseCatalog");
            if (country == null)
            {
                return(Attempt <IShipCountry> .Fail(new ArgumentNullException("country")));
            }

            var shipCountry = new ShipCountry(warehouseCatalogKey, country);

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IShipCountry>(shipCountry), this))
                {
                    shipCountry.WasCancelled = true;
                    return(Attempt <IShipCountry> .Fail(shipCountry));
                }
            }

            // verify that a ShipCountry does not already exist for this pair

            var sc = GetShipCountriesByCatalogKey(warehouseCatalogKey).FirstOrDefault(x => x.CountryCode.Equals(country.CountryCode));

            if (sc != null)
            {
                return
                    (Attempt <IShipCountry> .Fail(
                         new ConstraintException("A ShipCountry with CountryCode '" + country.CountryCode +
                                                 "' is already associate with this WarehouseCatalog")));
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateShipCountryRepository(uow, _storeSettingService))
                {
                    repository.AddOrUpdate(shipCountry);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IShipCountry>(shipCountry), this);
            }

            return(Attempt <IShipCountry> .Succeed(shipCountry));
        }
예제 #16
0
        /// <summary>
        /// The create entity collection.
        /// </summary>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="providerKey">
        /// The provider key.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IEntityCollection"/>.
        /// </returns>
        internal IEntityCollection CreateEntityCollection(Guid entityTfKey, Guid providerKey, string name, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(!Guid.Empty.Equals(entityTfKey), "entityTfKey");
            Mandate.ParameterCondition(!Guid.Empty.Equals(providerKey), "providerKey");
            var collection = new EntityCollection(entityTfKey, providerKey)
            {
                Name = name
            };

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IEntityCollection>(collection), this))
            {
                collection.WasCancelled = true;
                return(collection);
            }

            return(collection);
        }
예제 #17
0
        /// <summary>
        /// Creates a <see cref="IShipMethod"/>.  This is useful due to the data constraint
        /// preventing two ShipMethods being created with the same ShipCountry and ServiceCode for any provider.
        /// </summary>
        /// <param name="providerKey">
        /// The unique gateway provider key (GUID)
        /// </param>
        /// <param name="shipCountry">
        /// The <see cref="IShipCountry"/> this ship method is to be associated with
        /// </param>
        /// <param name="name">
        /// The required name of the <see cref="IShipMethod"/>
        /// </param>
        /// <param name="serviceCode">
        /// The ShipMethods service code
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="Attempt"/>.
        /// </returns>
        internal Attempt <IShipMethod> CreateShipMethodWithKey(Guid providerKey, IShipCountry shipCountry, string name, string serviceCode, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(providerKey != Guid.Empty, "providerKey");
            Mandate.ParameterNotNull(shipCountry, "shipCountry");
            Mandate.ParameterNotNullOrEmpty(name, "name");
            Mandate.ParameterNotNullOrEmpty(serviceCode, "serviceCode");

            if (ShipMethodExists(providerKey, shipCountry.Key, serviceCode))
            {
                return(Attempt <IShipMethod> .Fail(new ConstraintException("A Shipmethod already exists for this ShipCountry with this ServiceCode")));
            }

            var shipMethod = new ShipMethod(providerKey, shipCountry.Key)
            {
                Name        = name,
                ServiceCode = serviceCode,
                Provinces   = shipCountry.Provinces.ToShipProvinceCollection()
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IShipMethod>(shipMethod), this))
                {
                    shipMethod.WasCancelled = true;
                    return(Attempt <IShipMethod> .Fail(shipMethod));
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateShipMethodRepository(uow))
                {
                    repository.AddOrUpdate(shipMethod);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IShipMethod>(shipMethod), this);
            }

            return(Attempt <IShipMethod> .Succeed(shipMethod));
        }
예제 #18
0
        /// <summary>
        /// Attempts to create a <see cref="IPaymentMethod"/> for a given provider.  If the provider already
        /// defines a paymentCode, the creation fails.
        /// </summary>
        /// <param name="providerKey">The unique 'key' (Guid) of the TaxationGatewayProvider</param>
        /// <param name="name">The name of the payment method</param>
        /// <param name="description">The description of the payment method</param>
        /// <param name="paymentCode">The unique 'payment code' associated with the payment method.  (Eg. visa, mc)</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns><see cref="Attempt"/> indicating whether or not the creation of the <see cref="IPaymentMethod"/> with respective success or fail</returns>
        internal Attempt <IPaymentMethod> CreatePaymentMethodWithKey(Guid providerKey, string name, string description, string paymentCode, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(!Guid.Empty.Equals(providerKey), "providerKey");
            Mandate.ParameterNotNullOrEmpty(name, "name");
            Mandate.ParameterNotNullOrEmpty(paymentCode, "paymentCode");

            if (GetPaymentMethodByPaymentCode(providerKey, paymentCode) != null)
            {
                return(Attempt <IPaymentMethod> .Fail(new ConstraintException("A PaymentMethod already exists for the provider for the paymentCode '" + paymentCode + "'")));
            }

            var paymentMethod = new PaymentMethod(providerKey)
            {
                Name        = name,
                Description = description,
                PaymentCode = paymentCode
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IPaymentMethod>(paymentMethod), this))
                {
                    paymentMethod.WasCancelled = true;
                    return(Attempt <IPaymentMethod> .Fail(paymentMethod));
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreatePaymentMethodRepository(uow))
                {
                    repository.AddOrUpdate(paymentMethod);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IPaymentMethod>(paymentMethod), this);
            }

            return(Attempt <IPaymentMethod> .Succeed(paymentMethod));
        }
예제 #19
0
        /// <summary>
        /// Creates a customer without saving to the database
        /// </summary>
        /// <param name="loginName">The login name of the customer.</param>
        /// <param name="firstName">The first name of the customer</param>
        /// <param name="lastName">The last name of the customer</param>
        /// <param name="email">the email address of the customer</param>
        /// <returns>The <see cref="ICustomer"/></returns>
        public ICustomer CreateCustomer(string loginName, string firstName, string lastName, string email)
        {
            Mandate.ParameterNotNullOrEmpty(loginName, "loginName");
            var customer = new Customer(loginName)
            {
                FirstName = firstName,
                LastName  = lastName,
                Email     = email
            };

            if (!Creating.IsRaisedEventCancelled(new Events.NewEventArgs <ICustomer>(customer), this))
            {
                return(customer);
            }

            customer.WasCancelled = true;

            return(customer);
        }
예제 #20
0
        /// <summary>
        /// Creates an <see cref="IMedia"/> object using the alias of the <see cref="IMediaType"/>
        /// that this Media is based on.
        /// </summary>
        /// <param name="name">Name of the Media object</param>
        /// <param name="parent">Parent <see cref="IMedia"/> for the new Media item</param>
        /// <param name="mediaTypeAlias">Alias of the <see cref="IMediaType"/></param>
        /// <param name="userId">Optional id of the user creating the media item</param>
        /// <returns><see cref="IMedia"/></returns>
        public IMedia CreateMedia(string name, IMedia parent, string mediaTypeAlias, int userId = 0)
        {
            IMediaType mediaType;

            var uow = _uowProvider.GetUnitOfWork();

            using (var repository = _repositoryFactory.CreateMediaTypeRepository(uow))
            {
                var query = Query <IMediaType> .Builder.Where(x => x.Alias == mediaTypeAlias);

                var mediaTypes = repository.GetByQuery(query);

                if (!mediaTypes.Any())
                {
                    throw new Exception(string.Format("No MediaType matching the passed in Alias: '{0}' was found",
                                                      mediaTypeAlias));
                }

                mediaType = mediaTypes.First();

                if (mediaType == null)
                {
                    throw new Exception(string.Format("MediaType matching the passed in Alias: '{0}' was null",
                                                      mediaTypeAlias));
                }
            }

            var media = new Models.Media(name, parent, mediaType);

            if (Creating.IsRaisedEventCancelled(new NewEventArgs <IMedia>(media, mediaTypeAlias, parent), this))
            {
                media.WasCancelled = true;
                return(media);
            }

            media.CreatorId = userId;

            Created.RaiseEvent(new NewEventArgs <IMedia>(media, false, mediaTypeAlias, parent), this);

            Audit.Add(AuditTypes.New, "", media.CreatorId, media.Id);

            return(media);
        }
예제 #21
0
        /// <summary>
        /// Creates an <see cref="IMedia"/> object using the alias of the <see cref="IMediaType"/>
        /// that this Media should based on.
        /// </summary>
        /// <remarks>
        /// Note that using this method will simply return a new IMedia without any identity
        /// as it has not yet been persisted. It is intended as a shortcut to creating new media objects
        /// that does not invoke a save operation against the database.
        /// </remarks>
        /// <param name="name">Name of the Media object</param>
        /// <param name="parent">Parent <see cref="IMedia"/> for the new Media item</param>
        /// <param name="mediaTypeAlias">Alias of the <see cref="IMediaType"/></param>
        /// <param name="userId">Optional id of the user creating the media item</param>
        /// <returns><see cref="IMedia"/></returns>
        public IMedia CreateMedia(string name, IMedia parent, string mediaTypeAlias, int userId = 0)
        {
            var mediaType = FindMediaTypeByAlias(mediaTypeAlias);
            var media     = new Models.Media(name, parent, mediaType);

            if (Creating.IsRaisedEventCancelled(new NewEventArgs <IMedia>(media, mediaTypeAlias, parent), this))
            {
                media.WasCancelled = true;
                return(media);
            }

            media.CreatorId = userId;

            Created.RaiseEvent(new NewEventArgs <IMedia>(media, false, mediaTypeAlias, parent), this);

            Audit.Add(AuditTypes.New, "", media.CreatorId, media.Id);

            return(media);
        }
예제 #22
0
        /// <summary>
        /// Creates a <see cref="INotificationMessage"/> and saves it to the database
        /// </summary>
        /// <param name="methodKey">The <see cref="INotificationMethod"/> key</param>
        /// <param name="name">The name of the message (primarily used in the back office UI)</param>
        /// <param name="description">The name of the message (primarily used in the back office UI)</param>
        /// <param name="fromAddress">The senders or "from" address</param>
        /// <param name="recipients">A collection of recipient address</param>
        /// <param name="bodyText">The body text of the message</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns>Attempt{INotificationMessage}</returns>
        public Attempt <INotificationMessage> CreateNotificationMethodWithKey(Guid methodKey, string name, string description, string fromAddress,
                                                                              IEnumerable <string> recipients, string bodyText, bool raiseEvents = true)
        {
            var recipientArray = recipients as string[] ?? recipients.ToArray();

            Mandate.ParameterCondition(methodKey != Guid.Empty, "methodKey");
            Mandate.ParameterNotNullOrEmpty(name, "name");
            Mandate.ParameterNotNullOrEmpty(fromAddress, "fromAddress");

            var message = new NotificationMessage(methodKey, name, fromAddress)
            {
                Description = description,
                BodyText    = bodyText,
                Recipients  = string.Join(",", recipientArray)
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <INotificationMessage>(message), this))
                {
                    message.WasCancelled = true;
                    return(Attempt <INotificationMessage> .Fail(message));
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateNotificationMessageRepository(uow))
                {
                    repository.AddOrUpdate(message);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <INotificationMessage>(message), this);
            }

            return(Attempt <INotificationMessage> .Succeed(message));
        }
예제 #23
0
        /// <summary>
        /// Creates a payment without saving it to the database
        /// </summary>
        /// <param name="paymentMethodType">The type of the payment method</param>
        /// <param name="amount">The amount of the payment</param>
        /// <param name="paymentMethodKey">The optional payment method Key</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns>Returns <see cref="IPayment"/></returns>
        public IPayment CreatePayment(PaymentMethodType paymentMethodType, decimal amount, Guid?paymentMethodKey, bool raiseEvents = true)
        {
            var payment = new Payment(paymentMethodType, amount, paymentMethodKey);

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IPayment>(payment), this))
                {
                    payment.WasCancelled = true;
                    return(payment);
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IPayment>(payment), this);
            }

            return(payment);
        }
예제 #24
0
        /// <summary>
        /// Creates a note without saving it to the database.
        /// </summary>
        /// <param name="entityKey">
        /// The entity Key.
        /// </param>
        /// <param name="entityTfKey">
        /// The entity Type field Key.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="raiseEvents">
        /// The raise events.
        /// </param>
        /// <returns>
        /// The <see cref="INote"/>.
        /// </returns>
        public INote CreateNote(Guid entityKey, Guid entityTfKey, string message, bool raiseEvents = true)
        {
            var note = new Note(entityKey, entityTfKey)
            {
                Message = message
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <INote>(note), this))
                {
                    note.WasCancelled = true;
                    return(note);
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <INote>(note), this);

            return(note);
        }
예제 #25
0
        /// <summary>
        /// The create tax method with key.
        /// </summary>
        /// <param name="providerKey">
        /// The provider key.
        /// </param>
        /// <param name="country">
        /// The country.
        /// </param>
        /// <param name="percentageTaxRate">
        /// The percentage tax rate.
        /// </param>
        /// <param name="raiseEvents">
        /// The raise events.
        /// </param>
        /// <returns>
        /// The <see cref="Attempt"/>.
        /// </returns>
        internal Attempt <ITaxMethod> CreateTaxMethodWithKey(Guid providerKey, ICountry country, decimal percentageTaxRate, bool raiseEvents = true)
        {
            if (CountryTaxRateExists(providerKey, country.CountryCode))
            {
                return(Attempt <ITaxMethod> .Fail(new ConstraintException("A TaxMethod already exists for the provider for the countryCode '" + country.CountryCode + "'")));
            }

            var taxMethod = new TaxMethod(providerKey, country.CountryCode)
            {
                Name = country.CountryCode == "ELSE" ? "Everywhere Else" : country.Name,
                PercentageTaxRate = percentageTaxRate,
                Provinces         = country.Provinces.ToTaxProvinceCollection()
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <ITaxMethod>(taxMethod), this))
                {
                    taxMethod.WasCancelled = false;
                    return(Attempt <ITaxMethod> .Fail(taxMethod));
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateTaxMethodRepository(uow))
                {
                    repository.AddOrUpdate(taxMethod);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <ITaxMethod>(taxMethod), this);
            }

            return(Attempt <ITaxMethod> .Succeed(taxMethod));
        }
예제 #26
0
        /// <summary>
        /// Creates a <see cref="IOrder"/> and saves it to the database
        /// </summary>
        /// <param name="orderStatusKey">The <see cref="IOrderStatus"/> key</param>
        /// <param name="invoiceKey"></param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns><see cref="IOrder"/></returns>
        public IOrder CreateOrderWithKey(Guid orderStatusKey, Guid invoiceKey, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(!Guid.Empty.Equals(orderStatusKey), "orderStatusKey");
            Mandate.ParameterCondition(!Guid.Empty.Equals(invoiceKey), "invoiceKey");

            var status = GetOrderStatusByKey(orderStatusKey);

            var order = new Order(status, invoiceKey)
            {
                VersionKey = Guid.NewGuid(),
                OrderDate  = DateTime.Now
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IOrder>(order), this))
                {
                    order.WasCancelled = true;
                    return(order);
                }
            }


            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateOrderRepository(uow))
                {
                    repository.AddOrUpdate(order);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IOrder>(order), this);
            }

            return(order);
        }
예제 #27
0
        /// <summary>
        /// Creates a basket for a consumer with a given type
        /// </summary>
        /// <param name="customer">
        /// The customer.
        /// </param>
        /// <param name="itemCacheType">
        /// The item Cache Type.
        /// </param>
        /// <param name="versionKey">
        /// The version Key.
        /// </param>
        /// <returns>
        /// The <see cref="IItemCache"/>.
        /// </returns>
        public IItemCache GetItemCacheWithKey(ICustomerBase customer, ItemCacheType itemCacheType, Guid versionKey)
        {
            Mandate.ParameterCondition(Guid.Empty != versionKey, "versionKey");

            // determine if the consumer already has a item cache of this type, if so return it.
            var itemCache = GetItemCacheByCustomer(customer, itemCacheType);

            if (itemCache != null)
            {
                return(itemCache);
            }

            itemCache = new ItemCache(customer.Key, itemCacheType)
            {
                VersionKey = versionKey
            };

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IItemCache>(itemCache), this))
            {
                // registry.WasCancelled = true;
                return(itemCache);
            }

            itemCache.EntityKey = customer.Key;

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateItemCacheRepository(uow))
                {
                    repository.AddOrUpdate(itemCache);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <IItemCache>(itemCache), this);

            return(itemCache);
        }
예제 #28
0
        /// <summary>
        /// Creates a store setting and persists it to the database
        /// </summary>
        /// <param name="name">The settings name</param>
        /// <param name="value">The settings value</param>
        /// <param name="typeName">The type name</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns><see cref="IStoreSetting"/></returns>
        public IStoreSetting CreateStoreSettingWithKey(string name, string value, string typeName, bool raiseEvents)
        {
            Mandate.ParameterNotNullOrEmpty(name, "name");
            Mandate.ParameterNotNullOrEmpty(value, "value");
            Mandate.ParameterNotNullOrEmpty(typeName, "typeName");

            var storeSetting = new StoreSetting()
            {
                Name     = name,
                Value    = value,
                TypeName = typeName
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IStoreSetting>(storeSetting), this))
                {
                    storeSetting.WasCancelled = true;
                    return(storeSetting);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateStoreSettingRepository(uow))
                {
                    repository.AddOrUpdate(storeSetting);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IStoreSetting>(storeSetting), this);
            }

            return(storeSetting);
        }
예제 #29
0
        /// <summary>
        /// Creates warehouse catalog and persists it to the database.
        /// </summary>
        /// <param name="warehouseKey">
        /// The warehouse key.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="description">
        /// The description.
        /// </param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns>
        /// The <see cref="IWarehouseCatalog"/>.
        /// </returns>
        public IWarehouseCatalog CreateWarehouseCatalogWithKey(
            Guid warehouseKey,
            string name,
            string description = "",
            bool raiseEvents   = true)
        {
            Mandate.ParameterCondition(!warehouseKey.Equals(Guid.Empty), "warehouseKey");

            var catalog = new WarehouseCatalog(warehouseKey)
            {
                Name = name, Description = description
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IWarehouseCatalog>(catalog), this))
                {
                    catalog.WasCancelled = true;
                    return(catalog);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateWarehouseCatalogRepository(uow))
                {
                    repository.AddOrUpdate(catalog);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IWarehouseCatalog>(catalog), this);
            }

            return(catalog);
        }
예제 #30
0
        /// <summary>
        /// The create applied payment with key.
        /// </summary>
        /// <param name="paymentKey">
        /// The payment key.
        /// </param>
        /// <param name="invoiceKey">
        /// The invoice key.
        /// </param>
        /// <param name="appliedPaymentTfKey">
        /// The applied payment tf key.
        /// </param>
        /// <param name="description">
        /// The description.
        /// </param>
        /// <param name="amount">
        /// The amount.
        /// </param>
        /// <param name="raiseEvents">
        /// The raise events.
        /// </param>
        /// <returns>
        /// The <see cref="IAppliedPayment"/>.
        /// </returns>
        internal IAppliedPayment CreateAppliedPaymentWithKey(Guid paymentKey, Guid invoiceKey, Guid appliedPaymentTfKey, string description, decimal amount, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(!Guid.Empty.Equals(paymentKey), "paymentKey");
            Mandate.ParameterCondition(!Guid.Empty.Equals(invoiceKey), "invoiceKey");
            Mandate.ParameterCondition(!Guid.Empty.Equals(appliedPaymentTfKey), "appliedPaymentTfKey");

            var appliedPayment = new AppliedPayment(paymentKey, invoiceKey, appliedPaymentTfKey)
            {
                Description = description,
                Amount      = amount,
                Exported    = false
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IAppliedPayment>(appliedPayment), this))
                {
                    appliedPayment.WasCancelled = true;
                    return(appliedPayment);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateAppliedPaymentRepository(uow))
                {
                    repository.AddOrUpdate(appliedPayment);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IAppliedPayment>(appliedPayment), this);
            }

            return(appliedPayment);
        }