public async Task UpdateCurrentUser(string Token, UserUpdateDTO NewUser, CancellationToken Cancel) { if (!ModelsValidator.UserUpdateIsValid(NewUser)) { throw new ArgumentException(); } var Claims = HelperService.GetClaimsFromToken(Token, Key); var UserId = HelperService.GetIdFromToken(Claims); if (UserId == null) { throw new ArgumentNullException(); } await UserService.UpdateUser(new Guid(UserId), NewUser, Cancel); await UnitOfWork.SaveChangesAsync(Cancel); }
public async Task UpdateUser(Guid Id, UserUpdateDTO User, CancellationToken Cancel) { if (ModelsValidator.UserUpdateIsValid(User)) { if ((await UnitOfWork.UserRepository .DbSet.FirstOrDefaultAsync(item => item.Id == Id)) == null) { throw new ArgumentNullException(); } var _User = await UnitOfWork.UserRepository.DbSet.FirstOrDefaultAsync(item => item.Id == Id, Cancel); Mapper.Map(User, _User); UnitOfWork.UserRepository.Update(_User); await UnitOfWork.SaveChangesAsync(Cancel); } else { throw new ArgumentException(); } }