Example #1
0
        public Author CreateAuthor(Author author)
        {
            if (author.AssemblyMmsIds != null)
            {
                var assemblyMmses = _assemblyMmsService.GetAssemblyMmsByIds(author.AssemblyMmsIds);
                if (assemblyMmses.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                author.AssemblyMms = assemblyMmses;
            }

            if (author.CalibrationMmsIds != null)
            {
                var calibrationMmses = _calibrationMmsService.GetCalibrationMmsByIds
                                           (author.CalibrationMmsIds);
                if (calibrationMmses.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                author.CalibrationMms = calibrationMmses;
            }

            if (author.CalibrationProductIds != null)
            {
                var calibrationProducts = _calibrationProductService.GetCalibrationProductByIds
                                              (author.CalibrationProductIds);
                if (calibrationProducts.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                author.CalibrationProduct = calibrationProducts;
            }

            if (author.ConfiguringMmsIds != null)
            {
                var configuringMmses = _configuringMmsService.GetConfiguringMmsByIds
                                           (author.ConfiguringMmsIds);
                if (configuringMmses.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                author.ConfiguringMms = configuringMmses;
            }

            if (author.ConfiguringProductIds != null)
            {
                var configuringProducts = _configuringProductService.GetConfiguringProductByIds
                                              (author.ConfiguringProductIds);
                if (configuringProducts.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                ;
                author.ConfiguringProduct = configuringProducts;
            }

            if (author.MakeProductIds != null)
            {
                var makeProducts = _makeProductService.GetMakeProductByIds
                                       (author.MakeProductIds);
                if (makeProducts.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                author.MakeProduct = makeProducts;
            }

            if (author.MobileTestingMmsIds != null)
            {
                var mobileTestingMmses = _mobileTestingMmsService.GetMobileTestingMmsByIds
                                             (author.MobileTestingMmsIds);
                if (mobileTestingMmses.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                author.MobileTestingMms = mobileTestingMmses;
            }

            if (author.MobileTestingProductIds != null)
            {
                var mobileTestingProducts = _mobileTestingProductService
                                            .GetMobileTestingProductByIds(author.MobileTestingProductIds);
                if (mobileTestingProducts.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                author.MobileTestingProduct = mobileTestingProducts;
            }

            if (author.StationaryTestingMmsIds != null)
            {
                var stationaryTestingMmses = _stationaryTestingMmsService
                                             .GetStationaryTestingMmsByIds(author.StationaryTestingMmsIds);
                if (stationaryTestingMmses.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                author.StationaryTestingMms = stationaryTestingMmses;
            }

            if (author.StationaryTestingProductIds != null)
            {
                var stationaryTestingProducts = _stationaryTestingProductService
                                                .GetStationaryTestingProductByIds(author.StationaryTestingProductIds);
                if (stationaryTestingProducts.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                author.StationaryTestingProduct = stationaryTestingProducts;
            }

            if (author.WarehouseIds != null)
            {
                var warehouses = _warehouseService.GetWarehouseByIds(author.WarehouseIds);
                if (warehouses.Any(a => a.Author != null))
                {
                    throw new ArgumentException
                              ($"THERE IS ANOTHER AUTHOR FROM SOMEONE ON THE LIST");
                }
                author.Warehouse = warehouses;
            }

            return(_authorRepository.CreateAuthor(author));
        }