示例#1
0
        private void Handle(MaintenanceJobUpdated e)
        {
            MaintenanceJob job      = Jobs.FirstOrDefault(j => j.Id == e.JobId);
            Customer       customer = new Customer(e.CustomerInfo.Id, e.CustomerInfo.Name, e.CustomerInfo.TelephoneNumber);
            Vehicle        vehicle  = new Vehicle(e.VehicleInfo.LicenseNumber, e.VehicleInfo.Brand, e.VehicleInfo.Type, customer.Id);

            job.Update(e.StartTime, e.EndTime, vehicle, customer, e.Description);
        }
示例#2
0
        public void UpdateMaintenanceJob(UpdateMaintenanceJob command)
        {
            // check business rules
            this.UpdatedMaintenanceJobShouldFallWithinOneBusinessDay(command);
            this.NumberOfParallelMaintenanceJobsMustNotExceedAvailableWorkStations(command);
            this.NumberOfParallelMaintenanceJobsOnAVehicleIsOne(command);

            // handle event
            MaintenanceJobUpdated e = command.MapToMaintenanceJobUpdated();

            RaiseEvent(e);
        }
示例#3
0
        private async Task HandleAsync(MaintenanceJobUpdated mju)
        {
            var job = new MaintenanceJob
            {
                JobId         = mju.JobId.ToString(),
                CustomerId    = mju.CustomerInfo.Id,
                LicenseNumber = mju.VehicleInfo.LicenseNumber,
                StartTime     = mju.StartTime,
                Description   = mju.Description
            };

            Log.Information("Update Maintenance Job: {Id}, {CustomerId}, {VehicleLicenseNumber}, {StartTime}, {Description}",
                            job.JobId, job.CustomerId, job.LicenseNumber, job.StartTime, job.Description);

            await _repo.UpdateMaintenanceJobAsync(job);
        }
示例#4
0
        private async Task <bool> HandleAsync(MaintenanceJobUpdated e)
        {
            Log.Information("Updated Maintenance Job: {JobId}, {StartTime}, {EndTime}, {CustomerName}, {LicenseNumber}",
                            e.JobId, e.StartTime, e.EndTime, e.CustomerInfo.Name, e.VehicleInfo.LicenseNumber);

            try
            {
                using (var transaction = await _dbContext.Database.BeginTransactionAsync())
                {
                    var customer = await _dbContext.Customers
                                   .FirstOrDefaultAsync(c => c.CustomerId == e.CustomerInfo.Id);

                    if (customer == null)
                    {
                        throw new InvalidOperationException($"Customer not found {e.CustomerInfo.Id}");
                    }

                    customer.CustomerId      = e.CustomerInfo.Id;
                    customer.Name            = e.CustomerInfo.Name;
                    customer.TelephoneNumber = e.CustomerInfo.TelephoneNumber;

                    var vehicle = await _dbContext.Vehicles
                                  .FirstOrDefaultAsync(v => v.LicenseNumber == e.VehicleInfo.LicenseNumber);

                    if (vehicle == null)
                    {
                        throw new InvalidOperationException($"Vehicle not found {e.VehicleInfo.LicenseNumber}");
                    }

                    vehicle.LicenseNumber = e.VehicleInfo.LicenseNumber;
                    vehicle.Brand         = e.VehicleInfo.Brand;
                    vehicle.OwnerId       = customer.CustomerId;
                    vehicle.Type          = e.VehicleInfo.Type;

                    var job = await _dbContext.MaintenanceJobs
                              .FirstOrDefaultAsync(j => j.Id == e.JobId);

                    if (job == null)
                    {
                        throw new InvalidOperationException($"Job not found {e.JobId}");
                    }

                    job.Id        = e.JobId;
                    job.StartTime = e.StartTime;
                    job.EndTime   = e.EndTime;
                    job.Customer  = customer;
                    job.Vehicle   = vehicle;

                    // update maintetancejob

                    _dbContext.MaintenanceJobs.Update(job);

                    await _dbContext.SaveChangesAsync();

                    await transaction.CommitAsync();
                }
            }
            catch (InvalidOperationException ex)
            {
                Log.Warning($"Skipped updating maintenance job: {ex.Message}");
            }
            catch (DbUpdateException)
            {
                Log.Warning("Skipped updating maintenance job with id {JobId}.", e.JobId);
            }

            return(true);
        }