예제 #1
0
 public static bool Add(AuthorInfo ainfo)
 {
     if (dal.Exists(ainfo.Name))
     {
         return(false);
     }
     return(dal.Add(ainfo));
 }
예제 #2
0
        public async Task <BookModel> Add(BookModel book)
        {
            if (book == null)
            {
                return(null);
            }

            if (book.Id > 0)
            {
                return(book);
            }

            try
            {
                if (book.Categories != null)
                {
                    foreach (BookCategoryModel category in book.Categories)
                    {
                        await _category.Add(category);
                    }
                }

                if (book.Authors != null)
                {
                    foreach (AuthorModel author in book.Authors)
                    {
                        await _author.Add(author);
                    }
                }

                if (book.Publisher != null)
                {
                    await _publisher.Add(book.Publisher);
                }

                _context.Add(book);
                await _context.SaveChangesAsync();

                return(book);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                return(null);
            }
        }
예제 #3
0
 public void Post([FromBody] Author author)
 {
     _author.Add(author);
 }