示例#1
0
        public async Task <WarehouseDto> CreateAsync(WarehouseDto warehouseDto)
        {
            if (warehouseDto == null)
            {
                throw new ArgumentNullException(nameof(warehouseDto));
            }

            var existingWarehouse = await _warehouseRepository.FilterAsync(x =>
                                                                           x.Name == warehouseDto.Name && x.Company.Id == warehouseDto.Company.Id);

            if (existingWarehouse.Count != 0)
            {
                throw new Exception("Warehouse with same name already exists.");
            }

            var warehouse = _mapper.Map <WarehouseDto, Warehouse>(warehouseDto);

            _warehouseRepository.Add(warehouse);

            await _warehouseRepository.SaveChangesAsync();

            return(_mapper.Map <Warehouse, WarehouseDto>(warehouse));
        }