ill try to locate if my data is existing to other table and get the value of it. the problem is if there is no match in the other table i got an error but there's a match the controller save the value in my database. this is my code
and i got this error: Object reference not set to an instance of an object. if the "ReceiverCityId" has no value in "Location " i got an error. plsss help i need to set value into 0 if the "ReceiverCityId" has no value in "Location "
- var rate = _rateService.GetRatebyParentId(Convert.ToInt32(pickup.Client.ParentClientId ?? 0));
- var transaction = new Transaction
- {
- Source = "Pickup",
- TransactionId = pickup.Id,
- Amount = (rate != null ? rate.RateItems.FirstOrDefault(x => x.Location ==
- _cityService.Get(pickup.ReceiverCityId).Name).Amount : 0) - 10,
- DateCreated = DateTime.Now,
- CreatedBy = User.Identity.Name,
- ReferenceNumber = pickup.ReferenceNumber
- };
- _transactionService.Add(transaction);