Пример #1
0
        protected override async Task HandleCore(ImportRequestsCommand message)
        {
            var orgId = await context.Events.AsNoTracking()
                        .Include(rec => rec.Campaign)
                        .Where(rec => rec.Id == message.EventId)
                        .Select(rec => rec.Campaign.ManagingOrganizationId)
                        .FirstOrDefaultAsync();

            if (orgId > 0)
            {
                var requests = message.ImportRequestViewModels.Select(viewModel => new Request
                {
                    OrganizationId    = orgId,
                    RequestId         = NewRequestId(),
                    ProviderRequestId = viewModel.Id,
                    EventId           = message.EventId,
                    ProviderData      = viewModel.ProviderData,
                    Address           = viewModel.Address,
                    City      = viewModel.City,
                    DateAdded = DateTimeUtcNow(),
                    Email     = viewModel.Email,
                    Name      = viewModel.Name,
                    Phone     = viewModel.Phone,
                    State     = viewModel.State,
                    Zip       = viewModel.Zip,
                    Status    = RequestStatus.Unassigned,
                    Source    = RequestSource.Csv
                }).ToList();

                context.Requests.AddRange(requests);

                //TODO mgmccarthy: eventually move IGeocoder invocations to async using azure. Issue #1626 and #1639
                foreach (var request in requests)
                {
                    if (request.Latitude == 0 && request.Longitude == 0)
                    {
                        var coordinates = await geocoder.GetCoordinatesFromAddress(request.Address, request.City, request.State, request.Zip, string.Empty);

                        request.Latitude  = coordinates?.Latitude ?? 0;
                        request.Longitude = coordinates?.Longitude ?? 0;
                    }
                }

                await context.SaveChangesAsync();
            }
        }
Пример #2
0
        public void Process(RequestApiViewModel viewModel)
        {
            //since this is Hangfire job code, it needs to be idempotent, this could be re-tried if there is a failure
            if (context.Requests.Any(x => x.ProviderRequestId == viewModel.ProviderRequestId))
            {
                return;
            }

            var requestIsFromApprovedRegion = RequestIsFromApprovedRegion(viewModel.ProviderData);

            if (requestIsFromApprovedRegion)
            {
                var request = new Request
                {
                    RequestId = NewRequestId(),
                    //TODO mgmccarthy: this is hard-coded for now to 1, which is HTBox Org's Id in dev b/c SampleDataGenerator always creates it first. We'll need something more robust when we go to production.
                    OrganizationId    = 1,
                    ProviderRequestId = viewModel.ProviderRequestId,
                    ProviderData      = viewModel.ProviderData,
                    Address           = viewModel.Address,
                    City       = viewModel.City,
                    DateAdded  = DateTimeUtcNow(),
                    Email      = viewModel.Email,
                    Name       = viewModel.Name,
                    Phone      = viewModel.Phone,
                    State      = viewModel.State,
                    PostalCode = viewModel.PostalCode,
                    Status     = RequestStatus.Unassigned,
                    Source     = RequestSource.Api
                };

                //this is a web service call
                var coordinates = geocoder.GetCoordinatesFromAddress(request.Address, request.City, request.State, request.PostalCode, string.Empty).Result;

                request.Latitude  = coordinates?.Latitude ?? 0;
                request.Longitude = coordinates?.Longitude ?? 0;

                context.Add(request);
                context.SaveChanges();
            }

            //acceptance is true if we can service the Request or false if can't service it
            backgroundJobClient.Enqueue <ISendRequestStatusToGetASmokeAlarm>(x => x.Send(viewModel.ProviderRequestId, GasaStatus.New, requestIsFromApprovedRegion));
        }
        public async Task <Guid> Handle(EditRequestCommand message)
        {
            var request = await _context.Requests
                          .Include(l => l.Event)
                          .SingleOrDefaultAsync(t => t.RequestId == message.RequestModel.Id) ?? _context.Add(new Request {
                Source = RequestSource.UI
            }).Entity;

            var addressChanged = DetermineIfAddressChanged(message, request);

            var orgId = await _context.Events.AsNoTracking()
                        .Include(rec => rec.Campaign)
                        .Where(rec => rec.Id == message.RequestModel.EventId)
                        .Select(rec => rec.Campaign.ManagingOrganizationId)
                        .FirstOrDefaultAsync();

            request.EventId        = message.RequestModel.EventId;
            request.OrganizationId = orgId;
            request.Address        = message.RequestModel.Address;
            request.City           = message.RequestModel.City;
            request.Name           = message.RequestModel.Name;
            request.State          = message.RequestModel.State;
            request.Zip            = message.RequestModel.Zip;
            request.Email          = message.RequestModel.Email;
            request.Phone          = message.RequestModel.Phone;
            request.Latitude       = message.RequestModel.Latitude;
            request.Longitude      = message.RequestModel.Longitude;

            //If lat/long not provided and we detect the address changed, then use geocoding API to get the lat/long
            if (request.Latitude == 0 && request.Longitude == 0 && addressChanged)
            {
                var coordinates = await _geocoder.GetCoordinatesFromAddress(request.Address, request.City, request.State, request.Zip, string.Empty);

                request.Latitude  = coordinates?.Latitude ?? 0;
                request.Longitude = coordinates?.Longitude ?? 0;
            }

            _context.AddOrUpdate(request);

            await _context.SaveChangesAsync();

            return(request.RequestId);
        }
Пример #4
0
        public void Process(RequestApiViewModel viewModel)
        {
            //since this is Hangfire job code, it needs to be idempotent, this could be re-tried if there is a failure
            var requestExists = context.Requests.Any(x => x.ProviderRequestId == viewModel.ProviderRequestId);

            if (!requestExists)
            {
                var request = new Request
                {
                    RequestId = NewRequestId(),
                    //TODO mgmccarthy: this is hard-coded for now to 1, which is HTBox Org's Id in dev b/c SampleDataGenerator always creates it first. We'll need something more robust when we go to production.
                    OrganizationId    = 1,
                    ProviderRequestId = viewModel.ProviderRequestId,
                    ProviderData      = viewModel.ProviderData,
                    Address           = viewModel.Address,
                    City      = viewModel.City,
                    DateAdded = DateTimeUtcNow(),
                    Email     = viewModel.Email,
                    Name      = viewModel.Name,
                    Phone     = viewModel.Phone,
                    State     = viewModel.State,
                    Zip       = viewModel.Zip,
                    Status    = RequestStatus.Unassigned,
                    Source    = RequestSource.Api
                };

                //this is a web service call
                var coordinates = geocoder.GetCoordinatesFromAddress(request.Address, request.City, request.State, request.Zip, string.Empty).Result;

                request.Latitude  = coordinates?.Latitude ?? 0;
                request.Longitude = coordinates?.Longitude ?? 0;

                context.Add(request);
                context.SaveChanges();

                mediator.Publish(new ApiRequestProcessedNotification {
                    RequestId = request.RequestId
                });
            }
        }