public async Task <bool> ExistsAsync(Guid id) { var result = await _repostory.ExistsAsync(p => p.Id == id); return(result); ; }
public async Task <bool> IsBlockedUser(Guid blockedUserId, Guid userId) { var result = await _repository.ExistsAsync(x => (x.UserId == blockedUserId && x.BlockedUserId == userId) || (x.UserId == userId && x.BlockedUserId == blockedUserId)); return(result); }
public async Task HandleAsync(CreateOrder command) { var exists = await _repository.ExistsAsync(o => o.Id == command.OrderId); if (exists) { throw new InvalidOperationException($"Order with given id: {command.OrderId} already exists!"); } _logger.LogInformation($"Fetching a price for order with id: {command.OrderId}..."); var pricingDto = await _pricingServiceClient.GetAsync(command.OrderId); if (pricingDto is null) { throw new InvalidOperationException($"Pricing was not found for order: {command.OrderId}"); } _logger.LogInformation($"Order with id: {command.OrderId} will cost: {pricingDto.TotalAmount}$."); var order = new Order(command.OrderId, command.CustomerId, pricingDto.TotalAmount); await _repository.AddAsync(order); _logger.LogInformation($"Created an order with id: {command.OrderId}, customer: {command.CustomerId}."); var spanContext = _tracer.ActiveSpan.Context.ToString(); await _publisher.PublishAsync(new OrderCreated(order.Id), spanContext : spanContext); }
public async Task HandleAsync(SignUp command) { _validator.Validate(command).ThrowIfInvalid(); var alreadyExists = await _repository.ExistsAsync(u => u.Username == command.Username || u.Email == command.Email); if (alreadyExists) { throw new UserAlreadyExistsException(command.Username, command.Email); } var salt = _passwordService.CreateSalt(); var passwordHash = _passwordService.HashPassword(command.Password, salt); var user = new IdentityDocument { Id = command.Id, Username = command.Username, FullName = command.FullName, Email = command.Email, PhoneNumber = command.PhoneNumber, Password = passwordHash, Salt = salt, UpdatedAt = DateTime.UtcNow }; await _repository.AddAsync(user); }
public async Task <bool> HasPendingOrder(Guid customerId) { var result = await _orderRepository.ExistsAsync(o => o.CustomerId == customerId && (o.Status == OrderStatus.Created || o.Status == OrderStatus.Approved)); return(result); }
public async Task <ApiBaseResponse> CommentPostAsync(CommentRequestModel comment) { var userId = Guid.Parse(_httpContextAccessor?.HttpContext?.User?.Identity?.Name); BlogStatsItem statsItem = new BlogStatsItem(); if (await _blogStatsItemRepository.ExistsAsync(c => c.PostId == comment.PostId)) { statsItem = await _blogStatsItemRepository.GetAsync(c => c.PostId == comment.PostId); statsItem.CommentCount = statsItem.CommentCount + 1; statsItem.Comments.Add(new Comment { Id = Guid.NewGuid(), UserId = userId, CommentText = comment.Comment, CreateDate = DateTime.UtcNow }); await _blogStatsItemRepository.UpdateAsync(statsItem); } else { statsItem = new BlogStatsItem { Id = Guid.NewGuid(), PostId = comment.PostId, CommentCount = 1, FavouriteCount = 0 }; statsItem.Comments.Add(new Comment { Id = Guid.NewGuid(), UserId = userId, CommentText = comment.Comment, CreateDate = DateTime.UtcNow }); await _blogStatsItemRepository.AddAsync(statsItem); } return(new ApiBaseResponse(HttpStatusCode.OK, ApplicationStatusCode.Success, null, "Succesfully commented.")); }
public async Task CreateAsync(CinemaDto dto) { var alreadyExists = await _repository.ExistsAsync(c => c.Id == dto.Id); if (alreadyExists) { throw new CinemaAlreadyExistsException(dto.Id); } var events = dto.Halls.Select(h => new HallAdded(dto.Id, h.Id)); await _repository.AddAsync(dto.AsDocument()); await _broker.PublishAsync(events); }
public async Task HandleAsync(string messageId, Func <Task> handler) { if (!Enabled) { _logger.LogWarning("Outbox is disabled, incoming messages won't be processed."); return; } if (string.IsNullOrWhiteSpace(messageId)) { throw new ArgumentException("Message id to be processed cannot be empty.", nameof(messageId)); } // unique check for our message - if messageId already processed we will not call our handler that means we will not involve our command or event handler again _logger.LogTrace($"Received a message with id: '{messageId}' to be processed."); if (await _inboxRepository.ExistsAsync(m => m.Id == messageId)) { _logger.LogTrace($"Message with id: '{messageId}' was already processed."); return; } IClientSessionHandle session = null; if (_transactionsEnabled) { session = await _sessionFactory.CreateAsync(); //important thing is here, using a transaction session.StartTransaction(); } try { _logger.LogTrace($"Processing a message with id: '{messageId}'..."); //we need to store all inbox and outbox data in same transaction and database await handler(); //outbox pattern - adding outbox event to database here with doing IMessageOutbox.SendAsync in out handler await _inboxRepository.AddAsync(new InboxMessage //inbox pattern { Id = messageId, ProcessedAt = DateTime.UtcNow }); if (session is {}) { await session.CommitTransactionAsync(); } _logger.LogTrace($"Processed a message with id: '{messageId}'."); }
public async Task HandleAsync(string messageId, Func <Task> handler) { if (!Enabled) { _logger.LogWarning("Outbox is disabled, incoming messages won't be processed."); return; } if (string.IsNullOrWhiteSpace(messageId)) { throw new ArgumentException("Message id to be processed cannot be empty.", nameof(messageId)); } _logger.LogTrace($"Received a message with id: '{messageId}' to be processed."); if (await _inboxRepository.ExistsAsync(m => m.Id == messageId)) { _logger.LogTrace($"Message with id: '{messageId}' was already processed."); return; } IClientSessionHandle session = null; if (_transactionsEnabled) { session = await _sessionFactory.CreateAsync(); session.StartTransaction(); } try { _logger.LogTrace($"Processing a message with id: '{messageId}'..."); await handler(); await _inboxRepository.AddAsync(new InboxMessage { Id = messageId, ProcessedAt = DateTime.UtcNow }); if (session is {}) { await session.CommitTransactionAsync(); } _logger.LogTrace($"Processed a message with id: '{messageId}'."); }
public async Task Handle(string messageId, string consumerType, Func <Task> handler) { if (!Enabled) { _logger.LogInformation("Inbox is disabled, incoming messages won't be processed."); return; } if (string.IsNullOrWhiteSpace(messageId)) { throw new ArgumentException("Message id to be processed cannot be empty.", nameof(messageId)); } if (string.IsNullOrWhiteSpace(consumerType)) { throw new ArgumentException("Consumer type can not be empty for message to be processed cannot be empty.", nameof(consumerType)); } if (await _inboxRepository.ExistsAsync(m => m.EventId == messageId && m.ConsumerType == consumerType)) { _logger.LogTrace($"Message with id: '{messageId}' and was already processed for '{consumerType}."); return; } try { await handler(); await _inboxRepository.AddAsync(new InboxMessage { Id = Guid.NewGuid().ToString("N"), EventId = messageId, ConsumerType = consumerType, ProcessedAt = DateTime.UtcNow }); } catch (System.Exception ex) { _logger.LogError(ex, $"There was an error when processing a message with id: '{messageId}'."); throw; } }
public async Task <IEnumerable <SprintDto> > HandleAsync(GetSprints query) { var documents = _sprintRepository.Collection.AsQueryable(); if (string.IsNullOrWhiteSpace(query.ProjectId)) { return(new List <SprintDto>()); } if (!await _projectRepository.ExistsAsync(p => p.Id == query.ProjectId)) { throw new ProjectNotFoundException(query.ProjectId); } var project = await _projectRepository.GetAsync(query.ProjectId); var sprintsWithProject = await documents.Where(p => p.ProjectId == project.Id).ToListAsync(); return(sprintsWithProject.Select(p => p.AsDto())); }
public async Task <Result> Handle(DeleteCategoryCommand request, CancellationToken cancellationToken) { var category = await _toolCategoryRepository.GetAsync(request.Id, cancellationToken); if (category is null) { return(Result.Failed(new NotFoundObjectResult(new ApiMessage(ResponseMessage.CategoryNotFound)))); } if (await _departmentRepository .ExistsAsync(x => x.IsDeleted == false && x.ToolsCategories.Any(tc => tc.Id == request.Id), cancellationToken)) { return(Result.Failed(new BadRequestObjectResult( new ApiMessage(ResponseMessage.CategoryInDepartment)))); } await _toolCategoryRepository.DeleteAsync(request.Id); return(Result.SuccessFul()); }
public Task <bool> ExistsAsync(string sprintId) => _repository.ExistsAsync(c => c.Id == sprintId);
public async Task <bool> ExistsAsync(Expression <Func <TEntity, bool> > predicate) => await _decoratedRepository.ExistsAsync(predicate);
public Task <bool> ExistsAsync(Guid id) => _repository.ExistsAsync(c => c.Id == id);
public Task <bool> ExistsAsync(AggregateId id) => _repository.ExistsAsync(r => r.Id == id);
public async Task <bool> ValidMobileAddress(RegisterCommand registerCommand, CancellationToken cancellationToken) => !await _userRepository.ExistsAsync(x => x.IsDelete == false && x.Mobile == registerCommand.Mobile, cancellationToken);
public async Task <bool> ExistsAsync(Guid id) => await _repository.ExistsAsync(p => p.Id == id);
public async Task <bool> IsEmailUnique(string email) => await _repository.ExistsAsync(x => x.Email == email.ToLowerInvariant()) == false;
public Task <bool> ExistsAsync(string projectId) => _repository.ExistsAsync(c => c.Id == projectId);
public async Task <bool> ExistsAsync(Guid id) => await _repository.ExistsAsync(item => item.Id == id);
public Task <bool> ExistsAsync(HallId hallId) => _repository.ExistsAsync(h => h.Id == hallId);
public async Task <bool> SchoolAdminExistsAsync(Guid schoolId) => await _repository.ExistsAsync(x => x.SchoolId == schoolId && (x.Roles.ToList().Contains(Role.SchoolAdmin)));
private async Task <bool> ValidName(UpdatePlanCommand updatePlanCommand, CancellationToken cancellationToken) { return(!await _planRepository.ExistsAsync(x => x.IsDeleted == false && x.Name == updatePlanCommand.Name, cancellationToken)); }
private async Task <bool> ValidEmailAddress(UpdateUserCommand updateUserCommand, CancellationToken cancellationToken) => !await _userRepository.ExistsAsync(x => x.Email == updateUserCommand.Email && x.Id != updateUserCommand.Id && x.IsDelete == false, cancellationToken);
public async Task <bool> IsExist(string name, string surname, string companyName) { var result = await _repository.ExistsAsync(x => x.Name == name && x.Surname == surname && x.CompanyName == companyName); return(result); }
public Task <bool> IsEmailInUseAsync(string email) => _repository.ExistsAsync(d => d.Email == email);
public async Task <bool> ExistsAsync(string id) => await repository.ExistsAsync(i => i.Id == id);
public Task <bool> ExistsAsync(string issueId) => _repository.ExistsAsync(c => c.Id == issueId);
public Task <bool> ExistsAsync(Guid groupId) => _repository.ExistsAsync(gi => gi.Id == groupId);