Exemplo n.º 1
0
        public async Task <Response> MobileCheckIn(string organisationId, MobileUpdateCountRequest payload)
        {
            var walletRequest = new CreateWalletRequest
            {
                MobileNumber = payload.MobileNumber
            };

            var wallet = await _walletService.CreateWallet(walletRequest, true);

            var session = await _sessionService.CreateSession(payload.MobileNumber, wallet);

            var organisation = await _organisationRepository.GetAsync(Guid.Parse(organisationId));

            if (organisation == default)
            {
                throw new NotFoundException(Messages.Org_NotExists);
            }

            await _smsService.SendWelcomeSms(payload.MobileNumber, organisation.Name, session.ExpireAt.Value, session.Id);

            var updateCounterRequest = new UpdateCountRequest
            {
                Latitude  = payload.Latitude,
                Longitude = payload.Longitude,
                WalletId  = wallet.Id.ToString()
            };

            var counterResponse = await UpdateCountAsync(organisationId, updateCounterRequest, ScanType.CheckIn, true);

            return(counterResponse);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Subtract(string id)
        {
            var payload = new UpdateCountRequest()
            {
                Latitude = 0, Longitude = 0,
            };

            return(StatusCode(StatusCodes.Status200OK,
                              await _organisationService.UpdateCountAsync(id, payload, ScanType.CheckOut)));
        }
Exemplo n.º 3
0
        public async Task <Response> MobileCheckOut(string organisationId, MobileUpdateCountRequest payload)
        {
            _cryptoService.EncryptAsServer(payload, true);

            var updateCounterRequest = new UpdateCountRequest
            {
                Latitude  = payload.Latitude,
                Longitude = payload.Longitude,
                WalletId  = await GetCheckoutWalletId(payload.MobileNumber)
            };

            var counterResponse = await UpdateCountAsync(organisationId, updateCounterRequest, ScanType.CheckOut, true);

            return(counterResponse);
        }
Exemplo n.º 4
0
        public async Task <Response> UpdateCountAsync(string id, UpdateCountRequest payload, ScanType scanType, bool mobile = false)
        {
            Wallet wallet = null;

            if (!string.IsNullOrEmpty(payload.WalletId))
            {
                wallet = await _walletRepository.GetAsync(Guid.Parse(payload.WalletId));

                if (wallet == null)
                {
                    throw new NotFoundException(Messages.Wallet_NotFound);
                }
            }

            var organisation = await _organisationRepository.GetWithLogsAsync(Guid.Parse(id));

            if (organisation == default)
            {
                throw new NotFoundException(Messages.Org_NotExists);
            }

            ValidateScan(organisation.AccessLogs.ToList(), scanType, wallet, mobile);

            await UpdateLogs(wallet, organisation, scanType);

            var logs = organisation.AccessLogs
                       .Where(oal => oal.CreatedAt.Value.Date.Equals(DateTime.UtcNow.Date))
                       .ToList();

            return(new Response(
                       new UpdateCountResponse()
            {
                Balance = logs.Count == 0 ? 0 : GetAccessLogBalance(logs),
                Total = logs.Count == 0 ? 0 : GetAccessLogTotal(logs),
                OrganisationName = organisation.Name
            },
                       true,
                       HttpStatusCode.OK));
        }
Exemplo n.º 5
0
 public async Task <IActionResult> AccessDenied(string id, [FromBody] UpdateCountRequest payload)
 {
     return(StatusCode(StatusCodes.Status200OK,
                       await _organisationService.UpdateCountAsync(id, payload, ScanType.Denied)));
 }