public decimal GetPricePerGame( IServiceProvider serviceProvider, IList <ScheduleDay> egmPriceModifiers, EGM game) { if (egmPriceModifiers == null || !egmPriceModifiers.Any()) { return(game.PricePerGame); } bool hasModifier = false; //ScheduleDay modifier; PriceChangerEnum sign = PriceChangerEnum.None; decimal percents = 0m; // get modifier foreach (var priceModifier in egmPriceModifiers) { bool isModifierValid = priceModifier.PriceChangerSign != PriceChangerEnum.None && priceModifier.PriceModifier > 0; if (priceModifier.IsActive && priceModifier.IsDateRange) { if (DateTime.UtcNow >= priceModifier.From && DateTime.UtcNow <= priceModifier.To) { TrySetModifier(isModifierValid, out hasModifier, out sign, out percents, priceModifier); } if (hasModifier) { break; } } else if (priceModifier.IsActive) { var currentDay = (int)DateTime.UtcNow.DayOfWeek; if (currentDay == 0) { currentDay = 7; } if (currentDay == priceModifier.DayOfWeek) { TrySetModifier(isModifierValid, out hasModifier, out sign, out percents, priceModifier); if (hasModifier) { break; } } } } // modified price per game var pricePerGame = game.PricePerGame; if (hasModifier) { if (sign == PriceChangerEnum.Add) { pricePerGame += ((pricePerGame / 100) * percents); } else if (sign == PriceChangerEnum.Subtract) { pricePerGame -= ((pricePerGame / 100) * percents); } } return(pricePerGame); }
private async ValueTask <(bool success, CanPlayResponse response)> CanPlayAsyncInternal( Guid guid, string concentratorId, string controllerId, int cardType, string cardId, bool shouldPay, int transactionId, int endpointRssi, int concentratorRssi) { Concentrator getConcentrator() { var repo = _serviceProvider.GetService <ICardSystemRepository <Concentrator> >(); return(repo.AsNoTracking().FirstOrDefault(x => x.DeviceId == concentratorId)); }; ControllerConfigRelay getController() { var repo = _serviceProvider.GetService <ICardSystemRepository <ControllerConfigRelay> >(); return(repo.AsNoTracking() .Include(x => x.EGM) .ThenInclude(x => x.AllowedCurrencies) .FirstOrDefault(x => x.SerialNumber == controllerId && x.OwnerId == _ownerId)); }; Card getCard() { Card entity = null; ICardSystemRepository <Card> repo = null; string cardDBId = CardCacheServiceV2.Instance.GetIdByExternalId(cardId); if (!string.IsNullOrWhiteSpace(cardDBId)) { entity = CardCacheServiceV2.Instance.GetCard(_serviceProvider, cardDBId); if (entity != null) { return(entity); } repo = _serviceProvider.GetService <ICardSystemRepository <Card> >(); entity = repo.AsNoTracking() .Include(x => x.CardMode) .Include(x => x.User) .FirstOrDefault(x => x.Id == cardDBId); if (entity != null) { CardCacheServiceV2.Instance.AddCard(_serviceProvider, entity); CardCacheServiceV2.Instance.AddNewMap(entity); } return(entity); } repo = _serviceProvider.GetService <ICardSystemRepository <Card> >(); entity = repo.AsNoTracking() .Include(x => x.CardMode) .Include(x => x.User) .FirstOrDefault(x => x.ExternalId == cardId); if (entity != null) { CardCacheServiceV2.Instance.AddCard(_serviceProvider, entity); CardCacheServiceV2.Instance.AddNewMap(entity); } return(entity); }; IEnumerable <CurrencyTemplate> getCurrencyTemplates() { var repo = _serviceProvider.GetService <ICardSystemRepository <CurrencyTemplate> >(); return(repo.AsNoTracking() .Where(x => x.OwnerId == _ownerId) .ToList()); } var concentrator = getConcentrator(); if (concentrator == null) { var response = new CanPlayResponse { TransactionId = transactionId, Time = DateTime.UtcNow, ResponseCode = 101, ConcentratorId = concentratorId, ControllerId = controllerId, CardType = cardType, CardId = cardId, CardNumber = string.Empty, ServiceId = string.Empty, ServiceName = string.Empty, Permission = false, RelayType = string.Empty, RelayPulse = 0, RelayOnTime = 0, RelayOffTime = 0, RelayDisplayTime = 0, DisplayLine1 = "Err 101", DisplayLine2 = "Concentrator N/A" }; _logger.ErrorLog($"[CardService.CanPlayAsyncInternal][-OUT-] [{guid}] TransactionId {transactionId} | ConcentratorId {concentratorId} | ControllerId {controllerId} | CardType {cardType} | CardId {cardId} | ShouldPay {shouldPay} | EndpointRssi: {endpointRssi} | ConcentratorRssi {concentratorRssi} | {JsonSerializer.Serialize(response, new JsonSerializerOptions { WriteIndented = false })}", GetIpAddress()); return(false, response); } var controller = getController(); if (controller == null) { var response = new CanPlayResponse { TransactionId = transactionId, Time = DateTime.UtcNow, ResponseCode = 102, ConcentratorId = concentratorId, ControllerId = controllerId, CardType = cardType, CardId = cardId, CardNumber = string.Empty, ServiceId = string.Empty, ServiceName = string.Empty, Permission = false, RelayType = string.Empty, RelayPulse = 0, RelayOnTime = 0, RelayOffTime = 0, RelayDisplayTime = 0, DisplayLine1 = "Err 102", DisplayLine2 = "Controller N/A" }; _logger.ErrorLog($"[CardService.CanPlayAsyncInternal][-OUT-] [{guid}] TransactionId {transactionId} | ConcentratorId {concentratorId} | ControllerId {controllerId} | CardType {cardType} | CardId {cardId} | ShouldPay {shouldPay} | EndpointRssi: {endpointRssi} | ConcentratorRssi {concentratorRssi} | {JsonSerializer.Serialize(response, new JsonSerializerOptions { WriteIndented = false })}", GetIpAddress()); return(false, response); } var card = getCard(); if (card == null) { var response = new CanPlayResponse { TransactionId = transactionId, Time = DateTime.UtcNow, ResponseCode = 103, ConcentratorId = concentratorId, ControllerId = controllerId, CardType = cardType, CardId = cardId, CardNumber = string.Empty, ServiceId = string.Empty, ServiceName = string.Empty, Permission = false, RelayType = string.Empty, RelayPulse = 0, RelayOnTime = 0, RelayOffTime = 0, RelayDisplayTime = 0, DisplayLine1 = "Err 103", DisplayLine2 = "Card N/A" }; _logger.ErrorLog($"[CardService.CanPlayAsyncInternal][-OUT-] [{guid}] TransactionId {transactionId} | ConcentratorId {concentratorId} | ControllerId {controllerId} | CardType {cardType} | CardId {cardId} | ShouldPay {shouldPay} | EndpointRssi: {endpointRssi} | ConcentratorRssi {concentratorRssi} | {JsonSerializer.Serialize(response, new JsonSerializerOptions { WriteIndented = false })}", GetIpAddress()); return(false, response); } var currencyTemplates = getCurrencyTemplates(); IEnumerable <ScheduleDay> getScheduleDays() { IEnumerable <ScheduleDay> egmPriceModifiers = null; var repo = _serviceProvider.GetService <ICardSystemRepository <ScheduleDay> >(); if (!string.IsNullOrWhiteSpace(controller.EGM.Id)) { egmPriceModifiers = repo.AsNoTracking() .Include(x => x.Hours) .Where(x => x.EGMId == controller.EGM.Id) .AsEnumerable(); } if (egmPriceModifiers != null && !egmPriceModifiers.Any()) { egmPriceModifiers = repo .AsNoTracking() .Include(x => x.Hours) .Where(x => x.GameCenterId == controller.EGM.GameCenterId) .AsEnumerable(); } return(egmPriceModifiers ?? new List <ScheduleDay>()); } var scheduleDays = getScheduleDays(); // ако се изиква плащане този метод променя баланса на картата var canPlayDto = _serviceProvider.GetService <ICanPlayService>().CanPlayV2( _serviceProvider, concentrator, controller, card, scheduleDays.ToList(), shouldPay, currencyTemplates); if (canPlayDto.HasError) { var errors = canPlayDto.Message.Split('|'); var response = new CanPlayResponse { TransactionId = transactionId, Time = DateTime.UtcNow, ResponseCode = int.Parse(errors[0]), ConcentratorId = concentratorId, ControllerId = controllerId, CardType = cardType, CardId = cardId, CardNumber = string.Empty, ServiceId = string.Empty, ServiceName = string.Empty, Permission = false, RelayType = string.Empty, RelayPulse = 0, RelayOnTime = 0, RelayOffTime = 0, RelayDisplayTime = 0, DisplayLine1 = $"Err {errors[0]}", DisplayLine2 = errors[1] }; _logger.ErrorLog($"[CardService.CanPlayAsyncInternal][-OUT-] [{guid}] TransactionId {transactionId} | ConcentratorId {concentratorId} | ControllerId {controllerId} | CardType {cardType} | CardId {cardId} | ShouldPay {shouldPay} | EndpointRssi: {endpointRssi} | ConcentratorRssi {concentratorRssi} | {JsonSerializer.Serialize(response, new JsonSerializerOptions { WriteIndented = false })}", GetIpAddress()); return(false, response); } EGM gameDto = null; if (canPlayDto.CanPlay) { gameDto = controller.EGM; } var canPlayResponse = new CanPlayResponse { TransactionId = transactionId, Time = DateTime.UtcNow, ResponseCode = 0, ConcentratorId = concentrator.DeviceId, ControllerId = controller.SerialNumber, CardType = card.Type, CardId = card.ExternalId, CardNumber = card.Number, ServiceId = canPlayDto.GameId, ServiceName = canPlayDto.GameName, Permission = canPlayDto.CanPlay, RelayType = gameDto?.RelayMode, RelayPulse = gameDto?.RelayPulse ?? 0, RelayOnTime = gameDto?.RelayOnTime ?? 0, RelayOffTime = gameDto?.RelayOffTime ?? 0, RelayDisplayTime = gameDto?.RelayDisplayTime ?? 0, DisplayLine1 = $"{canPlayDto.PricePerGame:F2}".Trim().Trim(',').Trim(), DisplayLine2 = $"{canPlayDto.RemainingBalance:F2}" }; // само ако се изисква плащане логира плащането в транзакшън лога и обновява кеша на картата в api.icardmanager.eu if (shouldPay) { canPlayDto.GameId = gameDto?.Id; string relayInfo = $" | Relay ontime: {gameDto?.RelayOnTime}, Relay offtime: {gameDto?.RelayOffTime}, Relay pulse: {gameDto?.RelayPulse}, Relay display time: {gameDto?.RelayDisplayTime}, Relay mode: {gameDto?.RelayMode}, Game Serial Number: '{gameDto?.SerialNumber}'"; CreateCanPlayLog( concentrator.DeviceId, controller.SerialNumber, $"{canPlayDto.GameCenterName}{relayInfo}", canPlayDto.GameId, canPlayDto.GameName, canPlayDto.CurrencyInfo, card.ExternalId, card.Type, canPlayDto.PricePerGame, canPlayDto.PaidFromBonusBalance, canPlayDto.CanPlay, gameDto?.GameCenterId, gameDto != null ? gameDto.OwnerId : "system" ); try { var apiResponse = await _restApiClient.GetAsync <string>(_configuration.GetSection("AppSettings:ApiServiceURL").Get <string>(), $"api/{_ownerId}/card/{card.Id}/reloadcache"); if (apiResponse.hasError) { _logger.ErrorLog($"[CardService.CanPlayAsyncInternal][-API-] [{guid}] TransactionId {transactionId} | ConcentratorId {concentratorId} | ControllerId {controllerId} | CardType {cardType} | CardId {cardId} | ShouldPay {shouldPay} | EndpointRssi: {endpointRssi} | ConcentratorRssi {concentratorRssi} | {apiResponse.errorMessage}", GetIpAddress()); } } catch (Exception ex) { _logger.LogException($"CardService.CanPlayAsyncInternal throws: {ex}"); } } _logger.InfoLog($"[CardService.CanPlayAsyncInternal][-OUT-] [{guid}] TransactionId {transactionId} | ConcentratorId {concentratorId} | ControllerId {controllerId} | CardType {cardType} | CardId {cardId} | ShouldPay {shouldPay} | EndpointRssi: {endpointRssi} | ConcentratorRssi {concentratorRssi} | DB Result {JsonSerializer.Serialize(canPlayResponse, new JsonSerializerOptions { WriteIndented = false })}", GetIpAddress()); return(true, canPlayResponse); }
public GeoidTangentPlane(EGM egm, double origin_latitude, double origin_longitude, double origin_altitude = 0.0) : base(origin_latitude, origin_longitude, origin_altitude) { EGM = egm; Transform = new EGMTransform(egm, new WGS84Transform()); }
public EGMTransform(EGM egm, IGeodeticTransform geodeticTransform) { EGM = egm; GeodeticTransform = geodeticTransform; }