コード例 #1
0
        public ClientAggregate Create(long clientId)
        {
            var clientResult = _clientsReadRepo.GetClient(clientId);

            if (clientResult is null)
            {
                throw new ArgumentException("No client with this id was found!");
            }
            var cars = _clientsReadRepo.GetClientCars(clientId).Select(c => new Car(c.Id, c.ClientId, c.BrandName,
                                                                                    c.ModelName, c.PlateNumber, c.RegistrationId)).ToList();

            if (cars is null)
            {
                throw new ArgumentException("No car for this client was found!");
            }
            var revisions = _clientsReadRepo.GetClientRevisions(clientId).Select(r => new Revision(r.Id, r.ClientId, r.CarId, r.Title, r.ProblemDetails)).ToList();

            if (revisions is null)
            {
                throw new ArgumentException(nameof(revisions), "No revision for this client was found!");
            }
            var client = new ClientAggregate(clientResult.Id, clientResult.FirstName, clientResult.LastName,
                                             clientResult.PhoneNumber, clientResult.Email, clientResult.Password,
                                             cars, revisions);

            return(client);
        }
コード例 #2
0
        public void Save(ClientAggregate client)
        {
            var createdCars      = client.Cars.Where(x => x.Id == 0).ToArray();
            var updatedCars      = client.Cars.Where(x => x.IsModified).ToArray();
            var deletedCars      = client.Cars.Where(x => x.IsDeleted).ToArray();
            var createdRevisions = client.Revisions.Where(x => x.Id == 0).ToArray();
            var updatedRevisions = client.Revisions.Where(x => x.IsModified).ToArray();
            var deletedRevisions = client.Revisions.Where(x => x.IsDeleted).ToArray();

            if (client.Id == 0 && !client.IsDeleted)
            {
                Create(client);
            }
            else if (client.IsDeleted)
            {
                Delete(client);
            }
            else if (client.IsModified)
            {
                Edit(client);
            }

            Create(createdCars);
            Edit(updatedCars);
            Delete(deletedCars);

            Create(createdRevisions);
            Edit(updatedRevisions);
            Delete(deletedRevisions);
        }
コード例 #3
0
        public ClientAggregate Create(CreateClientCommand createClientCommand)
        {
            if (createClientCommand is null || string.IsNullOrWhiteSpace(createClientCommand.LastName))
            {
                throw new ArgumentNullException(nameof(createClientCommand), "Input was null!");
            }
            var client = new ClientAggregate(createClientCommand.FirstName, createClientCommand.LastName, createClientCommand.PhoneNumber,
                                             createClientCommand.Email, createClientCommand.Password);

            return(client);
        }