public async Task Handle(InvoiceCreated e, CancellationToken cancellationToken) { var payable = new Payable(e.ClientId, e.Amount, e.InvoiceId); await _repository.AddAsync(payable, cancellationToken); await _repository.SaveChangesAsync(cancellationToken); }
public async Task <Unit> Handle(OrderBookCommand request, CancellationToken cancellationToken) { /* * var isAlreadyOrdered = await _orders * .AnyAsync(o => o.BookTakenDate <= request.StartTime && o.OrderStatus != OrderStatus.Returned); * * if (isAlreadyOrdered) * { * //TODO: Нужно бы выкинуть исключение и перехватить в мидлваре, но для простоты реализации этого нет * return Unit.Value; * } */ var order = new Order { BookId = request.BookId, UserId = request.UserId, BookTakenDate = request.StartTime, OrderStatus = OrderStatus.InReading }; await _orders.AddAsync(order); await _unitOfWork.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public virtual async Task <IHttpActionResult> Create([CanBeNull] TEntity entity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (entity == null) { return(BadRequest("Missing request body.")); } TEntity storedEntity; try { storedEntity = await Repository.AddAsync(entity); } catch (KeyNotFoundException ex) { return(BadRequest(ex.Message)); } catch (DataException ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.GetInnerMost().Message)); } return(Created( location: new Uri(Request.RequestUri.EnsureTrailingSlash(), storedEntity.Id.ToString()), content: storedEntity)); }
public async Task Handle(CreateInvoice command, CancellationToken cancellationToken) { var invoice = new Invoice(command.ClientId, command.ContractId, command.Amount); await _repository.AddAsync(invoice, cancellationToken); await _repository.SaveChangesAsync(cancellationToken); }
public async Task Handle(ContractValidated e, CancellationToken cancellationToken) { var invoice = new Invoice(e.ClientId, e.ContractId, e.Amount); await _invoiceRepository.AddAsync(invoice, cancellationToken); await _invoiceRepository.SaveChangesAsync(cancellationToken); }
public async Task <TDtoElement> AddAsync(TDtoElement item) { var target = m_mapper.Map <TDbElement>(item); await m_repository.AddAsync(target); await m_repository.SaveAsync(); return(m_mapper.Map <TDtoElement>(target)); }
public async Task HandleAsync(CreateRide command, ICorrelationContext context) { //Todo: Check if the same driver has rides scheduled during that time var ride = new Ride(command); await _crudRepository.AddAsync(ride); // await _busPublisher.PublishAsync(new ProductCreated(command.Id, command.Name, // command.Description, command.Vendor, command.Price, command.Quantity), context); }
public async Task <Unit> Handle(CreatePayable command, CancellationToken cancellationToken) { var payable = new Payable(command.ClientId, command.Amount, command.InvoiceId, command.ContractId); await _repository.AddAsync(payable, cancellationToken); await _repository.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task Handle(ContractCreated @event, CancellationToken cancellationToken) { var c = await _contractReadModelRepository.GetByIdAsync(@event.ContractId, cancellationToken); if (c == null) { await _contractReadModelRepository.AddAsync(new ContractReadModel(@event.ContractId, @event.ClientId, 0), cancellationToken); await _contractReadModelRepository.SaveChangesAsync(cancellationToken); } }
public async Task <Unit> Handle(AddUserCommand request, CancellationToken cancellationToken) { var user = new User { Login = request.Login, FullName = request.FullName }; await _usersRepository.AddAsync(user); await _unitOfWork.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(RentalCarCommand request, CancellationToken cancellationToken) { var rental = new Rental { CarId = request.CarId, UserId = request.UserId, CarTakenDate = request.StartTime, RentalStatus = RentalStatus.InUse }; await _rentals.AddAsync(rental); await _unitOfWork.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <ActionResult> ChangeObjectType(SpaceObjectTypeDto model) { if (ModelState.IsValid) { if (model.Id > 0) { await TypesRepository.UpdateAsync(model); } else { await TypesRepository.AddAsync(model); } return(RedirectToAction("ObjectTypes")); } return(View(new SpaceObjectTypeDto())); }
public async Task AddDeleteAsyncTest() { int countOld = repository.Count; await repository.AddAsync(toAdd); int countAfterAdding = repository.Count; Assert.IsTrue(countAfterAdding == countOld + 1); int lastId = repository.GetAll().Max(x => x.Id); await repository.DeleteAsync(lastId); int countAfterDeleting = repository.Count; Assert.IsTrue(countAfterDeleting == countOld); }
private async Task <int> SaveCapitalAsync(string capitalName) { using (var context = new CountriesContext()) { var capital = await citiesRepository.GetAll(context) .FirstOrDefaultAsync(city => city.Name == capitalName) .ConfigureAwait(false); if (capital == null) { capital = new City() { Name = capitalName }; await citiesRepository.AddAsync(context, capital).ConfigureAwait(false); } await context.SaveChangesAsync().ConfigureAwait(false); return(capital.Id); } }
private async Task <int> SaveRegionAsync(string regionName) { using (var context = new CountriesContext()) { var region = await regionsRepository.GetAll(context) .FirstOrDefaultAsync(reg => reg.Name == regionName) .ConfigureAwait(false); if (region == null) { region = new Region() { Name = regionName }; await regionsRepository.AddAsync(context, region).ConfigureAwait(false); } await context.SaveChangesAsync().ConfigureAwait(false); return(region.Id); } }
public async Task AddDeleteAsyncTest() { int countOld = repository.GetAll().Count(); var first = repository.GetAll().FirstOrDefault(); int typeId = first == null ? 1 : first.TypeId; int ownerId = first == null ? 1 : first.Id; toAdd.TypeId = typeId; toAdd.OwnerId = ownerId; await repository.AddAsync(toAdd); int countAfterAdding = repository.GetAll().Count(); Assert.IsTrue(countAfterAdding == countOld + 1); int lastId = repository.GetAll().Max(x => x.Id); await repository.DeleteAsync(lastId); int countAfterDeleting = repository.GetAll().Count(); Assert.IsTrue(countAfterDeleting == countOld); }
public IActionResult Post(CreateRide newRide) { var ride = new Ride(newRide); return(Accepted(_ridesRepository.AddAsync(ride))); }
public async Task <TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = new CancellationToken()) => (await Inner.AddAsync( await entity.ResolveReferencesAsync(_repositoryFactory), cancellationToken)).DehydrateReferences();
public async Task <T> AddAsync(T entity) { return(await _crudRepository.AddAsync(entity)); }
public Task AddAsync(DirectDebitPayment entity) => _crudRepository.AddAsync(entity);
public Task AddAsync(ExpenseCategory entity) => _crudRepository.AddAsync(entity);
public Task AddAsync(PosPayment entity) => _crudRepository.AddAsync(entity);