示例#1
0
        public async Task <ServiceResult> RecoverPriceTresholdAsync(int id)
        {
            var obj = await _repository.FindAsync(id);

            var conflictingItem = _repository.FirstOrDefault(x => x.IsDeleted != true && (x.MinCharges == obj.MinCharges || x.PricePerCharge == obj.PricePerCharge));

            if (conflictingItem != null)
            {
                if (conflictingItem.MinCharges == 0 && obj.MinCharges == 0)
                {
                    conflictingItem.IsDeleted = true;
                    _repository.Edit(conflictingItem);

                    obj.IsDeleted = false;
                    _repository.Edit(obj);
                    await _unitOfWork.CommitAsync();

                    return(ServiceResult.Success("Przywrócono przedział cenowy, oraz podmieniono już z isntiejącym - kolidującym"));
                }
                return(ServiceResult <PriceTresholdBaseDto, PrcAdminCreateInfo>
                       .Failure($"Nie można przywrócić przedziału, koliduje z przedziałem o wartościach: (min. wyjazdy: {conflictingItem.MinCharges}, cena za szt.: {conflictingItem.PricePerCharge.ToString("##.00")})"));
            }
            obj.IsDeleted = false;
            _repository.Edit(obj);
            await _unitOfWork.CommitAsync();

            return(ServiceResult.Success("Przywrócono przedział cenowy."));
        }