public async Task <IActionResult> EditUserProfile() { User user = await _userManager.GetUserAsync(User); CryptcurAddr cryptcurAddr = _devRepo.GetCrypCurAddrById(user.Id); EditUserProfileViewModel editUserProfileViewModel = null; if (user.Role == UserRole.Dev) { Developer dev = (Developer)user; editUserProfileViewModel = new EditUserProfileViewModel { Role = dev.Role, NickName = dev.NickName, Email = dev.Email, Country = dev.Country, Region = dev.Region, SelfIntro = dev.SelfIntro, BitcoinAddr = cryptcurAddr.BitcoinAddr, EthereumAddr = cryptcurAddr.EthereumAddr, LitecoinAddr = cryptcurAddr.LitecoinAddr }; return(View(editUserProfileViewModel)); } else if (user.Role == UserRole.Buyer) { Buyer buyer = (Buyer)user; editUserProfileViewModel = new EditUserProfileViewModel { Role = buyer.Role, NickName = buyer.NickName, Email = buyer.Email, Country = buyer.Country, Region = buyer.Region, CompanyName = buyer.CompanyName, CompanyAddr = buyer.CompanyAddr, BitcoinAddr = cryptcurAddr.BitcoinAddr, EthereumAddr = cryptcurAddr.EthereumAddr, LitecoinAddr = cryptcurAddr.LitecoinAddr }; } return(View(editUserProfileViewModel)); }
public async Task <IActionResult> EditUserProfile(EditUserProfileViewModel editUserProfileViewModel) { User user = await _userManager.GetUserAsync(User); CryptcurAddr cryptcurAddr = _devRepo.GetCrypCurAddrById(user.Id); cryptcurAddr.BitcoinAddr = editUserProfileViewModel.BitcoinAddr; cryptcurAddr.EthereumAddr = editUserProfileViewModel.EthereumAddr; cryptcurAddr.LitecoinAddr = editUserProfileViewModel.LitecoinAddr; if (ModelState.IsValid) { if (user.Role == UserRole.Dev) { Developer dev = (Developer)user; dev.NickName = editUserProfileViewModel.NickName; dev.Email = editUserProfileViewModel.Email; dev.Country = editUserProfileViewModel.Country; dev.Region = editUserProfileViewModel.Region; dev.SelfIntro = editUserProfileViewModel.SelfIntro; dev.MyCryptcurAddr = cryptcurAddr; var result = await _userManager.UpdateAsync(dev); return(result.Succeeded ? RedirectToAction("Index", "Dev") : RedirectToAction("Index", "ErrorPage")); } else if (user.Role == UserRole.Buyer) { Buyer buyer = (Buyer)user; buyer.NickName = editUserProfileViewModel.NickName; buyer.Email = editUserProfileViewModel.Email; buyer.Country = editUserProfileViewModel.Country; buyer.Region = editUserProfileViewModel.Region; buyer.CompanyName = editUserProfileViewModel.CompanyName; buyer.CompanyAddr = editUserProfileViewModel.CompanyAddr; buyer.MyCryptcurAddr = cryptcurAddr; var result = await _userManager.UpdateAsync(buyer); return(result.Succeeded ? RedirectToAction("Index", "Buyer") : RedirectToAction("Index", "ErrorPage")); } } return(View(editUserProfileViewModel)); }