public async Task <int> AddPhotoAsync(CarPhotoCreateCommand createCommand) { await ValidatorFactory.GetValidator <CarPhotoCreateCommand>().ValidateAndThrowAsync(createCommand); try { await UnitOfWork.BeginTransactionAsync(); var fileName = await _fileManager.SaveAsync(createCommand.Photo, FileDestinations.CarPhoto); var item = createCommand.ToCarPhoto(fileName); await WriteRepository.AddAsync(item); await UnitOfWork.CommitAsync(); return(item.Id); } catch { _fileManager.RollBack(); await UnitOfWork.RollbackAsync(); throw; } }
public async Task AssignAsync(CarEngineGearboxAssignCommand assignCommand) { await ValidatorFactory.GetValidator <CarEngineGearboxAssignCommand>().ValidateAndThrowAsync(assignCommand); await WriteRepository.AddAsync(Mapper.Map <EngineSupportsGearbox>(assignCommand)); await UnitOfWork.CommitAsync(); }
public async Task AssignAsync(CarBodyTypeAssignCommand assignCommand) { await ValidatorFactory.GetValidator <CarBodyTypeAssignCommand>().ValidateAndThrowAsync(assignCommand); await WriteRepository.AddAsync(Mapper.Map <ModelSupportsBodyType>(assignCommand)); await UnitOfWork.CommitAsync(); }
public virtual async Task <int> AddAsync(TCreateCommand createCommand) { await ValidatorFactory.GetValidator <TCreateCommand>().ValidateAndThrowAsync(createCommand); var item = Mapper.Map <TDataModel>(createCommand); await WriteRepository.AddAsync(item); await UnitOfWork.CommitAsync(); return(item.Id); }
public override async Task <int> AddAsync(WorkOrderCreateCommand createCommand) { await ValidatorFactory.GetValidator <WorkOrderCreateCommand>().ValidateAndThrowAsync(createCommand); var works = await _readRepository.GetAsync(_workFiltersProvider.ByIds(createCommand.WorksIds.Distinct())); var item = Mapper.Map <Data.Models.WorkOrder.WorkOrder>(createCommand); item.TotalPrice = works.Sum(x => x.Price); await WriteRepository.AddAsync(item); await UnitOfWork.CommitAsync(); return(item.Id); }
public async Task <int> AddWithDeliveryRequestAsync(OrderWithDeliveryRequestCreateCommand command) { await ValidatorFactory.GetValidator <OrderWithDeliveryRequestCreateCommand>().ValidateAndThrowAsync(command); await UnitOfWork.BeginTransactionAsync(); var item = Mapper.Map <Data.Models.Order.Order>(command); item.DeliveryRequest = Mapper.Map <DeliveryRequest>(command); await WriteRepository.AddAsync(item); await UnitOfWork.CommitAsync(); return(item.Id); }
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); } }
public override async Task <int> AddAsync(CarStockCreateCommand createCommand) { await ValidatorFactory.GetValidator <CarStockCreateCommand>().ValidateAndThrowAsync(createCommand); using (await BusinessLocks.CarStockLock.LockAsync()) { var car = await _readRepository.GetSingleAsync(_carStockFiltersProvider.MatchAll(createCommand.ModelId, createCommand.BodyTypeId, createCommand.ColorId, createCommand.EngineGearboxId, createCommand.ComplectationId)); if (car == null) { car = Mapper.Map <CarStock>(createCommand); car.Price = await _carStockCommandRepository.CalculateCarPriceAsync(car.ModelId, car.BodyTypeId, car.EngineGearboxId, car.ComplectationId); await WriteRepository.AddAsync(car); await UnitOfWork.CommitAsync(); } return(car.Id); } }
public void AddAsync_Should_Add_Data_And_Should_Return_Exptected(Mock <ISessionManager> mockSessionManager, DefaultSession session, Dummy data) { //Arrange mockSessionManager.Setup(m => m.Current) .Returns(session); var options = new DbContextOptionsBuilder <DummyContext>() .UseInMemoryDatabase("DummyDb") .Options; //Act var context = new DummyContext(options, mockSessionManager.Object); var repository = new WriteRepository <DummyContext, Dummy>(context); repository.AddAsync(data); //Assert Dummy dummyData = repository.GetById(data.Id); dummyData.Should().BeEquivalentTo(data); context.Dispose(); }