Example #1
0
        public async Task SetupBaseData(HttpRequestMessage req)
        {
            var config = await _configRepo.GetItemAsync(Config.ConfigId);

            if (config != null && config.BaseDataSetup)
            {
                return;
            }
            try
            {
                await _userService.GetAllUsers(req);    //This will save all users into the document DB, this may be slow if there are many users!
            }
            catch (Exception exp)
            {
                throw new Exception("Unable to save all users: " + exp.Message + exp.StackTrace);
            }

            await _metadataRepository.CreateOrUpdateItemAsync(BaseMetadata.metaData, req);

            await _eventReminderRepo.CreateOrUpdateItemAsync(BaseEventReminder.EventReminder, req);


            await _configRepo.CreateOrUpdateItemAsync(new Config()
            {
                id                      = Config.ConfigId,
                BaseDataSetup           = true,
                JourneyCounter          = 1,
                JourneyApprovalsEnabled = false // Note - The approvals feature was implemented before client decided it wasn't needed. Can turn on again here if they change their mind again!
            }, req);
        }
Example #2
0
        public async Task <HttpResponseMessage> Post(HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                await _journeyRepository.InitializeAsync();
            }
            catch (Exception ex)
            {
                log.Error($"Error initialising database: {ex.ToString()}");
                return(req.CreateResponse(HttpStatusCode.BadRequest));
            }

            await SetupBaseData(req);

            await UpdateUserRoles(req);

            await UpdateUserRoles(req);

            // var sampleFile = await AddSampleFile(req);

            foreach (var journey in SampleJourneys.All)
            {
                var c = await _journeyService.CreateOrUpdateAsync(journey, req);
            }

            var orgs = new List <Organisation>();

            foreach (var org in SampleOrgs.All)
            {
                orgs.Add(org);
                await _orgRepository.CreateOrUpdateItemAsync(org, req);
            }

            foreach (var driver in SampleDrivers.All)
            {
                driver.Organisation = SampleOrgs.Organisation1;

                var t = await _driverRepo.CreateOrUpdateItemAsync(driver, req);
            }

            var vehicles = new List <Vehicle>();

            foreach (var vehicle in SampleVehicles.All)
            {
                vehicles.Add(vehicle);
                await _vehicleRepo.CreateOrUpdateItemAsync(vehicle, req);
            }

            foreach (var journey in SampleJourneys.All)
            {
                await _journeyRepository.CreateOrUpdateItemAsync(journey, req);
            }

            var config = await _configRepo.GetItemAsync(Config.ConfigId);

            return(req.CreateResponse(HttpStatusCode.Created));
        }