예제 #1
0
        public async Task DeleteSubmission(long priceSubmissionId)
        {
            var priceSubmission = await dbContext.PriceSubmissions.GetAsync(priceSubmissionId);

            dbContext.PriceSubmissions.Remove(priceSubmission);
            await dbContext.SaveChangesAsync();
        }
예제 #2
0
        public async Task Update(long id, UpdateSchedulerModel model)
        {
            var scheduler = await dbContext.Schedulers.GetAsync(id);

            scheduler.Update(model);
            auditMetadataProvider.UpdateAuditMetadataInExistingEntiy(scheduler);
            await dbContext.SaveChangesAsync();
        }
예제 #3
0
        public async Task <long> Create(AddFranchiseModel model)
        {
            var franchise = new Entities.Franchise(model.Name, false);

            auditMetadataProvider.AddAuditMetadataToNewEntity(franchise);
            dbContext.Franchises.Add(franchise);
            await dbContext.SaveChangesAsync();

            return(franchise.Id);
        }
예제 #4
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());
        }
예제 #5
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);
        }
예제 #6
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();
        }
예제 #7
0
        internal async Task SeedKnownFranchises()
        {
            if (franchiseCollectionFactory.Initialized)
            {
                return;
            }

            var existingFranchises = await dbContext.Franchises.Where(x => KnownFranchises.Contains(x.Name)).ToListAsync();

            var missingFranchises = KnownFranchises.Except(existingFranchises.Select(x => x.Name))
                                    .Select(name =>
            {
                var franchise = new Franchise(name, true);
                auditMetadataProvider.AddAuditMetadataToNewEntity(franchise);
                return(franchise);
            })
                                    .ToList();

            if (missingFranchises.Any())
            {
                logger.LogInitializationProcess($"Creating franchises: { String.Join(", ", missingFranchises) }");
                dbContext.AddRange(missingFranchises);
                await dbContext.SaveChangesAsync();
            }

            var franchises = existingFranchises.Concat(missingFranchises).ToDictionary(x => x.Name, x => x.Id);

            franchiseCollectionFactory.Lotos       = franchises["Lotos"];
            franchiseCollectionFactory.Orlen       = franchises["Orlen"];
            franchiseCollectionFactory.Bp          = franchises["Bp"];
            franchiseCollectionFactory.Auchan      = franchises["Auchan"];
            franchiseCollectionFactory.Initialized = true;
        }
예제 #8
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();
            }
        }
예제 #9
0
        public async Task <long> Create(AddGasStationModel model)
        {
            var gasStation = new Entities.GasStation(
                name: model.Name,
                addressLine1: model.AddressLine1,
                addressLine2: model.AddressLine2,
                franchiseId: model.FranchiseId,
                maintainedBySystem: false,
                websiteAddress: model.WebsiteAddress);

            auditMetadataProvider.AddAuditMetadataToNewEntity(gasStation);
            dbContext.GasStations.Add(gasStation);
            await dbContext.SaveChangesAsync();

            return(gasStation.Id);
        }
예제 #10
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);
        }