public async Task <IActionResult> ManageGoldReference() { var client = await _clientRepository.GetClientByEmailAsync(User.Identity.Name); if (client == null) { return(NotFound()); } var tier = await _programTierRepository.GetByDescriptionAsync("Gold"); if (tier == null) { return(NotFound()); } if (client.ProgramTier != tier) { return(RedirectToAction(nameof(MyAccount))); } var model = new GoldReferenceViewModel(); if (client.IsInReferrerProgram) { var userIsAlreadyReferred = await _clientRepository.CheckIfClientIsAlreadyReferredAsync(client); if (userIsAlreadyReferred) { model.ReferrerClientNumber = await _clientRepository.GetReferrerClientNumber(client); model.ReferredClientNumber = client.MilesProgramNumber; model.ViewState = 0; model.Info = $"The client with number {model.ReferrerClientNumber} is sharing their Gold tier with you"; return(View(model)); } model.ReferrerClientNumber = client.MilesProgramNumber; model.ReferredClientNumber = await _clientRepository.GetReferredClientNumber(client); model.ViewState = 1; model.Info = $"You are sharing your Gold status with the client number {model.ReferredClientNumber}"; return(View(model)); } model.ReferrerClientNumber = client.MilesProgramNumber; model.ViewState = 2; model.Info = "Insert the client number with which you wish to share your Gold tier with"; return(View(model)); }
public async Task <IActionResult> ManageGoldReference(GoldReferenceViewModel model) { if (ModelState.IsValid) { string message; if (model.ViewState == 0) { return(RedirectToAction(nameof(MyAccount))); } else if (model.ViewState == 1) { message = await _clientRepository.RemoveReferenceClientsAsync(model.ReferrerClientNumber, model.ReferredClientNumber); model.ViewState = 2; ViewData["Message"] = message; return(View(model)); } var clientNumberToBeReferred = await _clientRepository.GetClientByNumberAsync(model.ReferredClientNumber); if (clientNumberToBeReferred == null) { ViewData["Message"] = "A client with this number was not found"; return(View(model)); } message = await _clientRepository.AddClientsToReferenceProgramAsync(model.ReferrerClientNumber, model.ReferredClientNumber); model.ViewState = 1; ViewData["Message"] = message; return(View(model)); } return(View(model)); }