示例#1
0
        public void SaveBook(Book book)
        {
            BookEnt bookEnt = ConvertEntity.ConvertToBookEnt(book);

            if (book.BookId == 0)
            {
                context.Books.Add(bookEnt);
            }
            else
            {
                BookEnt dbEntry = context.Books.FirstOrDefault(b => b.BookEntId == book.BookId);
                if (dbEntry != null)
                {
                    dbEntry.Name        = book.Name;
                    dbEntry.Description = book.Description;
                    dbEntry.Price       = book.Price;
                    dbEntry.Category    = book.Category;
                    dbEntry.Author      = book.Author;
                    dbEntry.Count       = book.Count;
                }
            }
            context.SaveChanges();
        }