Esempio n. 1
0
        public async Task AssignAsync(DeliveryRequestAssignCommand command)
        {
            using (await BusinessLocks.DeliveryRequestAssignmentLock.LockAsync())
            {
                await ValidatorFactory.GetValidator <DeliveryRequestAssignCommand>().ValidateAndThrowAsync(command);

                var deliveryRequest = await _readRepository.GetByIdAsync <DeliveryRequest>(command.DeliveryRequestId);

                deliveryRequest.StatusId          = (int)DeliveryRequestStatuses.InProgress;
                deliveryRequest.SupplierManagerId = command.SupplierManagerId;

                await WriteRepository.UpdateAsync(deliveryRequest);

                await UnitOfWork.CommitAsync();
            }
        }
        public override async Task <int> AddAsync(OrderFromStockCreateCommand command)
        {
            using (await BusinessLocks.OrderCreateLock.LockAsync())
            {
                await ValidatorFactory.GetValidator <OrderFromStockCreateCommand>().ValidateAsync(command);

                await UnitOfWork.BeginTransactionAsync();

                var order = Mapper.Map <Data.Models.Order.Order>(command);
                var car   = await _readRepository.GetByIdAsync <CarStock>(command.CarId);

                car.Amount--;

                await WriteRepository.AddAsync(order);

                await WriteRepository.UpdateAsync(car);

                await UnitOfWork.CommitAsync();

                return(order.Id);
            }
        }