Ejemplo n.º 1
0
        private void CommandBinding_ChangeAuthorExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            Author auth = this.authorsListView.SelectedItem as Author;

            auth.IsNew = false;
            var authWindow = new NewAuthor(auth);

            authWindow.ShowDialog();
            this.authorsListView.Items.Refresh();
        }
Ejemplo n.º 2
0
        private void CommandBinding_NewAuthorExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            Author auth       = new Author();
            var    authWindow = new NewAuthor(auth);

            if ((bool)authWindow.ShowDialog())
            {
                this.AuthorCollection.Add(auth);
            }
        }
Ejemplo n.º 3
0
        public IActionResult AddAuthor([FromBody] NewAuthor na)
        {
            Author author = new Author()
            {
                Name       = na.Name,
                AuthorType = na.AuthorType
            };

            _ctx.Add(author);
            _ctx.SaveChanges();
            return(Ok());
        }
Ejemplo n.º 4
0
 private void saveButton_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(authorNameBox.Text) && !string.IsNullOrWhiteSpace(authorSurnameBox.Text))
     {
         NewAuthor?.Invoke(this, new BookRelatedEventArgs {
             Author = new Author(authorNameBox.Text, authorSurnameBox.Text)
         });
     }
     else
     {
         MessageBox.Show(StringConstants.missingInfo);
     }
 }
Ejemplo n.º 5
0
        public ActionResult Add(NewAuthor newauthor)
        {
            DateTime born = new DateTime(Int32.Parse(newauthor.birthYear), Int32.Parse(newauthor.birthMonth), Int32.Parse(newauthor.birthDate));

            newauthor.author.Born = born;
            if ((bool)newauthor.author.isDead)
            {
                DateTime died = new DateTime(Int32.Parse(newauthor.deathYear), Int32.Parse(newauthor.deathMonth), Int32.Parse(newauthor.deathDate));
                newauthor.author.Died = died;
            }
            database.Authors.Add(newauthor.author);
            database.SaveChanges();
            return(Redirect("/Author"));
        }
Ejemplo n.º 6
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (textBox.Text == "")
            {
                MessageBox.Show("Please Enter Author Name");
            }
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("http://localhost:62135/");

                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var Profile = new NewAuthor();
                var AName   = textBox.Text;
                var url     = "api/Author/" + AName;

                var response = client.GetAsync(url).Result;

                try
                {
                    if (response.IsSuccessStatusCode)
                    {
                        var details           = response.Content.ReadAsAsync <NewAuthor>().Result;
                        List <NewAuthor> list = new List <NewAuthor>();

                        list.Add(details);

                        textBox1.Text = details.AName;
                        textBox2.Text = details.Email;
                        textBox3.Text = details.Company;
                        textBox4.Text = details.Phone;
                    }
                    else
                    {
                        MessageBox.Show(response.StatusCode + "With Message " + response.ReasonPhrase);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(Convert.ToString(ex));
                }
            }
        }
Ejemplo n.º 7
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (textBox.Text == "" && textBox2.Text == "" && textBox2.Text == "" && textBox3.Text == "")
            {
                MessageBox.Show("There is a field is empty");
            }
            else
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("http://localhost:62135/");

                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var Author = new NewAuthor();
                try
                {
                    Author.AName   = textBox.Text;
                    Author.Email   = textBox1.Text;
                    Author.Company = textBox2.Text;
                    Author.Phone   = textBox3.Text;
                }
                catch (Exception)
                {
                    MessageBox.Show("feh 8lt");
                }

                var response = client.PostAsJsonAsync("api/Author", Author).Result;
                if (response.IsSuccessStatusCode)
                {
                    MessageBox.Show("New Author has been added Succesfully");
                    clearTexts();
                }
                else
                {
                    MessageBox.Show(response.StatusCode + "With Message " + response.ReasonPhrase);
                }
            }
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("One-to-one");
            using (var db = new BookContext())
            {
                Mother m1 = new Mother {
                    Name = "Marry"
                };
                Mother m2 = new Mother {
                    Name = "Jany"
                };

                db.Mothers.Add(m1);
                db.Mothers.Add(m2);

                db.SaveChanges();

                Child c1 = new Child {
                    Id = m1.Id, Name = "Jhon"
                };
                Child c2 = new Child {
                    Id = m2.Id, Name = "Jack"
                };

                db.Children.Add(c1);
                db.Children.Add(c2);

                db.SaveChanges();
            }

            using (var db = new BookContext())
                foreach (var mother in db.Mothers.Include("Child").ToList())
                {
                    Console.WriteLine($"Mother {mother.Name} and her kid {mother.Child.Name}");
                }

            Console.WriteLine("Many-to-many");
            using (var db = new BookContext())
            {
                NewAuthor ilf = new NewAuthor  {
                    Name = "Ilya Ilf"
                };
                NewAuthor petrov = new NewAuthor  {
                    Name = "Evgeny Petrov"
                };
                NewAuthor gaiman = new NewAuthor  {
                    Name = "Neil Gaiman"
                };
                NewAuthor pratchett = new NewAuthor  {
                    Name = "Terry Pratchett"
                };
                NewAuthor jolliffe = new NewAuthor  {
                    Name = "Gray Jolliffe"
                };

                db.NewAuthors.Add(ilf);
                db.NewAuthors.Add(petrov);
                db.NewAuthors.Add(gaiman);
                db.NewAuthors.Add(pratchett);
                db.NewAuthors.Add(jolliffe);

                db.SaveChanges();

                NewBook osa = new NewBook {
                    Name = "One-story America"
                };
                NewBook go = new NewBook {
                    Name = "Good omens"
                };
                NewBook tuc = new NewBook {
                    Name = "The Unadulterated Cat"
                };

                osa.NewAuthors.Add(ilf);
                osa.NewAuthors.Add(petrov);

                go.NewAuthors.Add(gaiman);
                go.NewAuthors.Add(pratchett);

                tuc.NewAuthors.Add(pratchett);
                tuc.NewAuthors.Add(jolliffe);

                db.NewBooks.Add(osa);
                db.NewBooks.Add(go);
                db.NewBooks.Add(tuc);

                db.SaveChanges();
            }

            Console.WriteLine("Books with authors:");
            int i = 1;

            using (var db = new BookContext())
                foreach (var book in db.NewBooks)
                {
                    Console.WriteLine($"{i++}. {book.Name}");
                    using (var middleContext = new BookContext())
                    {
                        var b = middleContext.NewBooks.FirstOrDefault(x => x.Id == book.Id);
                        foreach (var author in b.NewAuthors)
                        {
                            Console.WriteLine($"\t{author.Name}");
                        }
                    }
                }

            Console.WriteLine("Authors with books:");
            i = 1;
            using (var db = new BookContext())
                foreach (var author in db.NewAuthors)
                {
                    Console.WriteLine($"{i++}. {author.Name}");
                    using (var middleContext = new BookContext())
                    {
                        var a = middleContext.NewAuthors.FirstOrDefault(x => x.Id == author.Id);
                        foreach (var book in a.NewBooks)
                        {
                            Console.WriteLine($"\t{book.Name}");
                        }
                    }
                }

            Console.ReadLine();
        }