Пример #1
0
        public void EditClient(ClientDTO clientDTO, List <int> songlistIDs)
        {
            if (clientDTO == null)
            {
                throw new ArgumentNullException("Client service - EditClient(...)clientDTO cannot be null");
            }

            using (var uow = UnitOfWorkProvider.Create())
            {
                var client = clientRepository.GetByID(clientDTO.ID);
                if (client == null)
                {
                    throw new NullReferenceException("Client service - EditClient(...) client cannot be null(not found)");
                }

                Mapper.Map(clientDTO, client);

                if (songlistIDs != null && songlistIDs.Any())
                {
                    var songlists = songlistRepository.GetByIDs(songlistIDs);
                    client.Songlists.RemoveAll(review => !songlists.Contains(review));
                    client.Songlists.AddRange(
                        songlists.Where(review => !client.Songlists.Contains(review)));
                }
                else
                {
                    client.Songlists.Clear();
                }

                clientRepository.Update(client);
                uow.Commit();
            }
        }