private static SingleEntityDataServiceResponse <decimal> GetCustomerLocalPendingBalance(GetCustomerAccountLocalPendingBalanceDataRequest request) { ThrowIf.Null(request, "request"); ThrowIf.NullOrWhiteSpace(request.AccountNumber, "request.AccountNumber"); decimal tenderedAmount = decimal.Zero; decimal depositsAmount = decimal.Zero; ParameterSet parameters = new ParameterSet(); parameters["@nvc_AccountNumber"] = request.AccountNumber; parameters["@nvc_StoreId"] = request.RequestContext.GetOrgUnit().OrgUnitNumber; parameters["@nvc_PosOperation"] = (int)RetailOperation.PayCustomerAccount; parameters["@i_LastCounter"] = request.LastReplicationCounter; parameters["@nvc_DataAreaId"] = request.RequestContext.GetChannelConfiguration().InventLocationDataAreaId; ParameterSet outputParameters = new ParameterSet(); outputParameters["@d_tenderAmount"] = tenderedAmount; outputParameters["@d_depositAmount"] = depositsAmount; using (SqlServerDatabaseContext databaseContext = new SqlServerDatabaseContext(request.RequestContext)) { databaseContext.ExecuteStoredProcedureScalar(LocalPendingTransactionsAmountSprocName, parameters, outputParameters); } tenderedAmount = Convert.ToDecimal(outputParameters["@d_tenderAmount"]); depositsAmount = Convert.ToDecimal(outputParameters["@d_depositAmount"]); return(new SingleEntityDataServiceResponse <decimal>(tenderedAmount - depositsAmount)); }
/// <summary> /// Unlock the current user. /// </summary> /// <param name="request">The data service request.</param> /// <returns>The data service response.</returns> private SingleEntityDataServiceResponse <bool> UnLockUserAtLogOff(UnlockUserAtLogOffDataRequest request) { ParameterSet parameters = new ParameterSet(); parameters[ChannelIdParamName] = request.ChannelId; parameters[StaffIdParamName] = request.StaffId; parameters[DataAreaIdParamName] = request.DataAreaId; ParameterSet outputParameters = new ParameterSet(); outputParameters[ReturnValueParamName] = 0; using (SqlServerDatabaseContext databaseContext = new SqlServerDatabaseContext(request)) { databaseContext.ExecuteStoredProcedureScalar(UnlockUserSprocName, parameters, outputParameters); } bool result = false; if ((int)outputParameters[ReturnValueParamName] == 1) { result = true; } EmployeeL2CacheDataStoreAccessor cacheAccessor = GetCacheAccessor(request.RequestContext); cacheAccessor.ClearCacheLockUserAtLogOn(request.TerminalId, request.StaffId); // unlocking the user has the same meaning as deleting the user session on the terminal cacheAccessor.ClearCacheIsEmployeeSessionOpenOnTerminal(request.TerminalId, request.StaffId); return(new SingleEntityDataServiceResponse <bool>(result)); }
/// <summary> /// Converts shift To table variable parameters and calls stored procedure. /// </summary> /// <param name="storedProcedureName">The stored procedure name.</param> /// <param name="request">The create shift data request.</param> /// <param name="isShiftStagingTableRow">A boolean value indicating if the row is from shift staging table or Pos batch table.</param> private void ConvertShiftToTableVariableParametersAndCallStoredProcedure(string storedProcedureName, ShiftDataRequest request, bool isShiftStagingTableRow = true) { string inventLocationDataAreaId = request.RequestContext.GetChannelConfiguration().InventLocationDataAreaId; Shift shift = request.Shift; var parameters = new ParameterSet(); using (DataTable shiftTable = new DataTable(ShiftTableTypeName)) using (DataTable shiftTenderLineTable = new DataTable(ShiftTenderLineTableTypeName)) using (DataTable shiftAccountLineTable = new DataTable(ShiftAccountLineTableTypeName)) { this.SetShiftTableTypeSchema(shiftTable); shiftTable.Rows.Add(this.ConvertToShiftDataRow(shiftTable, shift, inventLocationDataAreaId, isShiftStagingTableRow)); parameters[ShiftTableTypeVariableName] = shiftTable; if (shift.Status == ShiftStatus.Closed) { // Only closed shift contains tenderline information. this.SetShiftTenderLineTableTypeSchema(shiftTenderLineTable); foreach (DataRow row in this.ConvertToShiftTenderLineDataRows(shiftTenderLineTable, shift, inventLocationDataAreaId)) { shiftTenderLineTable.Rows.Add(row); } parameters[ShiftTenderLineTableTypeVariableName] = shiftTenderLineTable; // Insert account (income /expense) lines this.SetShiftAccountLineTableTypeSchema(shiftAccountLineTable); foreach (DataRow row in this.ConvertToShiftAccountLineDataRows(shiftAccountLineTable, shift, inventLocationDataAreaId)) { shiftAccountLineTable.Rows.Add(row); } parameters[ShiftAccountLineTableTypeVariableName] = shiftAccountLineTable; } var inputOutputParameters = new ParameterSet(); inputOutputParameters[RowVersionViarableName] = shift.RowVersion; int errorCode; using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request)) { errorCode = sqlServerDatabaseContext.ExecuteStoredProcedureScalar(storedProcedureName, parameters, inputOutputParameters); } if (errorCode != (int)DatabaseErrorCodes.Success) { throw new StorageException( StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError, errorCode, string.Format("Unable to execute the stored procedure {0}.", storedProcedureName)); } shift.RowVersion = inputOutputParameters[RowVersionViarableName] as byte[]; } }
/// <summary> /// Verifies if the current user is locked out from the system, and if yes, returns the time duration in which the user will be unlocked. /// </summary> /// <param name="request">The data service request.</param> /// <returns>The data service response containing the number of minutes for which the user will be blocked.</returns> private SingleEntityDataServiceResponse <int> VerifyUserLockoutPolicy(VerifyUserLockoutPolicyDataRequest request) { ParameterSet parameters = new ParameterSet(); parameters["@bi_ChannelId"] = request.RequestContext.GetPrincipal().ChannelId; parameters["@nvc_StaffId"] = request.StaffId; ParameterSet outputParameters = new ParameterSet(); outputParameters[TimeToAccountUnlockInSecondsParamName] = 0; int timeToAccountUnlockInSeconds; using (SqlServerDatabaseContext databaseContext = new SqlServerDatabaseContext(request)) { databaseContext.ExecuteStoredProcedureScalar(VerifyUserLockoutSprocName, parameters, outputParameters); } timeToAccountUnlockInSeconds = (int)outputParameters[TimeToAccountUnlockInSecondsParamName]; return(new SingleEntityDataServiceResponse <int>(timeToAccountUnlockInSeconds)); }
/// <summary> /// Creates an employee session. /// </summary> /// <param name="context">The request context.</param> /// <param name="allowMultipleTerminalSessions">A value indicating whether a session can be created if the employee already holds a session on another terminal.</param> /// <param name="channelId">The channel identifier.</param> /// <param name="terminalId">The terminal identifier.</param> /// <param name="staffId">The staff identifier.</param> /// <param name="dataAreaId">The data area identifier.</param> /// <returns>The response for creating the new session.</returns> private CreateEmployeeSessionDataResponse CreateEmployeeSession( RequestContext context, bool allowMultipleTerminalSessions, long channelId, string terminalId, string staffId, string dataAreaId) { ParameterSet parameters = new ParameterSet(); parameters[TerminalIdParamName] = terminalId; parameters[ChannelIdParamName] = channelId; parameters[StaffIdParamName] = staffId; parameters[DataAreaIdParamName] = dataAreaId; // if user is not allowed multiple sessions, then we can only create the session if no other sessions are present for the user parameters[OnlyCreateSessionIfNoOtherSessionsArePresentParameterName] = !allowMultipleTerminalSessions; ParameterSet outputParameters = new ParameterSet(); outputParameters[CreateEmployeeSessionOpenSessionTerminalIdReturnParamName] = string.Empty; outputParameters[CreateEmployeeSessionReturnValueParamName] = 0; using (SqlServerDatabaseContext databaseContext = new SqlServerDatabaseContext(context)) { databaseContext.ExecuteStoredProcedureScalar(CreateEmployeeSessionSprocName, parameters, outputParameters); } string existingSessionTerminalId = (string)outputParameters[CreateEmployeeSessionOpenSessionTerminalIdReturnParamName]; // session was created if multiple terminal sessions were allowed; or if it wasn't, then session was created only if no previous session was found bool wasSessionCreated = allowMultipleTerminalSessions || string.IsNullOrWhiteSpace(existingSessionTerminalId); GetCacheAccessor(context).CacheIsEmployeeSessionOpenOnTerminal(terminalId, staffId, wasSessionCreated); return(new CreateEmployeeSessionDataResponse(existingSessionTerminalId)); }