public ActionResult Create() { User user = UserManager.CreateUser(); UserDto userDto = UserDto.Create(user); return(new JsonServiceStackResult(userDto)); }
public async Task <IEnumerable <UserDto> > GetUsers() { var users = await _context.Users.Take(100).ToListAsync(); var output = new List <UserDto>(); foreach (var user in users) { var isSeller = await _userManager.IsInRoleAsync(user, UserRole.Seller); var isAdmin = await _userManager.IsInRoleAsync(user, UserRole.Admin); var products = isSeller || isAdmin ? await _context.Products.Where(p => p.SellerId.Equals(user.Id)).Select(p => p.Id).ToListAsync() : null; var purchases = await _context.Purchases.Where(p => p.UserId.Equals(user.Id)).ToListAsync(); var gainedPurchases = isSeller || isAdmin ? await _context.Purchases .Where(p => products.Contains(p.ProductId) && p.IsFinished) .Select(p => p.TotalPrice).ToListAsync() : null; var gained = gainedPurchases?.Aggregate(0d, (current, next) => current + next) ?? 0; output.Add(UserDto.Create(user, isSeller ? UserRole.Seller : isAdmin ? UserRole.Admin : "User", products?.Count ?? 0, purchases, gained)); } return(output); }
public ActionResult Create() { User user = UserManager.CreateUser(); UserDto userDto = UserDto.Create(user); return(new JsonDataContractActionResult(userDto)); }
public ActionResult Get(Guid id) { User user = UserDao.Get(id); UserDto userDto = UserDto.Create(user); return(new JsonDataContractActionResult(userDto)); }
public ActionResult Get(Guid id) { User user = UserDao.Get(id); UserDto userDto = UserDto.Create(user); return(new JsonServiceStackResult(userDto)); }
public ActionResult GetByGooglePlusId(string googlePlusId) { User user = UserDao.GetByGooglePlusId(googlePlusId); UserDto userDto = UserDto.Create(user); return(new JsonServiceStackResult(userDto)); }
public async Task <UserDto> FindByNameAsync(string userName) { var user = await _userManager.FindByNameAsync(userName); var roles = await _userManager.GetRolesAsync(user); var claims = await _userManager.GetClaimsAsync(user); return(UserDto.Create(user.Id, user.FirstName.ToLower(), user.LastName.ToLower(), user.Email.ToLower(), user.Cpf, roles, claims)); }
public JsonResult Get(Guid id) { UserDto userDto; using (ITransaction transaction = Session.BeginTransaction()) { User user = UserManager.Get(id); userDto = UserDto.Create(user); transaction.Commit(); } return(Json(userDto)); }
public void Should_return_user_by_id_same_as_from_repository() { // Arrange var userId = 0; var expected = UserDto.Create(_userRepository.Get(userId)); // Act var result = _userService.Get(userId); // Assert Assert.That(result != null); Assert.That(result.EquivalentTo(expected)); }
public async Task <IActionResult> Get(string userID) { var user = await dbContext.Users.FirstOrDefaultAsync(u => u.Id == userID); if (user == null) { return(CodeResultAndLog(HttpStatusCode.NotFound, $"Could not find user with ID '{userID}'.")); } var response = UserDto.Create(user, cdnService); return(CodeResult(HttpStatusCode.OK, response)); }
public UserDto Create(UserDto userDto) { UserDto createdUserDto; using (ITransaction transaction = Session.BeginTransaction()) { User user = UserManager.CreateUser(userDto.GooglePlusId ?? string.Empty); createdUserDto = UserDto.Create(user); transaction.Commit(); } return(createdUserDto); }
public UserDto MergeByGooglePlusId(Guid id, string googlePlusId) { UserDto userDto; using (ITransaction transaction = Session.BeginTransaction()) { User googlePlusUser = UserManager.MergeByGooglePlusId(id, googlePlusId); userDto = UserDto.Create(googlePlusUser); transaction.Commit(); } return(userDto); }
public JsonResult GetByGooglePlusId(string googlePlusId) { UserDto userDto; using (ITransaction transaction = Session.BeginTransaction()) { User user = UserManager.GetByGooglePlusId(googlePlusId); userDto = UserDto.Create(user); transaction.Commit(); } return(Json(userDto)); }
public void SignInAsyncSuccess() { var identityResult = SignInResult.Success; var repository = Substitute.For <IIdentityRepository>(); repository.SignInAsync(Arg.Any <string>(), Arg.Any <string>()) .Returns(x => identityResult); repository.FindByNameAsync(Arg.Any <string>()).Returns(UserDto .Create("", "Ton", "Gomes", "*****@*****.**", "31076292860", new List <string> { "admin" }, new List <Claim>()) ); var result = HandleLoginUserCommand(new LoginUserCommand { Cpf = "31076292860", Password = "******" }, repository); var jwtToken = result.JwtToken; result.Should().BeEquivalentTo(new LoginUserResultDto(jwtToken, true, string.Empty)); }
public async Task <IdentityResultDto> Handle(RegisterUserCommand request, CancellationToken cancellationToken) { var result = await _userRepository.CreateAsync(UserDto.Create(request), "citizen"); return(new IdentityResultDto(result.Succeeded, result.Errors.Select(x => x.Description))); }
public UserDto Create(CreateUserDto user) { User newUser = _userRepository.Add(new User(user.Email, user.Name, user.Type)); return(UserDto.Create(newUser)); }
public UserDto Get(Int32 userId) { return(UserDto.Create(_userRepository.Get(userId))); }