HTTPPOST: Create API to add new item in the database | ASP.NET Core 5.0 Web API Tutorial

preview_player
Показать описание
Asp.Net Core Web API 5.0 Tutorial

===================================
===================================

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

Follow us on
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

Popular free courses from WebGentle
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Рекомендации по теме
Комментарии
Автор

why passing controller name again in CreatedAtAction menthod?
if we dont pass controller name like "return CreatedAtAction(nameof(GetBookById), new { id = id }, booksModel)" it does not make any difference in location url

SalluBhai
Автор

How are you auto generating the id here?

vaibhavjain
Автор

we can also use EF directly for adding anything to DB if we have database scaffolded right?

gauravshinde
Автор

I am a beginner in the web api technology.

I am confused between the following code snippets.

Code snippet1:

public async Task<int> AddBook(BookModel book)
{
Book newBook = _mapper.Map<Book>(book);
await
_context.SaveChanges();
return newBook.BookId;
}
Code snippet2:

public async Task<int> AddBook(BookModel book)
{
Book newBook = _mapper.Map<Book>(book);
await _context.Books.Add(newBook);
_context.SaveChangesAsync();
return newBook.BookId;
}
I have the following questions
Q1) What is the difference between code snippet1 and code snippet2?
Q2) When should we use async and await?
Q3) What if I use async and do not use await?
Q4) What if I do not use async at all the method declaration?
Q5) In controller why should we return the ActionResult as async?

bhavyareddy
Автор

I have one error can you solve it?
error: A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
please reply as soon as possible

vechnogamers
Автор

not understand why you still want to create the bookmodel since all the properties in the bookmodel class is same as per book class

darkshadowgks
visit shbcf.ru