示例#1
0
        public async Task <int> CreateBook(Book book)
        {
            int DbResult = 0;
            int authorId = 0;

            if (dataReqiered.IsDataNoEmpty(book))
            {
                bool isNewBook = await CheckingBookOnDuplicate(book);

                if (isNewBook)
                {
                    authorId = Convert.ToInt32(book.AuthorId);
                    BookPostgreSql newBook = new BookPostgreSql {
                        Name = book.Name, Description = book.Description, Year = book.Year, AuthorId = authorId
                    };

                    db.Books.Add(newBook);

                    try
                    {
                        DbResult = await db.SaveChangesAsync();
                    }
                    catch
                    {
                        return(DbResult);
                    }
                }
            }

            return(DbResult);
        }
示例#2
0
        public async Task <int> CreateAuthor(Author author)
        {
            int DbResult = 0;

            if (dataReqiered.IsDataNoEmpty(author))
            {
                AuthorPostgreSql newAuthor = new AuthorPostgreSql {
                    Name = author.Name, Surname = author.Surname
                };

                db.Authors.Add(newAuthor);
                try
                {
                    DbResult = await db.SaveChangesAsync();
                }
                catch
                {
                    return(DbResult);
                }
            }

            return(DbResult);
        }