public async Task AddChannel(Channel channel) { using (var uow = await _uowFactory.CreateAsync()) { var toInsert = _mapper.Map <Channel, DomainChannel>(channel); _channelRepository.InsertChannel(toInsert); await uow.CommitChangesAsync(); } }
public async Task AddAsync(Layer layer) { await using var unitOfWork = await unitOfWorkFactory.CreateAsync(); var repository = unitOfWork.GetRepository <ILayersRepository>(); await repository.AddAsync(layer); await unitOfWork.CommitAsync(); logger.LogDebug("Layer {LayerId} added", layer.Id); }
public async Task DeleteAsync(Guid id) { await using var unitOfWork = await unitOfWorkFactory.CreateAsync(); var layerRepository = unitOfWork.GetRepository <ILayersRepository>(); var mapRepository = unitOfWork.GetRepository <IMapsRepository>(); await layerRepository.DeleteByMapIdAsync(id); await mapRepository.DeleteAsync(id); await unitOfWork.CommitAsync(); logger.LogInformation("Map {MapId} deleted", id); }
private static async Task <bool> IsUniqueNameAsync(SaveMapRequest map, IUnitOfWorkFactory unitOfWorkFactory, CancellationToken cancellationToken) { await using var unitOfWork = await unitOfWorkFactory.CreateAsync(cancellationToken); var repository = unitOfWork.GetRepository <IMapsRepository>(); var exists = await repository.ExistsAsync(map.UserId, map.Name !); await unitOfWork.CommitAsync(cancellationToken); return(!exists); }
public async Task <Unit> AddUser(DTOUser user) { using (var uow = await _uowFactory.CreateAsync()) { var toInsert = _mapper.Map <DTOUser, DomainUser>(user); _userRepository.InsertUser(toInsert); await uow.CommitChangesAsync(); return(Unit.Default); } }
public async Task <List <Map> > GetMapsAsync(Guid id) { await using var unitOfWork = await unitOfWorkFactory.CreateAsync(); var repository = unitOfWork.GetRepository <IMapsRepository>(); List <Map> layers = await repository.GetByUserIdAsync(id) .ThrowOnEmptyAsync(() => new TmcException(TmcError.User.NotFound)); await unitOfWork.CommitAsync(); return(layers); }
public async Task HandleAsync(ScheduleAppointmentCommand command, CancellationToken cancellationToken = default(CancellationToken)) { using (var unitOfWork = await _unitOfWorkFactory.CreateAsync()) { // Convert from external representations to domain representations var appointmentId = new AppointmentId(command.AppointmentId); var doctorId = new DoctorId(command.DoctorId); var patientId = new PatientId(command.PatientId); var appointmentDuration = new AppointmentDuration(command.AppointmentDurationInMinutes); // Invoke domain logic await _scheduleAppointmentService.ScheduleAsync(appointmentId, doctorId, patientId, command.AppointmentAt, appointmentDuration, cancellationToken); await unitOfWork.CommitAsync(); } }
public async Task Add_NewEntity_Success() { var user = CreateUser(); await using (var unitOfWork = await unitOfWorkFactory.CreateAsync(Tag)) { var repository = unitOfWork.GetRepository <IUsersRepository>(); await repository.AddAsync(user); await unitOfWork.CommitAsync(); } await using (var unitOfWork = await unitOfWorkFactory.CreateAsync()) { var repository = unitOfWork.GetRepository <IUsersRepository>(); var storedUser = await repository.GetAsync(user.Id); await unitOfWork.CommitAsync(); Assert.Equal(user.Id, storedUser.Id); Assert.Equal(user.Name, storedUser.Name); } }