Esempio n. 1
0
        public async Task AddRating(long id, RatePriceSubmissionModel model)
        {
            var priceSubmission = await dbContext.PriceSubmissions.GetAsync(id);

            var rating = new Entities.PriceSubmissionRating(
                priceSubmissionId: priceSubmission.Id,
                userId: userContext.Id.Value,
                value: model.Value,
                submitedAt: DateTime.Now);

            await dbContext.UpsertAsync(new[] { rating }, options => options
                                        .SelectValues(x => new object[]
            {
                (int)x.Value,
                x.PriceSubmissionId,
                $"'{x.SubmitedAt.ToString(CultureInfo.InvariantCulture)}'",
                x.UserId
            })
                                        .WithColumns(
                                            x => x.Value,
                                            x => x.PriceSubmissionId,
                                            x => x.SubmitedAt,
                                            x => x.UserId
                                            )
                                        .ConflictOn(
                                            x => x.UserId,
                                            x => x.PriceSubmissionId
                                            ));
        }
Esempio n. 2
0
        public async Task UpdateWholesalePrices()
        {
            IReadOnlyCollection <FuelTypePrice> prices = null;

            try
            {
                prices = await priceProvider.GetPrices();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to fetch prices from Lotos website", ex);
            }

            if (!prices.Any())
            {
                throw new Exception("Failed to fetch prices from Lotos website");
            }

            var modifiedAt      = DateTime.UtcNow;
            var wholesalePrices = prices.Select(x => new FranchiseWholesalePrice(
                                                    franchiseId: franchiseId,
                                                    fuelType: x.FuelType,
                                                    amount: x.Amount,
                                                    modifiedAt: modifiedAt));

            await dbContext.UpsertAsync(wholesalePrices, options => options
                                        .WithColumns(
                                            x => x.Amount,
                                            x => x.FranchiseId,
                                            x => x.FuelType,
                                            x => x.ModifiedAt)
                                        .ConflictOn(
                                            x => x.FranchiseId,
                                            x => x.FuelType)
                                        .SelectValues(p => new object[]
            {
                p.Amount.ToString(CultureInfo.InvariantCulture),
                p.FranchiseId,
                (int)p.FuelType,
                $"'{ p.ModifiedAt.ToString(CultureInfo.InvariantCulture) }'"
            }));
        }