コード例 #1
0
        public void UpdateImport(ImportViewModel importViewModel)
        {
            var      existedImport = _importService.GetImportWithProductsById(importViewModel.Id);
            Provider provider      = null;

            if (_providersService.EntityExist(importViewModel.Provider))
            {
                provider = _providersService.GetEntityById(importViewModel.Provider.Id);
            }

            List <ImportProduct> products = new List <ImportProduct>(importViewModel.Products?.Count ?? 0);

            foreach (var product in importViewModel.Products)
            {
                if (_productsService.EntityExist(product.ProductId.Value))
                {
                    var importProduct = new ImportProduct();
                    importProduct.Product = _productsService.GetEntityById(product.ProductId.Value);
                    importProduct.Count   = product.Count;
                    products.Add(importProduct);
                }
            }

            existedImport.CreatedDate = importViewModel.CreatedDate;
            existedImport.ImportDate  = importViewModel.ImportDate;
            existedImport.FinishDate  = importViewModel.FinishDate;
            existedImport.Status      = importViewModel.Status;
            existedImport.Provider    = provider;

            _importProductsService.DeleteEntityRange(existedImport.Products);

            existedImport.Products = products;

            _service.UpdateEntity(existedImport);
        }
コード例 #2
0
        public void Create(ProductViewModel productViewModel)
        {
            var product = new Product()
            {
                Name          = productViewModel.Name,
                ProviderPrice = productViewModel.ProviderPrice,
                State         = productViewModel.State,
                StorePrice    = productViewModel.StorePrice,
                VendorCode    = productViewModel.VendorCode,
                Count         = productViewModel.Count,
                Description   = productViewModel.Description
            };

            if (!_categoriesService.EntityExist(productViewModel.Category))
            {
                throw new EntityNotFoundException(nameof(productViewModel.Category), productViewModel.Category.Id);
            }

            var category = _categoriesService.GetEntityById(productViewModel.Category.Id);

            if (!_manufacturesManager.EntityExist(productViewModel.Manufacture))
            {
                throw new EntityNotFoundException(nameof(productViewModel.Manufacture), productViewModel.Manufacture.Id);
            }

            var manufacture = _manufacturesManager.GetEntityById(productViewModel.Manufacture.Id);

            if (!_providersManager.EntityExist(productViewModel.Provider))
            {
                throw new EntityNotFoundException(nameof(productViewModel.Provider), productViewModel.Provider.Id);
            }

            var provider = _providersManager.GetEntityById(productViewModel.Provider.Id);

            product.Category    = category;
            product.Manufacture = manufacture;
            product.Provider    = provider;

            product.State = ProductState.Awaiting;

            _productsService.CreateEntity(product);
        }
コード例 #3
0
 public bool ProviderExist(INameId provider)
 {
     return(_providersService.EntityExist(provider));
 }