Пример #1
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);
        }