示例#1
0
        public async Task UpdateGasStations()
        {
            var gasStations = await gasStationsFetcher.GetAuchanGasStations();

            var gasStationsQueryValues = string.Join(",", gasStations.Select((x, n) => $"({n}, '{x.Name}')"));
            var franchiseId            = franchiseCollection.Auchan;

            var missingGasStations = await dbContext.Database.GetDbConnection().QueryAsync <int>($@"
                SELECT n FROM (VALUES { gasStationsQueryValues }) as request (n, name)
                LEFT JOIN ""{ nameof(GasStation) }s"" stations
                ON stations.""{ nameof(GasStation.Name) }"" = request.name 
                    AND stations.""{ nameof(GasStation.FranchiseId) }"" = { franchiseId }
                WHERE stations.""{ nameof(GasStation.Id) }"" IS NULL");

            foreach (var index in missingGasStations)
            {
                var missingGasStation = gasStations[index];
                var gasStation        = new GasStation(
                    name: missingGasStation.Name,
                    addressLine1: missingGasStation.AddressLine1,
                    addressLine2: missingGasStation.AddressLine2,
                    franchiseId: franchiseId,
                    maintainedBySystem: true,
                    websiteAddress: missingGasStation.WebsiteAddress);

                auditMetadataProvider.AddAuditMetadataToNewEntity(gasStation);
                dbContext.Add(gasStation);
            }

            await dbContext.SaveChangesAsync();
        }
示例#2
0
        public async Task SeedSchedulers()
        {
            var franchiseCollection = franchiseCollectionFactory();
            var existingSchedulers  = await dbContext.Schedulers.AsNoTracking().Select(x => x.Id).ToListAsync();

            var missingSchedulers = AllSchedulers.Except(existingSchedulers).ToList();

            if (missingSchedulers.Any())
            {
                logger.LogInitializationProcess($"Seeding schedulers: { string.Join(",", missingSchedulers) }.");

                foreach (var schedulerId in missingSchedulers)
                {
                    var scheduler = schedulerId switch
                    {
                        0 => CreateForWholesalePrices(schedulerId, franchiseCollection.Lotos),
                        1 => CreateForWholesalePrices(schedulerId, franchiseCollection.Orlen),
                        2 => CreateForWholesalePrices(schedulerId, franchiseCollection.Bp),
                        3 => CreateForGasStations(schedulerId, franchiseCollection.Lotos),
                        4 => CreateForGasStations(schedulerId, franchiseCollection.Auchan),
                        5 => CreateForGasStationPrices(schedulerId, franchiseCollection.Auchan),
                        _ => null
                    };

                    auditMetadataProvider.AddAuditMetadataToNewEntity(scheduler);
                    dbContext.Add(scheduler);
                }

                await dbContext.SaveChangesAsync();
            }
        }
示例#3
0
        public async Task <User> Add(string nameId, RegisterModel registerModel)
        {
            var user = new Entities.User(
                nameId: nameId,
                authenticationSchema: Entities.AuthenticationSchema.Facebook,
                name: registerModel.Username,
                role: registerModel.Role,
                active: true);

            dbContext.Add(user);
            await dbContext.SaveChangesAsync();

            return(user.ToContract());
        }
示例#4
0
        public async Task <long> Create(AddCommentModel model)
        {
            var comment = new Entities.Comment(
                content: model.Content,
                createdAt: DateTime.UtcNow,
                tag: model.Tag,
                subjectId: model.SubjectId);

            auditMetadataProvider.AddAuditMetadataToNewEntity(comment);
            dbContext.Add(comment);
            await dbContext.SaveChangesAsync();

            return(comment.Id);
        }
示例#5
0
        public async Task <long> SeedSystemUser()
        {
            var existingSystemUser = await dbContext.Users.SingleOrDefaultAsync(x => x.Role == Shared.Users.UserRole.System);

            if (existingSystemUser != null)
            {
                return(existingSystemUser.Id);
            }

            logger.LogInitializationProcess("Adding system user");

            var systemUser = new User(
                name: "System",
                nameId: "SYSTEM",
                authenticationSchema: AuthenticationSchema.Internal,
                role: Shared.Users.UserRole.System,
                active: true);

            dbContext.Add(systemUser);
            await dbContext.SaveChangesAsync();

            return(systemUser.Id);
        }