Esempio n. 1
0
        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);
        }
Esempio n. 2
0
            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);
            }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
            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);
            }
Esempio n. 11
0
            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);
            }
Esempio n. 12
0
        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()));
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 15
0
        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);
        }
Esempio n. 17
0
        public IActionResult Post(CreateRide newRide)
        {
            var ride = new Ride(newRide);

            return(Accepted(_ridesRepository.AddAsync(ride)));
        }
Esempio n. 18
0
 public async Task <TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = new CancellationToken()) => (await Inner.AddAsync(
                                                                                                                             await entity.ResolveReferencesAsync(_repositoryFactory), cancellationToken)).DehydrateReferences();
Esempio n. 19
0
 public async Task <T> AddAsync(T entity)
 {
     return(await _crudRepository.AddAsync(entity));
 }
 public Task AddAsync(DirectDebitPayment entity) => _crudRepository.AddAsync(entity);
Esempio n. 21
0
 public Task AddAsync(ExpenseCategory entity) => _crudRepository.AddAsync(entity);
 public Task AddAsync(PosPayment entity) => _crudRepository.AddAsync(entity);