private async Task <OrderPaymentInfo> PrepareCompletePayuRequestAsync(PaymentRequest request) { var product = request.products.First(); var priceTreshold = (await _pricesRepository.GetAllAsync(x => x.MinCharges <= Convert.ToInt32(product.quantity) && !x.IsDeleted)) .OrderByDescending(x => x.MinCharges).First(); var totalPrice = (priceTreshold.PricePerCharge * Convert.ToInt32(product.quantity)); product.unitPrice = (priceTreshold.PricePerCharge * 100).ToString("####"); request.extOrderId = (await _orderService.GenerateExternalOrderIdAsync()).Result.ToString(); request.totalAmount = (totalPrice * 100).ToString("####"); request.merchantPosId = _paymentSettings.PosID; return(new OrderPaymentInfo { TotalAmount = totalPrice, PricePerCharge = priceTreshold.PricePerCharge, PriceTresholdId = priceTreshold.Id }); }
public new async Task <ServiceResult <PriceTresholdBaseDto, PrcAdminCreateInfo> > CreateAsync(PriceTresholdBaseDto entity) { var createInfo = new PrcAdminCreateInfo(); var recoverItem = await _repository.FirstOrDefaultAsync(x => x.IsDeleted && x.MinCharges == entity.MinCharges && x.PricePerCharge == entity.PricePerCharge); if (recoverItem != null) { recoverItem.IsDeleted = false; _repository.Edit(recoverItem); await _unitOfWork.CommitAsync(); createInfo.Recovered = true; return(ServiceResult <PriceTresholdBaseDto, PrcAdminCreateInfo> .Success(_mapper.Map <PriceTresholdBaseDto>(recoverItem), createInfo)); } var conflictingItems = await _repository.GetAllAsync(x => !x.IsDeleted && (x.MinCharges == entity.MinCharges || x.PricePerCharge == entity.PricePerCharge)); if (conflictingItems.Any()) { if (entity.MinCharges == 0) { var currentDefault = await _repository.FirstOrDefaultAsync(x => !x.IsDeleted && x.MinCharges == 0); currentDefault.IsDeleted = true; foreach (var conflictingItem in conflictingItems) { conflictingItem.IsDeleted = true; _repository.Edit(conflictingItem); } createInfo.ReplacedDefault = true; } else { return(ServiceResult <PriceTresholdBaseDto, PrcAdminCreateInfo> .Failure($"Podane wartości kolidują z już istniejącym przedziałem (min. wyjazdy: {conflictingItems.First().MinCharges}, cena za szt.: {conflictingItems.First().PricePerCharge.ToString("##.00")})")); } } var newPrc = _repository.Add(_mapper.Map <PriceTreshold>(entity)); await _unitOfWork.CommitAsync(); return(ServiceResult <PriceTresholdBaseDto, PrcAdminCreateInfo> .Success(_mapper.Map <PriceTresholdBaseDto>(newPrc), createInfo)); }