コード例 #1
0
        public async Task EditModelAsync(int id, CreateUpdateModelDto model, CancellationToken token)
        {
            var modelToUpdate = new Model
            {
                Id              = id,
                Name            = model.Name,
                ProductionStart = DateTime.Parse(model.ProductionStart),
                ProductionEnd   = DateTime.Parse(model.ProductionEnd)
            };

            await ModelRepository.UpdateAsync(modelToUpdate, token);

            await UnitOfWork.CommitAsync(token);
        }
コード例 #2
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);
        }