This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("GetWidget")] | |
public async Task<IActionResult> GetWidget([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "/widgets/{id}")] HttpRequest req, int id, ILogger log) | |
{ | |
log.LogInformation($"getting widget: ${id}"); | |
try | |
{ | |
var selectedItem = await _dbContext.Widgets.FindAsync(id); | |
return new ObjectResult(selectedItem); | |
} | |
catch (Exception e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FunctionWrapper | |
{ | |
private readonly ILogger _log; | |
public FunctionWrapper(ILogger<FunctionWrapper> log) | |
{ | |
_log = log; | |
} | |
public async Task<IActionResult> Execute(Func<Task<IActionResult>> azureFunction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
builder.Services.AddTransient<FunctionWrapper>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Widgets | |
{ | |
private readonly DbContext _DbContext; | |
private readonly FunctionWrapper _functionWrapper; | |
public Widgets(DbContext DbContext, FunctionWrapper functionWrapper) | |
{ | |
_DbContext = DbContext; | |
_functionWrapper = functionWrapper; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<IActionResult> PostWidget( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "widgets")] Models.Widget item, ILogger log) | |
{ | |
log.LogInformation($"posting widget: ${item.Id}"); | |
var newItem = await _dbContext.Widgets.AddAsync(item); | |
await _dbContext.SaveChangesAsync(); | |
return new OkObjectResult(newItem.Entity); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace WidgetApi.Models | |
{ | |
public abstract class ModelBase | |
{ | |
public int Id { get; set; } | |
public int CreatedBy { get; set; } | |
public DateTime CreatedOn { get; set; } | |
public int? UpdatedBy { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net.Http; | |
using FluentValidation; | |
using WidgetApi.Models; | |
namespace WidgetApi.FunctionHelpers | |
{ | |
public class BaseValidator<T> : AbstractValidator<T> where T : ModelBase | |
{ | |
public BaseValidator() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Net; | |
using System.Threading.Tasks; | |
using FluentValidation; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.EntityFrameworkCore.Internal; | |
using Microsoft.Extensions.Logging; | |
using WidgetApi.Models; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net; | |
using Microsoft.AspNetCore.Mvc; | |
namespace WidgetApi.Models | |
{ | |
internal class ResponseEnvelopeResult<T> : ObjectResult where T : class | |
{ | |
/// <summary> | |
/// Data envelope for wrapping responses | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class KeyResults | |
{ | |
private readonly WidgetDbContext _dbContext; | |
private readonly FunctionWrapper<Widget> _functionWrapper; | |
public Widgets(WidgetDbContext dbContext, FunctionWrapper<Widget> functionWrapper) | |
{ | |
_dbContext = dbContext; | |
_functionWrapper = functionWrapper; | |
} |
OlderNewer