コード例 #1
0
        public async Task Consume(ConsumeContext <BlockUser> context)
        {
            var message = context.Message;

            try
            {
                var user = await _userService.BlockAsync(message.Username);

                var @event = new UserBlocked
                {
                    Id       = user.Id,
                    Username = user.Username
                };

                await _bus.Publish(@event);
            }
            catch (Exception ex)
            {
                var domainException = ex as UserServiceException;
                var failedEvent     = new BlockUserFailed
                {
                    Id       = domainException?.UserId,
                    Username = message.Username
                };
                await _bus.Publish(failedEvent);

                throw;
            }
        }
コード例 #2
0
        public async Task <int> BlockUser(UserBlocked blocked)
        {
            try
            {
                int resultedId = 0;
                var reslt      = await this.therapistContext.UserBlocked.FirstOrDefaultAsync(x => x.UserId == blocked.UserId && x.BlockedUserId == blocked.BlockedUserId);

                if (reslt != null)
                {
                    reslt.IsActive  = true;
                    reslt.IsDeleted = false;
                    await this.therapistContext.SaveChangesAsync();

                    resultedId = (int)reslt.UserBlockedId;
                }
                else
                {
                    this.therapistContext.UserBlocked.Add(blocked);
                    await this.therapistContext.SaveChangesAsync();

                    resultedId = Convert.ToInt32(blocked.UserBlockedId);
                }
                await this.SaveBlockHistory(blocked.UserId, blocked.BlockedUserId, true);

                return(resultedId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        public async Task <IActionResult> PutMessage(UserBlocked message)
        {
            if (!message.messageType.Equals("UserBlocked"))
            {
                return(BadRequest());
            }

            var data = await _context.Messages.FindAsync(message.data.UserId);

            if (data == null)
            {
                Notifiy(message.data.UserId, "No UserId Found");
                return(NotFound());
            }
            _context.Entry(data).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MessageExists(message.data.UserId))
                {
                    Notifiy(message.data.UserId, "No User Found");
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            Notifiy(message.data.UserId, "Updated");
            return(Ok());
        }
コード例 #4
0
 public async Task <int> BlockUser(int userId, int blockedOrFollowerId)
 {
     try
     {
         var         now     = DateTime.UtcNow;
         UserBlocked blocked = new UserBlocked
         {
             UserBlockedId   = 0,
             UserBlockedGuid = System.Guid.NewGuid(),
             UserId          = userId,
             BlockedUserId   = blockedOrFollowerId,
             BlockedDate     = now,
             CreatedDate     = now,
             CreatedBy       = userId,
             ModifiedDate    = null,
             ModifiedBy      = null,
             IsActive        = true,
             IsDeleted       = false
         };
         return(await this._settingsRepo.BlockUser(blocked));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #5
0
        public async Task <bool> UnblockUser(UnblockUserRequest unblockUser)
        {
            try
            {
                UserBlocked userBlocked = await this.therapistContext.UserBlocked.FirstOrDefaultAsync(x => x.UserId.Equals(unblockUser.userId) && x.UserBlockedId.Equals(unblockUser.userBlockedId));

                userBlocked.IsActive     = false;
                userBlocked.IsDeleted    = true;
                userBlocked.ModifiedDate = DateTime.UtcNow;
                userBlocked.ModifiedBy   = unblockUser.userId;
                await this.therapistContext.SaveChangesAsync();

                await this.SaveBlockHistory(unblockUser.userId, unblockUser.blockedUserId, false);

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #6
0
 private void Apply(UserBlocked e)
 {
     this._blocked = true;
 }