public async Task <IReadOnlyCollection <ReadModelDto> > GetManufacturerModelsAsync(int id, CancellationToken token) { var manufacturer = await ManufacturerRepository.FindByIdAsync(id, token); var models = Mapper.Map <IEnumerable <Model>, IReadOnlyCollection <ReadModelDto> >(manufacturer.Models); return(models); }
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); }
public async Task <ReadManufacturerDto> FindManufacturerAsync(int id, CancellationToken token) => Mapper.Map <Manufacturer, ReadManufacturerDto>(await ManufacturerRepository.FindByIdAsync(id, token));