Example #1
0
 public Author GetAuthorById(int id)
 {
     using (var context = new DataContext())
     {
         return context.Authors.First(x => x.Id == id);
     }
 }
Example #2
0
 public void Delete(int id)
 {
     using (var context = new DataContext())
     {
         context.Authors.Remove(context.Authors.First(x => x.Id == id));
         context.SaveChanges();
     }
 }
Example #3
0
        public Author Save(Author author)
        {
            using (var context = new DataContext())
            {
                if (author.Id == 0)
                {
                    context.Authors.Add(author);
                }
                else
                {
                    context.Entry(author).State = EntityState.Modified;
                    context.Authors.AddOrUpdate(author);
                }
                context.SaveChanges();

            }
            return author;
        }
Example #4
0
        public List<Author> GetAuthors()
        {
            using (var context = new DataContext())
            {
                return context.Authors.ToList();
            }

            //List<Author> authors = new List<Author>();

            //Author author = new Author();
            //author.Id = 1;
            //author.FirstName = "James";
            //author.LastName = "West";

            //authors.Add(author);

            //return authors;
        }