示例#1
0
        public async Task AttachModelToManufacturer(int id, CreateUpdateModelDto model, CancellationToken token)
        {
            var manufacturer = await ManufacturerRepository.FindByIdAsync(id, token);

            if (manufacturer == null)
            {
                throw new ApplicationException("Manufacturer with given Id doesn't exist.");
            }

            var modelToCreate = new Model
            {
                Name            = model.Name,
                ProductionStart = DateTime.Parse(model.ProductionStart),
                ProductionEnd   = DateTime.Parse(model.ProductionEnd),
                ManufacturerId  = id,
            };

            await ModelRepository.CreateAsync(modelToCreate, token);

            await UnitOfWork.CommitAsync(token);
        }