/// <summary> /// Activate a user based on the activation token, user extension and activation request /// </summary> /// <param name="userExtension">The user extension</param> /// <param name="activationRequest">The activation request</param> /// <returns>The activated user name</returns> private string ActivateUser(UserExtension userExtension, ActivationRequest activationRequest, string activationType) { MembershipUser user = membership.GetUser(userExtension.UserId); bool isUpdated = false; // NOTE: This condition seems to be wrong, because the return user.UserName statement at the end of this method could be called on a potentially null object. if (user != null) { using (BusinessTransaction tx = new BusinessTransaction()) { //unlock user if user is locked if (userExtension.UserStatusCode == UserStatusEnum.Locked.GetCode()) { user.UnlockUser(); } userExtension.UserStatusCode = USER_STATUS_ACTIVATED; bool isChangePassword = membership.ChangePassword(user, activationRequest.Password); bool isChangeQuestionAndAnswer = membership.ChangeSecurityQuestionAndAnswer( user, activationRequest.Password, activationRequest.SecurityQuestionId.ToString(), activationRequest.Answer); isUpdated = userExtensionDao.Modify(userExtension); if (activationType == RESETPASSWORD_TYPE_CODE) { userManager.RecordUserEvent(userExtension.UserId, UserEventTypesEnum.UserReActivated); } else if (activationType == ACTIVATION_TYPE_CODE) { userManager.RecordUserEvent(userExtension.UserId, UserEventTypesEnum.UserActivated); } if (isUpdated == false || isChangePassword == false || isChangeQuestionAndAnswer == false) { tx.Rollback(); } tx.Commit(); } } return user.UserName; }
/// <summary> /// Particular execute /// </summary> public override void ExecuteTask() { //Get the last sync timestamp from Ecommerce.BusinessAccount DateTime lastModifiedDateTime = businessManager.GetTimestampOfLastBusinessSyncedFromEcom(); if (fromDate.HasValue) { //means that we are unit testing it so we need to assume that this is the last modified date lastModifiedDateTime = fromDate.Value; } Log.LogInfo("Getting businesses updated from {0}", null, lastModifiedDateTime.ToString(CultureInfo.InvariantCulture)); foreach (ServiceTaskProviderElement provider in ServiceTaskProviderConfiguration.ProviderConfiguration) { ecomDataProvider = new EcomDataProvider(provider.ConnectionString); //Get all business modified since this timestamp in Ecommerce (BA_BUSINESSACCOUNT.BABA_MODIFICATIONDATE) List<EcomBusinessAccount> ecomBusinessList = ecomDataProvider.GetLastModifiedBusinesses(lastModifiedDateTime, DateTime.UtcNow); if (ecomBusinessList != null) { Log.LogInfo("{0} - {1} {2} Businesses have been modified on Ecom", null, TaskName, ecomBusinessList.Count, provider.ProviderSet); int numberOfBusinessesSynced = 0; //Insert/Update all modified businesses using (var tx = new BusinessTransaction()) { if (Log.IsDebugEnabled) { Log.LogDebug(string.Format("Synchronizing businesses to Eagle:")); } Guid updatedByUserId; if (!Guid.TryParse(identity.Name, out updatedByUserId)) { tx.Rollback(); Log.LogError("Couldn't get the user identity from the current thread"); Log.LogInfo("SyncBusinessesToEagle task finished executing"); return; } foreach (EcomBusinessAccount ecomBusinessAccount in ecomBusinessList) { if (State == TaskState.Stopping) { tx.Rollback(); Log.LogInfo("Aborting SyncBusinessesToEagle task due to the service being stopped."); return; } ecomBusinessAccount.ModifiedByUserId = updatedByUserId; var synced = true; try { //Log error in case we were unable to save due to existing ShortName in Business.BusinessCombined table if (!businessManager.SaveEcomBusinessAccount(EcomConverter.ConvertEcomToEagle(ecomBusinessAccount))) { synced = false; Log.LogError("eccomId = {0} was not synced because of existing shortName ({1}) in Business.BusinessCombined", null, null, ecomBusinessAccount.Id, ecomBusinessAccount.ShortName); } } catch (SqlException ex) { Log.LogError("eccomId = {0} was not synced because of SQL error.", null, ex, ecomBusinessAccount.Id); synced = false; } if (!synced) { continue; } numberOfBusinessesSynced++; if (Log.IsDebugEnabled) { Log.LogDebug("eccomId = {0} synced", ecomBusinessAccount.Id); } } tx.Commit(); } Log.LogInfo("{0} {1} Businesses have been synced to Eagle", null, numberOfBusinessesSynced, provider.ProviderSet); } } }
/// <summary> /// Delete a booking item that has been invoiced. /// A credit note is created following the deletion /// </summary> /// <param name="businessId">The id of the business</param> /// <param name="bookingItemId">The id of the booking item to delete</param> /// <param name="bookingId">The booking id</param> /// <returns>Credit note document id</returns> public int? DeleteInvoiceBookingItem(long businessId, int bookingItemId, int bookingId) { int? creditNoteId = default(int); using (BusinessTransaction businessTransaction = new BusinessTransaction()) { // cancel booking item var canceltemResult = bookingItemDao.CancelItem(bookingItemId); if (canceltemResult) { //create credit note for cancelled booking item creditNoteId = transactionDao.CreateDocument(businessId, bookingId, bookingItemId); businessTransaction.Commit(); } else { businessTransaction.Rollback(); } } return creditNoteId; }