/// <summary> /// Saves a single entity collection. /// </summary> /// <param name="entityCollection"> /// The entity collection. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Save(IEntityCollection entityCollection, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IEntityCollection>(entityCollection), this)) { ((EntityCollection)entityCollection).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateEntityCollectionRepository(uow)) { repository.AddOrUpdate(entityCollection); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IEntityCollection>(entityCollection), this); } }
/// <summary> /// Saves a single <see cref="ICustomerAddress"/> /// </summary> /// <param name="address"> /// The address. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Save(ICustomerAddress address, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <ICustomerAddress>(address), this)) { ((CustomerAddress)address).WasCancelled = true; return; } } var count = GetCustomerAddressCount(address.CustomerKey, address.AddressType); if (count == 0 || address.IsDefault) { ClearDefaultCustomerAddress(address.CustomerKey, address.AddressType); address.IsDefault = true; } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateCustomerAddressRepository(uow)) { repository.AddOrUpdate(address); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <ICustomerAddress>(address), this); } }
/// <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); }
/// <summary> /// Saves a single <see cref="IShipRateTier"/> /// </summary> /// <param name="shipRateTier">The <see cref="IShipRateTier"/> to save</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param> public void Save(IShipRateTier shipRateTier, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IShipRateTier>(shipRateTier), this)) { ((ShipRateTier)shipRateTier).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateShipRateTierRepository(uow)) { repository.AddOrUpdate(shipRateTier); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IShipRateTier>(shipRateTier), this); } }
/// <summary> /// Saves a single instance of <see cref="INotificationMessage"/> /// </summary> /// <param name="notificationMessage">The <see cref="NotificationMessage"/> to be saved</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(INotificationMessage notificationMessage, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <INotificationMessage>(notificationMessage), this)) { ((NotificationMessage)notificationMessage).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateNotificationMessageRepository(uow)) { repository.AddOrUpdate(notificationMessage); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <INotificationMessage>(notificationMessage), this); } }
/// <summary> /// Saves an <see cref="IAppliedPayment"/> /// </summary> /// <param name="appliedPayment">The <see cref="IAppliedPayment"/> to be saved</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IAppliedPayment appliedPayment, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IAppliedPayment>(appliedPayment), this)) { ((AppliedPayment)appliedPayment).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateAppliedPaymentRepository(uow)) { repository.AddOrUpdate(appliedPayment); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IAppliedPayment>(appliedPayment), this); } }
/// <summary> /// Called to 'call home' to ensure the current server has an active record /// </summary> /// <param name="address"></param> public void EnsureActive(string address) { var uow = _uowProvider.GetUnitOfWork(); using (var repo = _repositoryFactory.CreateServerRegistrationRepository(uow)) { //NOTE: we cannot use Environment.MachineName as this does not work in medium trust // found this out in CDF a while back: http://clientdependency.codeplex.com/workitem/13191 var computerName = System.Net.Dns.GetHostName(); var query = Query <ServerRegistration> .Builder.Where(x => x.ComputerName.ToUpper() == computerName.ToUpper()); var found = repo.GetByQuery(query).ToArray(); ServerRegistration server; if (found.Any()) { server = found.First(); server.ServerAddress = address; //This should not really change but it might! server.UpdateDate = DateTime.UtcNow; //Stick with Utc dates since these might be globally distributed server.IsActive = true; } else { server = new ServerRegistration(address, computerName, DateTime.UtcNow); } repo.AddOrUpdate(server); uow.Commit(); } }
/// <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="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); }
/// <summary> /// Gets an <see cref="IProfile"/> for the current BackOffice User. /// </summary> /// <param name="httpContext">HttpContext to fetch the user through</param> /// <returns><see cref="IProfile"/> containing the Name and Id of the logged in BackOffice User</returns> public IProfile GetCurrentBackOfficeUser(HttpContextBase httpContext) { Mandate.That(httpContext != null, () => new ArgumentException( "The HttpContext which is used to retrieve information about the currently logged in backoffice user was null and can therefor not be used", "HttpContextBase")); if (httpContext == null) { return(null); } var cookie = httpContext.Request.Cookies["UMB_UCONTEXT"]; Mandate.That(cookie != null, () => new ArgumentException("The Cookie containing the UserContext Guid Id was null", "Cookie")); if (cookie == null) { return(null); } string contextId = cookie.Value; string cacheKey = string.Concat("UmbracoUserContext", contextId); int userId = 0; if (HttpRuntime.Cache[cacheKey] == null) { using (var uow = _uowProvider.GetUnitOfWork()) { userId = uow.Database.ExecuteScalar <int>( "select userID from umbracoUserLogins where contextID = @ContextId", new { ContextId = new Guid(contextId) }); HttpRuntime.Cache.Insert(cacheKey, userId, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, (int)(Umbraco.Core.Configuration.GlobalSettings.TimeOutInMinutes / 10), 0)); } } else { userId = (int)HttpRuntime.Cache[cacheKey]; } var profile = GetProfileById(userId); return(profile); }
public IEnumerable <IMemberType> GetAllMemberTypes(params int[] ids) { using (var repository = _repositoryFactory.CreateMemberTypeRepository(_uowProvider.GetUnitOfWork())) { return(repository.GetAll(ids)); } }
private IContentType FindContentTypeByAlias(string contentTypeAlias) { using (var repository = _repositoryFactory.CreateContentTypeRepository(_uowProvider.GetUnitOfWork())) { var query = Query <IContentType> .Builder.Where(x => x.Alias == contentTypeAlias); var types = repository.GetByQuery(query); if (!types.Any()) { throw new Exception( string.Format("No ContentType matching the passed in Alias: '{0}' was found", contentTypeAlias)); } var contentType = types.First(); if (contentType == null) { throw new Exception(string.Format("ContentType matching the passed in Alias: '{0}' was null", contentTypeAlias)); } return(contentType); } }
/// <summary> /// Deletes the section /// </summary> public void DeleteSection(Section section) { lock (Locker) { //delete the assigned applications _uowProvider.GetUnitOfWork().Database.Execute( "delete from umbracoUser2App where app = @appAlias", new { appAlias = section.Alias }); //delete the assigned trees var trees = _applicationTreeService.GetApplicationTrees(section.Alias); foreach (var t in trees) { _applicationTreeService.DeleteTree(t); } LoadXml(doc => { doc.Root.Elements("add").Where(x => x.Attribute("alias") != null && x.Attribute("alias").Value == section.Alias) .Remove(); return(true); }, true); //raise event OnDeleted(section, new EventArgs()); } }
/// <summary> /// Gets a <see cref="IDataTypeDefinition"/> by its Id /// </summary> /// <param name="id">Id of the <see cref="IDataTypeDefinition"/></param> /// <returns><see cref="IDataTypeDefinition"/></returns> public IDataTypeDefinition GetDataTypeDefinitionById(int id) { using (var repository = _repositoryFactory.CreateDataTypeDefinitionRepository(_uowProvider.GetUnitOfWork())) { return(repository.Get(id)); } }
/// <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); }
/// <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)); }
public IUser GetUserByUserName(string username) { using (var repository = _repositoryFactory.CreateUserRepository(_uowProvider.GetUnitOfWork())) { var query = Query <IUser> .Builder.Where(x => x.Username == username); return(repository.GetByQuery(query).FirstOrDefault()); } }
private IEnumerable <Notification> GetUsersNotifications(IEnumerable <int> userIds, string action, IEnumerable <int> nodeIds, Guid objectType) { using (var uow = _uowProvider.GetUnitOfWork()) { var repository = new NotificationsRepository(uow); var ret = repository.GetUsersNotifications(userIds, action, nodeIds, objectType); uow.Commit(); return(ret); } }
/// <summary> /// Gets a list of all <see cref="ITemplate"/> objects /// </summary> /// <returns>An enumerable list of <see cref="ITemplate"/> objects</returns> public IEnumerable <ITemplate> GetTemplates(params string[] aliases) { using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork())) { return(repository.GetAll(aliases)); } }
/// <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> 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)); }
/// <summary> /// Gets the notifications for the user /// </summary> /// <param name="user"></param> /// <returns></returns> public IEnumerable <Notification> GetUserNotifications(IUser user) { var uow = _uowProvider.GetUnitOfWork(); var repository = new NotificationsRepository(uow); return(repository.GetUserNotifications(user)); }
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)); }
/// <summary> /// Saves a single instance of a <see cref="IGatewayProviderSettings"/> /// </summary> /// <param name="gatewayProviderSettings"></param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IGatewayProviderSettings gatewayProviderSettings, bool raiseEvents = true) { if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IGatewayProviderSettings>(gatewayProviderSettings), this); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateGatewayProviderRepository(uow)) { repository.AddOrUpdate(gatewayProviderSettings); uow.Commit(); } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IGatewayProviderSettings>(gatewayProviderSettings), this); } } }
/// <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); }
/// <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)); }
/// <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); }
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); }
public void WithReadLocked(Action <LockedRepository <TRepository> > action, bool autoCommit = true) { var uow = _uowProvider.GetUnitOfWork(); using (var transaction = uow.Database.GetTransaction(IsolationLevel.RepeatableRead)) { foreach (var lockId in _readLockIds) { uow.Database.AcquireLockNodeReadLock(lockId); } using (var repository = _repositoryFactory(uow)) { action(new LockedRepository <TRepository>(transaction, uow, repository)); if (autoCommit == false) { return; } uow.Commit(); transaction.Complete(); } } }
/// <summary> /// Creates a <see cref="INotificationMethod"/> and saves it to the database /// </summary> /// <param name="providerKey">The <see cref="IGatewayProviderSettings"/> key</param> /// <param name="name">The name of the notification (used in back office)</param> /// <param name="serviceCode">The notification service code</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> /// <returns>An Attempt{<see cref="INotificationMethod"/>}</returns> public Attempt <INotificationMethod> CreateNotificationMethodWithKey(Guid providerKey, string name, string serviceCode, bool raiseEvents = true) { Mandate.ParameterNotNullOrEmpty(name, "name"); Mandate.ParameterNotNullOrEmpty(serviceCode, "serviceCode"); var notificationMethod = new NotificationMethod(providerKey) { Name = name, ServiceCode = serviceCode }; if (raiseEvents) { if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <INotificationMethod>(notificationMethod), this)) { notificationMethod.WasCancelled = true; return(Attempt <INotificationMethod> .Fail(notificationMethod)); } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateNotificationMethodRepository(uow)) { repository.AddOrUpdate(notificationMethod); uow.Commit(); } } if (raiseEvents) { Created.RaiseEvent(new Events.NewEventArgs <INotificationMethod>(notificationMethod), this); } return(Attempt <INotificationMethod> .Succeed(notificationMethod)); }
/// <summary> /// The create anonymous customer with key. /// </summary> /// <returns> /// The <see cref="IAnonymousCustomer"/>. /// </returns> public IAnonymousCustomer CreateAnonymousCustomerWithKey() { var anonymous = new AnonymousCustomer(); if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IAnonymousCustomer>(anonymous), this)) { anonymous.WasCancelled = true; return(anonymous); } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateAnonymousCustomerRepository(uow)) { repository.AddOrUpdate(anonymous); uow.Commit(); } } Created.RaiseEvent(new Events.NewEventArgs <IAnonymousCustomer>(anonymous), this); return(anonymous); }