コード例 #1
0
ファイル: BusinessEventDao.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Record a business event asynchronously
        /// </summary>
        /// <param name="businessEvent">The business event to create</param>
        async public Task CreateAsync(BusinessEvent businessEvent)
        {
            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(BusinessEventMapper.Parameters.BusinessId, businessEvent.BusinessId),
                DbHelper.CreateParameter(BusinessEventMapper.Parameters.BusinessEventTypeCode, businessEvent.EventType.Code),
                DbHelper.CreateParameter(BusinessEventMapper.Parameters.Reference, businessEvent.Reference),
                DbHelper.CreateParameter(BusinessEventMapper.Parameters.Notes, businessEvent.Notes),
                DbHelper.CreateParameter(BusinessEventMapper.Parameters.CreatedBy, AuditFieldsHelper.GetUserId())
            };

            SqlParameter outputKey;
            parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(BusinessEventMapper.Parameters.Id, SqlDbType.Int));
            try
            {
                await DbHelper.ExecuteNonQueryCommandAsync(SQL_STATEMENT, parameters: parameters);

                // Make sure the record was created
                if (outputKey.Value == DBNull.Value)
                {
                    throw new PrimaryKeyNotSetException(ErrorFactory.CreateAndLogError(Errors.SRVEX30045,
                                                                                       "BusinessEventDao.Create",
                                                                                       additionalDescriptionParameters:
                                                                                           (new object[]
                                                                                               {businessEvent.Reference})));
                }

                businessEvent.Id = DbHelper.ParameterValue<int>(outputKey);
            }
            catch (SqlException sqlEx)
            {
                // if there is a reference and the sql exception relates to the ref, try again
                if (!string.IsNullOrWhiteSpace(businessEvent.Reference) &&
                    sqlEx.Message.IndexOf(TRIGGER_ERROR) >= 0)
                {
                    int retries = 0;
                    // while the event hasn't been created, retry up to max times (3 default)
                    while (businessEvent.Id == default(int) &&
                           MAX_RETRIES != retries)
                    {
                        // try again synchronously 
                        Create(businessEvent);
                        retries++;
                    }
                }
            }
        }
コード例 #2
0
ファイル: BusinessEventDaoTest.cs プロジェクト: ognjenm/egle
            public void CreateBusinessEventIsSuccessful()
            {
                // Arrange
                const long BUSINESS_ID = 1;
                
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateBusinessCacheTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var businessEvent = new BusinessEvent
                        {
                            BusinessId = BUSINESS_ID,
                            EventType = new EnumEntity { Code = BusinessEventTypesEnum.Created.GetCode() },
                            Reference = BUSINESS_ID.ToString(),
                            Notes = BUSINESS_ID.ToString()
                        };

                    // Act
                    businessEventDao.Create(businessEvent);

                    // Assert
                    Assert.IsNotNull(businessEvent.Id, "Id was not filled in after create");
                }
            }
コード例 #3
0
ファイル: BusinessEventDao.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Record a business event, note that this should only be used if 
        /// one needs the event id back before doing things.
        /// Otherwise use the Async version for speed.
        /// </summary>
        /// <param name="businessEvent">The business event to create</param>
        public void Create(BusinessEvent businessEvent)
        {
            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(BusinessEventMapper.Parameters.BusinessId, businessEvent.BusinessId),
                DbHelper.CreateParameter(BusinessEventMapper.Parameters.BusinessEventTypeCode, businessEvent.EventType.Code),
                DbHelper.CreateParameter(BusinessEventMapper.Parameters.Reference, businessEvent.Reference),
                DbHelper.CreateParameter(BusinessEventMapper.Parameters.Notes, businessEvent.Notes),
                DbHelper.CreateParameter(BusinessEventMapper.Parameters.CreatedBy, AuditFieldsHelper.GetUserId())
            };

            SqlParameter outputKey;
            parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(BusinessEventMapper.Parameters.Id, SqlDbType.Int));

            DbHelper.ExecuteNonQueryCommand(SQL_STATEMENT, parameters: parameters);

            // Make sure the record was created
            if (outputKey.Value == DBNull.Value)
            {
                throw new PrimaryKeyNotSetException(ErrorFactory.CreateAndLogError(Errors.SRVEX30045, "BusinessEventDao.Create", additionalDescriptionParameters: (new object[] { businessEvent.Reference })));
            }

            businessEvent.Id = DbHelper.ParameterValue<int>(outputKey);
        }
コード例 #4
0
ファイル: BusinessEventDaoTest.cs プロジェクト: ognjenm/egle
            public void CreateBusinessEventWithInvalidDataFails()
            {
                // Arrange
                const long BUSINESS_ID = 1;

                // Create event with a business id that doesn't exist
                var businessEvent = new BusinessEvent
                {
                    BusinessId = BUSINESS_ID,
                    EventType = new EnumEntity { Code = BusinessEventTypesEnum.Created.GetCode() },
                    Reference = BUSINESS_ID.ToString(),
                    Notes = BUSINESS_ID.ToString()
                };

                // Act
                businessEventDao.Create(businessEvent);
            }
コード例 #5
0
ファイル: EventTrackingManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Create a business event asynchronously
        /// </summary>
        /// <param name="businessId">The long id of the business</param>
        /// <param name="eventType">The type of business event</param>
        /// <param name="reference">The reference - usually the id related to the event type</param>
        /// <param name="notes">Notes if applicable</param>
        public void CreateBusinessEventAsync(long businessId, BusinessEventTypesEnum eventType, string reference, string notes = null)
        {
            
            var businessEvent = new BusinessEvent
            {
                BusinessId = businessId,
                EventType = new EnumEntity { Code = eventType.GetCode() },
                Reference = reference,
                Notes = notes
            };

            // Multithread it
            Task.Factory.StartNew(() => businessEventDao.CreateAsync(businessEvent));
        }
コード例 #6
0
ファイル: EventTrackingManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Create a business event synchronously, use if you need the results back immediately
        /// </summary>
        /// <param name="businessId">The long id of the business</param>
        /// <param name="eventType">The type of business event</param>
        /// <param name="reference">The reference - usually the id related to the event type</param>
        /// <param name="notes">Notes if applicable</param>
        public void CreateBusinessEvent(long businessId, BusinessEventTypesEnum eventType, string reference, string notes = null)
        {

            var businessEvent = new BusinessEvent
            {
                BusinessId = businessId,
                EventType = new EnumEntity { Code = eventType.GetCode() },
                Reference = reference,
                Notes = notes
            };

            // single thread it
            businessEventDao.Create(businessEvent);
        }
コード例 #7
0
ファイル: BusinessManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Create contact
        /// </summary>
        /// <param name="contactPerson">BusinessContactPerson</param>
        /// <returns>true if creation succeeeds</returns>
        public int CreateContact(BusinessContactPerson contactPerson)
        {
            int contactId = 0;
            int contactPhoneId = 0;
            using (var tx = new BusinessTransaction())
            {
                // write contact record to ContactPerson table
                contactId = businessDao.CreateContact(contactPerson);

                var createBusinessContactPersonEvent = new BusinessEvent
                {
                    BusinessId = contactPerson.BusinessId,
                    EventType = new EnumEntity { Code = BusinessEventTypesEnum.ContactPersonCreated.GetCode() },
                    Reference = contactId.ToString()

                };

                // reset primary contact if new contact is primary
                if (contactPerson.PrimaryContactId != default(int) && contactPerson.IsPrimary)
                {
                    businessDao.UpdatePrimaryContact(contactPerson.BusinessId, contactPerson.PrimaryContactId, false);
                    businessDao.UpdatePrimaryContact(contactPerson.BusinessId, contactId, true);

                    var updatecontactPerson = new BusinessEvent
                    {
                        BusinessId = contactPerson.BusinessId,
                        EventType = new EnumEntity { Code = BusinessEventTypesEnum.PrimaryContactModified.GetCode() },
                        Reference = contactId.ToString()
                    };

                    businessEventDao.Create(updatecontactPerson);
                }


                // write to business event table
                businessEventDao.Create(createBusinessContactPersonEvent);

                // write contact record to ContactPersonPhone table
                BusinessContactPersonPhone businessContactPersonPhone = new BusinessContactPersonPhone()
                {
                    BusinessId = contactPerson.BusinessId,
                    ContactPersonId = contactId,
                    PhoneTypeCode = PhoneTypeEnum.Contact1.GetCode(),
                    Number = contactPerson.Telephone
                };

                // write record to BusinessContactPersonPhone table
                contactPhoneId = businessDao.CreateContactPersonPhone(businessContactPersonPhone);

                var createBusinessPhoneEvent = new BusinessEvent
                {
                    BusinessId = contactPerson.BusinessId,
                    EventType = new EnumEntity { Code = BusinessEventTypesEnum.ContactPersonPhoneCreated.GetCode() },
                    Reference = contactPhoneId.ToString()

                };

                // write create business event to event table
                businessEventDao.Create(createBusinessPhoneEvent);

                tx.Commit();
            }
            return contactId;
        }
コード例 #8
0
ファイル: BusinessManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Create Business
        /// </summary>
        /// <param name="business">Business</param>
        /// <returns>new business id</returns>
        public long CreateBusiness(Model.Business.Business business)
        {
            int businessId = 0;
            using (var tx = new BusinessTransaction())
            {
                //generate unique reference code
                business.ReferenceCode = businessDao.GenerateReferenceCode(GetReferenceShortName(business.ShortName));

                // write business record to business table
                businessId = businessDao.Create(business);
                
                // set provider id here
                business.Provider.Id = businessId;

                //create default payment method as cash with default currency
                businessDao.AddBusinessOfflinePaymentMethod(new BusinessPaymentMethod
                {
                    BusinessId = businessId,
                    CurrencyCode = business.WorkingCurrencyCode,
                    PaymentMethodCode = PaymentMethodEnum.Cash.GetCode()
                });

                var createBusinessEvent = new BusinessEvent
                {
                    BusinessId = businessId,
                    EventType = new EnumEntity { Code = BusinessEventTypesEnum.Created.GetCode() }
                };

                // write create business event to event table
                businessEventDao.Create(createBusinessEvent);

                // Prevents from repetitive reference code
                businessEventDao.Create(new BusinessEvent { BusinessId = businessId, EventType = new EnumEntity { Code = BusinessEventTypesEnum.Modified.GetCode() }, Reference = business.ReferenceCode, Notes = "Finance reference created" });

                // Will throw exception if content id not unique
                businessDao.CreateProvider(business.Provider);

                //Create all new Bussiness channel overrides for this business and all channels
                businessChannelOverrideDao.CreateInitialBusinessChannelOverride(businessId: businessId);
                
                //opt in to default channels
                var channelsToOptIn = businessChannelOptInDao.GetDefaultChannelsPerBusinessLocation(businessId);
                channelsToOptIn.ForEach( channel => distributionManager.OptInToChannel(channel, business.DefaultCultureCode));
            
                tx.Commit();
            }

            return businessId;
        }
コード例 #9
0
ファイル: BusinessManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Modify existing business
        /// </summary>
        /// <param name="business">The business object to modify</param>
        public void ModifyBusiness(Model.Business.Business business)
        {
            using (var tx = new BusinessTransaction())
            {
                businessDao.Modify(business);

                businessDao.ModifyProvider(business.Provider);

                // Record business event
                var businessEvent = new BusinessEvent
                {
                    BusinessId = business.Id,
                    EventType = new EnumEntity { Code = BusinessEventTypesEnum.Modified.GetCode() },
                    Reference = business.Id.ToString()
                };

                businessEventDao.Create(businessEvent);
                tx.Commit();
            }

            // update the cache post modify
            Cache.Cache.Business.Invalidate(business.Id);
        }
コード例 #10
0
ファイル: AgreementManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Agree (insert) to the agreements listed
        /// </summary>
        /// <param name="agreements">Business Agreements that should be inserted into db</param>
        /// <returns>true if successful</returns>
        public bool AgreeToAgreements(List<BusinessAgreement> agreements)
        {
            using (var btran = new BusinessTransaction())
            {
                // so that we agree to everything or nothing
                foreach (BusinessAgreement bagree in agreements)
                {
                    businessAgreementDao.Create(bagree);
                    var businessEvent = new BusinessEvent
                    {
                        BusinessId = bagree.BusinessId,
                        EventType = new EnumEntity { Code = BusinessEventTypesEnum.AcceptedBusinessAgreement.GetCode() },
                        Reference = bagree.AgreementId.ToString()
                    };

                    businessEventDao.Create(businessEvent);
                }

                btran.Commit();
            }
            return true;
        }
コード例 #11
0
ファイル: SettlementManager.cs プロジェクト: ognjenm/egle
        /// <summary>
        /// Set settlement ActivationDate / InactivationDate
        /// </summary>
        /// <param name="provider">NewProvider</param>
        /// <param name="business">Business</param>
        /// <param name="businessStatusEvent">BusinessEvent</param>
        private void SetActiveInActiveDates(NewProvider provider, Model.Business.Business business, BusinessEvent businessStatusEvent)
        {
            Helper.ArgumentNotNull(provider, "provider");
            Helper.ArgumentNotNull(business, "business");
            Helper.ArgumentNotNull(businessStatusEvent, "businessStatusEvent");

            if (business.BusinessStatus != null)
            {
                if (business.BusinessStatus.Code == BusinessStatus.ACTIVE)
                {
                    provider.ActivationDate = businessStatusEvent.Created;
                }

                if (business.BusinessStatus.Code == BusinessStatus.DORMANT)
                {
                    provider.InactivationDate = businessStatusEvent.Created;
                }
            }
        }