public async Task <int> Create(int bookId, int bookRating, string content, string userId) { var book = db.Books.First(x => x.Id == bookId); book.RatingVotes = book.RatingVotes + 1; book.Rating = book.Rating + bookRating; var review = new Review { Date = DateTime.Now.ToString("dd-MMM-yyyy"), Content = content, BookTubeUserId = userId, BookId = bookId }; await db.AddAsync(review); await db.SaveChangesAsync(); return(bookId); }
public async Task <ResultModel> AddPublisher(string name, string contacts) { var publisher = new Publisher { Name = name, Contacts = contacts }; var publisherExist = db.Publishers.FirstOrDefault(x => x.Name == name); var result = new ResultModel(); if (publisherExist != null) { result.Message = "Publisher already exist!"; result.ResultId = 0; return(result); } await db.AddAsync(publisher); await db.SaveChangesAsync(); result.Message = "Publisher was successfully added!"; result.ResultId = publisher.Id; return(result); }
public async Task <ResultModel> AddAuthor(string name, string bio) { var author = new Author { Name = name, Bio = bio }; var authorExist = db.Authors.FirstOrDefault(x => x.Name == name); var result = new ResultModel(); if (authorExist != null) { result.Message = "Author already exist!"; result.ResultId = 0; return(result); } await db.AddAsync(author); await db.SaveChangesAsync(); result.Message = "Author was successfully added!"; result.ResultId = author.Id; return(result); }
public async Task <ResultModel> AddBook(string title, int authorId, int publisherId, int categoryId, int publicationYear, string isbn, string description) { var result = new ResultModel(); var bookExist = db.Books.FirstOrDefault(x => x.Title == title); if (bookExist != null) { result.Message = "Book already exist!"; result.ResultId = 0; return(result); } var author = db.Authors.First(x => x.Id == authorId); var category = db.Categories.First(x => x.Id == categoryId); var publisher = db.Publishers.First(x => x.Id == publisherId); var book = new Book { Title = title, Author = author, Category = category, Publisher = publisher, PublicationYear = publicationYear, Isbn = isbn, Description = description, PictureName = "" + (db.Books.Select(x => x.Id).Last() + 1) }; await db.AddAsync(book); await db.SaveChangesAsync(); result.Message = "Book was successfully added!"; result.ResultId = book.Id; return(result); }