Ejemplo n.º 1
0
 public void ShowAllAuthorsMethod()
 {
     using (Model1 context = new Model1())
     {
         foreach (Author a in context.Authors)
         {
             AllAuthors.Add(new AuthorViewModel()
             {
                 SecondName = a.SecondName, FirstName = a.FirstName, FatherName = a.FatherName
             });
         }
     }
 }
Ejemplo n.º 2
0
        public void AddAuthorMethod()
        {
            AllAuthors.Add(SelectedAuthor);
            Author OneAuthor = new Author();

            OneAuthor.FatherName = SelectedAuthor.FatherName;
            OneAuthor.FirstName  = SelectedAuthor.FirstName;
            OneAuthor.SecondName = SelectedAuthor.SecondName;
            using (Model1 context = new Model1())
            {
                context.Authors.Add(OneAuthor);
                context.SaveChanges();
            }
        }
 public void SetAuthorList(List <AuthorBO> authors)
 {
     if (AllAuthors == null)
     {
         AllAuthors = new List <SelectListItem>();
     }
     else
     {
         AllAuthors.Clear();
     }
     foreach (AuthorBO author in authors)
     {
         SelectListItem item = new SelectListItem();
         item.Value = author.AuthorID.ToString();
         item.Text  = author.Name;
         AllAuthors.Add(item);
     }
 }
Ejemplo n.º 4
0
 public void DeleteAuthorMethod()
 {
     if (CheckAuthor())
     {
         using (Model1 context = new Model1())
         {
             Author OneAuthor = context.Authors.Where(c => (c.SecondName == SelectedAuthor.SecondName) & (c.FatherName == SelectedAuthor.FatherName) & (c.FirstName == SelectedAuthor.FirstName))
                                .Include(c => c.Books).FirstOrDefault();
             context.Authors.Remove(OneAuthor);
             context.SaveChanges();
         }
         AllAuthors.Remove(SelectedAuthor);
     }
     else
     {
         MessageBox.Show("Автор не найден");
     }
 }