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 }); } } }
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); } }
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("Автор не найден"); } }