コード例 #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 Update(ProviderViewModel providerViewModel)
        {
            var existedProvider = _providersService.GetEntityById(providerViewModel.Id);

            existedProvider.Name = providerViewModel.Name;

            var contacts = new List <Contact>(providerViewModel.Contacts?.Count ?? 0);

            foreach (var contact in providerViewModel.Contacts)
            {
                if (_contactsService.EntityExist(contact))
                {
                    _contactsService.UpdateEntity(contact);
                    contacts.Add(contact);
                }
                else
                {
                    contacts.Add(contact);
                }
            }
            existedProvider.Contacts = contacts;

            var imports = new List <Import>(providerViewModel.Imports?.Count ?? 0);

            foreach (var import in providerViewModel.Imports)
            {
                if (_importService.EntityExist(import.Id))
                {
                    imports.Add(_importService.GetEntityById(import.Id));
                }
            }
            existedProvider.Imports = imports;

            _providersService.UpdateEntity(existedProvider);
        }
コード例 #3
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);
        }