-
-
Save justinyoo/46eb2ea35eb4e4cd4d453751cbd70f72 to your computer and use it in GitHub Desktop.
Precompiled Azure Functions Revisited
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 ProductService | |
{ | |
... | |
public async Task<ProductModel> GetAsync(string productId) | |
{ | |
var id = Guid.Parse(productId); | |
return await this.GetAsync(id).ConfigureAwait(false); | |
} | |
public async Task<ProductModel> GetAsync(Guid productId) | |
{ | |
var product = await this._context.Products | |
.Select( | |
p => new ProductModel() | |
{ | |
ProductId = p.ProductId, | |
Name = p.Name, | |
Description = p.Description, | |
UnitPrice = p.UnitPrice | |
}) | |
.SingleOrDefaultAsync(p => p.ProductId == productId) | |
.ConfigureAwait(false); | |
return product; | |
} | |
public async Task<int> SaveAsync(ProductModel model) | |
{ | |
var now = DateTimeOffset.UtcNow; | |
var product = await this._context.Products | |
.SingleOrDefaultAsync(p => p.ProductId == model.ProductId) | |
.ConfigureAwait(false); | |
if (product == null) | |
{ | |
product = new Product() { ProductId = Guid.NewGuid(), DateCreated = now }; | |
} | |
product.Name = model.Name; | |
product.Description = model.Description; | |
product.UnitPrice = model.UnitPrice; | |
product.DateUpdated = now; | |
this._context.Products.Add(product); | |
var result = await this._context.SaveChangesAsync().ConfigureAwait(false); | |
return result; | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment