public async Task <long> Handle(Command command, CancellationToken cancellationToken) { var owner = new Owner(command.Name); _db.Owners.Add(owner); _db.BeginTransaction(); await _db.CommitTransactionAsync(); return(owner.Id); }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { try { _dbContext.BeginTransaction(); await next(); await _dbContext.CommitTransactionAsync(); } catch (Exception) { _dbContext.RollbackTransaction(); throw; } }
public async Task <long> Handle(Command command, CancellationToken cancellationToken) { var owner = await _db.Owners.FirstActiveAsync(x => x.Id == command.OwnerId).ConfigureAwait(false); if (owner == null) { return(0); } var auto = Automobile.Create(command.VehicleId, command.Make, command.Model, command.Year, command.Transmission, command.FuelType, command.BodyStyle, command.DriveTrain, command.Vin); var vehicle = Vehicle.Create(command.OwnerId, auto, command.Title, command.Description, command.Mileage, "MI", command.Url, command.ImageUrl, "foo", command.Condition, command.Price, command.Address, command.ExteriorColor, command.SalePrice, command.StateOfVehicle, 0, 0); _db.Vehicles.Add(vehicle); _db.BeginTransaction(); await _db.CommitTransactionAsync(); return(vehicle.Id); }