private void AddPublisher_Click(object sender, RoutedEventArgs e)
        {
            var addPublisherWindow = new AddPublisherWindow();

            addPublisherWindow.PublisherAdded += (_, e) => PublishingHouses.Add(e.Entity);
            addPublisherWindow.Show();
        }
        private void MenuItemDeletePublisher_OnClick(object sender, RoutedEventArgs e)
        {
            var publisher = (PublishingHouse)PublisherComboBox.SelectedItem;

            try {
                ApplicationDbContext.Instance.PublishingHouses.Remove(publisher);
                ApplicationDbContext.Instance.SaveChanges();
                PublishingHouses.Remove(publisher);
            }
            catch (Microsoft.EntityFrameworkCore.DbUpdateException) {
                MessageBox.Show("Ten wydawca jest przypisany do jakiejś książki, nie można go usunąć.", "Info",
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
        public PublishingHouses Add(PublishingHouses publisher)
        {
            if (publisher.Name.Length < 2 || publisher.Name.Length > 50)
            {
                throw new FormatException("The values for some or all of the entity fields do not meet the minimum or maximum length requirements");
            }

            else
            {
                bool isUnique = true;
                foreach (var p in booksAuthorsContext.PublishingHouses.Local)
                {
                    if (publisher.Name == p.Name && p.Id != publisher.Id)
                    {
                        isUnique = false;
                        break;
                    }
                }

                if (isUnique)
                {
                    foreach (var p in booksAuthorsContext.PublishingHouses)
                    {
                        if (publisher.Name == p.Name && p.Id != publisher.Id)
                        {
                            isUnique = false;
                            break;
                        }
                    }
                }

                else
                {
                    throw new InvalidOperationException("There are duplicate entries");
                }

                if (isUnique)
                {
                    publisher.Id = booksAuthorsContext.PublishingHouses.Local.Last().Id + 1;
                    booksAuthorsContext.PublishingHouses.Add(publisher);
                    return(publisher);
                }

                else
                {
                    throw new InvalidOperationException("There are duplicate entries");
                }
            }
        }
        public void SetLocalId(PublishingHouses publisher)
        {
            if (publisher != null && publisher.Id == 0)
            {
                try
                {
                    publisher.Id = booksAuthorsContext.PublishingHouses.Local.Last(p => p.Id != 0).Id + 1;
                }

                catch
                {
                    publisher.Id = 1;
                }
            }
        }
        public PublishingHouses Update(PublishingHouses publisher)
        {
            if (publisher.Name.Length < 2 || publisher.Name.Length > 50)
            {
                booksAuthorsContext.Entry(publisher).Reload();
                throw new FormatException("The values for some or all of the entity fields do not meet the minimum or maximum length requirements");
            }

            else
            {
                string originalFirstName = publisher.Name;

                PublishingHouses duplicatePublisher = null;

                foreach (var p in booksAuthorsContext.PublishingHouses.Local)
                {
                    if (publisher.Name == p.Name && p.Id != publisher.Id)
                    {
                        duplicatePublisher = publisher;
                    }
                }

                if (duplicatePublisher == null)
                {
                    foreach (var p in booksAuthorsContext.PublishingHouses)
                    {
                        if (publisher.Name == p.Name && p.Id != publisher.Id)
                        {
                            duplicatePublisher = publisher;
                        }
                    }
                }

                if (duplicatePublisher != null)
                {
                    publisher.Name = originalFirstName;
                    return(null);
                }

                return(publisher);
            }
        }
Example #6
0
        public PublishHouseInformation FindByName(string name)
        {
            if (name == null)
            {
                throw new System.ArgumentNullException(nameof(name));
            }

            PublishHouseInformation publishHouseInformation = null;
            PublishingHouse         publishingHouse         = PublishingHouses.FindByName(name);

            if (publishingHouse != null)
            {
                publishHouseInformation = new PublishHouseInformation()
                {
                    Category = publishingHouse.category,
                    Location = publishingHouse.location,
                    Name     = publishingHouse.name
                };
            }

            return(publishHouseInformation);
        }
Example #7
0
        public void Delete(PublishHouseInformation publishHouse)
        {
            if (publishHouse == null)
            {
                throw new System.ArgumentNullException(nameof(publishHouse));
            }

            try
            {
                PublishingHouses.Delete(new PublishingHouse()
                {
                    category = publishHouse.Category,
                    location = publishHouse.Location,
                    name     = publishHouse.Name
                });

                OnOperationExecute(true);
            }
            catch
            {
                OnOperationExecute(false);
            }
        }
 public BooksAuthorsReportForm(PublishingHouses publishingHouses)
 {
     InitializeComponent();
     this.publishingHouses = publishingHouses;
 }