public async Task <IActionResult> UpdateUser(UserProfileViewModel model) { string id = User.FindFirst("id").Value; User user = await UserManager.FindByIdAsync(id); if (user == null || !user.PhoneNumberConfirmed) { return(Unauthorized()); } if (user.FileNo != model.FileNo) { return(Unauthorized()); } user = Mapper.Map(model, user); user.Activities.Add(new AccountActivity() { ActivityType = Models.Entities.Activity.AccountUpdated }); UserDataContext.Update(user); await UserDataContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Username,Email,SocialSecurityNumber,Password")] Account account) { if (id != account.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(account); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountExists(account.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(account)); }
public override async Task <Resource> ReplaceAsync(Resource resource, string correlationIdentifier) { if (resource.Identifier == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } Core2EnterpriseUser user = resource as Core2EnterpriseUser; if (string.IsNullOrWhiteSpace(user.UserName)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } IEnumerable <Core2EnterpriseUser> existingUsers = _context.Users .Select(u => (Core2EnterpriseUser)u).ToList(); if ( existingUsers.Any( (Core2EnterpriseUser existingUser) => string.Equals(existingUser.UserName, user.UserName, StringComparison.Ordinal) && !string.Equals(existingUser.Identifier, user.Identifier, StringComparison.OrdinalIgnoreCase)) ) { throw new HttpResponseException(HttpStatusCode.Conflict); } if (int.TryParse(user.Identifier, out int id) && _context.Users.Find(id) is MvcMovie.Models.User existingModelUser) { existingModelUser.DisplayName = user.DisplayName; existingModelUser.Active = user.Active; existingModelUser.UserName = user.UserName; _context.Update(existingModelUser); await _context.SaveChangesAsync(); return(user); } throw new HttpResponseException(HttpStatusCode.NotFound); }