public List <UserRecordViewModel> GetAllUsers() { List <ApplicationUser> users = _appUserService.GetAllUsers().Where(x => (DateTime.Now - x.CreatedDate).TotalDays <= 14).OrderByDescending(x => x.CreatedDate).ToList(); List <UserRecordViewModel> rez = new List <UserRecordViewModel>(); foreach (var user in users) { UserRecordViewModel usr = new UserRecordViewModel(user.Id, _appUserService.DetermineUserRole(user.Id), user.Email, user.FirstName, user.LastName, user.BirthDate, user.Title, user.CabinetAddress, user.PhoneNumber, user.ActiveAccount, user.CreatedDate); rez.Add(usr); } return(rez); }
public async Task <IActionResult> Index(IndexViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var phoneNumber = user.PhoneNumber.Decrypt(); if (model.PhoneNumber != phoneNumber) { var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, model.PhoneNumber.Encrypt()); if (!setPhoneResult.Succeeded) { throw new ApplicationException($"Unexpected error occurred setting phone number for user with ID '{user.Id}'."); } } var cabinetAddress = user.CabinetAddress.Decrypt(); if (cabinetAddress != model.CabinetAddress && model.CabinetAddress != null && _service.DetermineUserRole(model.Id).ToUpper() == "MEDIC") { _service.ModifyCabinetAddress(model.Id, model.CabinetAddress.Encrypt()); } if (model.File != null) { string id = user.Id.ToString(); await _service.UploadProfilePicture(id, model.File); } StatusMessage = "Your profile has been updated"; return(RedirectToAction(nameof(Index))); }