Ejemplo n.º 1
0
        public async Task <BlockUserServiceResult> BlockUser(string sourceUserId, string targetUserId)
        {
            var result = new BlockUserServiceResult();

            try
            {
                UserBlock userBlock = new UserBlock()
                {
                    BlockerId = sourceUserId,
                    BlockedId = targetUserId
                };

                _dbContext.UserBlocks.Add(userBlock);
                await _dbContext.SaveChangesAsync();

                result.UserBlock = userBlock;
                await _loggerService.AddUserActivity(sourceUserId, EventConstants.BlockUser, $"User blocked user {targetUserId}");
            }
            catch (Exception ex)
            {
                result.AddError(ex.GetBaseException().ToString(), ex.ToString());
                await _loggerService.AddLogEntry(ex.GetBaseException().ToString(), ex.ToString());
            }

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <LoginServiceResult> Login(LoginInput input, string ip)
        {
            var serviceResult = new LoginServiceResult();
            var user          = await _dbContext.Users.FirstOrDefaultAsync(r => r.UserName.Equals(input.UserName));

            if (user == null)
            {
                serviceResult.SetFailed(9128);

                return(serviceResult);
            }

            var passwordMatch = await _userManager.CheckPasswordAsync(user, input.Password);

            if (passwordMatch)
            {
                serviceResult.Token = await GenerateJwtToken(user);
            }
            else
            {
                serviceResult.SetFailed(1001);
            }

            await _loggerService.AddUserActivity(user.Id, EventConstants.Login, $"User logined at {ip}");

            return(serviceResult);
        }