Skip to content

Instantly share code, notes, and snippets.

View masoodwasim's full-sized avatar
🎯
Focusing

Wasim Ul Masood masoodwasim

🎯
Focusing
  • EY Global
View GitHub Profile
[assembly: WebJobsStartup(typeof(Startup))]
namespace SampleFunctionsApp
{
public class Startup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddFilter(level => true);
[FunctionName(nameof(CreateBook))]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "CreateBook")] HttpRequest req)
{
IActionResult returnValue = null;
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var input = JsonConvert.DeserializeObject<BookModel>(requestBody);
public int Update(BookModel bookModel)
{
using (IDbConnection db = new SqlConnection(Configuration.GetConnectionString("SampleDB"))
{
string sqlQuery ="UPDATE Book SET Title = @Title, " +
"Author = @Author" + "WHERE Id = @Id";
int rowsAffected = db.Execute(sqlQuery, author);
return rowsAffected;
}
}
public async Task<BookModel> GetBook(int id)
{
using (IDbConnection db = new SqlConnection(Configuration.GetConnectionString("SampleDB"))
{
var result= await db.Query<BookModel>("Select * From Book" +
WHERE Id = @Id", new { id }).SingleOrDefault();
return result;
}
}
public List<BookModel> GetLatestBooks()
{
using (IDbConnection db = new SqlConnection(Configuration.GetConnectionString("SampleDB"))
{
return db.Query<BookModel>
("Select * From Book").ToList();
}
}
public class BookModel
{
public int ID { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public string Publisher { get; set; }
public string Category { get; set; }
public decimal Price { get; set; }
}
{
"Id": 226,
"Iso": "US",
"Name": "United States",
"Iso3": "USA",
"NumCode": 840,
"PhoneCode": 1,
"id": "ca025639-d776-4444-93dd-6739b0394ae9",
"_rid": "bRZNAO4ywesBAAAAAAAAAA==",
"_self": "dbs/bRZNAA==/colls/bRZNAO4ywes=/docs/bRZNAO4ywesBAAAAAAAAAA==/",
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="parent-container d-flex">
<div class="container">
<div class="row">
<div class="col">
public class SampleDBContext : DbContext
{
public SampleDBContext(DbContextOptions<SampleDBContext> options)
: base(options)
{
}
public DbSet<BookModel> BooksDbSet { get; set; }
}
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.