Пример #1
0
        public ActionResult Create()
        {
            User    user    = UserManager.CreateUser();
            UserDto userDto = UserDto.Create(user);

            return(new JsonServiceStackResult(userDto));
        }
Пример #2
0
        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);
        }
Пример #3
0
        public ActionResult Create()
        {
            User    user    = UserManager.CreateUser();
            UserDto userDto = UserDto.Create(user);

            return(new JsonDataContractActionResult(userDto));
        }
Пример #4
0
        public ActionResult Get(Guid id)
        {
            User    user    = UserDao.Get(id);
            UserDto userDto = UserDto.Create(user);

            return(new JsonDataContractActionResult(userDto));
        }
Пример #5
0
        public ActionResult Get(Guid id)
        {
            User    user    = UserDao.Get(id);
            UserDto userDto = UserDto.Create(user);

            return(new JsonServiceStackResult(userDto));
        }
Пример #6
0
        public ActionResult GetByGooglePlusId(string googlePlusId)
        {
            User user = UserDao.GetByGooglePlusId(googlePlusId);

            UserDto userDto = UserDto.Create(user);

            return(new JsonServiceStackResult(userDto));
        }
Пример #7
0
        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));
        }
Пример #8
0
        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));
        }
Пример #9
0
        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));
        }
Пример #10
0
        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));
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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));
        }
Пример #14
0
        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));
        }
Пример #15
0
        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)));
        }
Пример #16
0
        public UserDto Create(CreateUserDto user)
        {
            User newUser = _userRepository.Add(new User(user.Email, user.Name, user.Type));

            return(UserDto.Create(newUser));
        }
Пример #17
0
 public UserDto Get(Int32 userId)
 {
     return(UserDto.Create(_userRepository.Get(userId)));
 }