public async Task <IActionResult> Inherit(ClientInheritViewModel model) { if (ModelState.IsValid) { var client = await _clientRepository.GetByIdAsync(model.ClientId); if (client != null) { //if (model.HeirIds.Count() > 0) //{ if (!client.Active && !client.IsDeceased) { //foreach (var heirProgramNum in model.HeirIds) //{ var heir = await _clientRepository.GetClientByNumberAsync(model.HeirProgramNum); if (heir != null) { var bonusBalance = await _mileRepository.GetCurrentMilesBalanceByClientIdAsync(client.Id, "Bonus"); var statusBalance = await _mileRepository.GetCurrentMilesBalanceByClientIdAsync(client.Id, "Status"); if (bonusBalance != 0 || statusBalance != 0) { await _milesTransactionRepository.InheritMilesAsync(heir, bonusBalance, statusBalance); } client = await _clientRepository.GetByIdAsync(model.ClientId); client.IsDeceased = true; await _clientRepository.UpdateAsync(client); return(RedirectToAction(nameof(Index))); } else { //model.HeirIds.Remove(heirProgramNum); ModelState.AddModelError(string.Empty, "Entered heir is not a valid user."); } //} } else { ModelState.AddModelError(string.Empty, "Current client has either been processed for inheritance or is active. Please attempt to start this process from the clients list if you believe this to be an error."); } //} //else //{ // ModelState.AddModelError(string.Empty, "Received heirs list was empty."); //} } else { ModelState.AddModelError(string.Empty, "User account not found."); } } return(View(model)); }
public async Task <IActionResult> Inherit(int?clientId) { if (clientId == null) { return(NotFound()); } var client = await _clientRepository.GetByIdAsync(clientId.Value); if (client != null) { if (!client.Active && !client.IsDeceased) { var model = new ClientInheritViewModel { ClientId = client.Id }; return(View(model)); } } return(NotFound()); }