Created
August 17, 2017 15:06
-
-
Save ksysiekj/8c79f38c5158488d9f9e5832e019b3cb to your computer and use it in GitHub Desktop.
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 BaseController : Controller | |
{ | |
protected readonly AdventureWorksDbContext _adventureWorksDbContext; | |
protected static readonly JsonSerializerSettings DefaultJsonSerializerSettings = new JsonSerializerSettings | |
{ | |
NullValueHandling = NullValueHandling.Ignore, | |
ContractResolver = new CamelCasePropertyNamesContractResolver(), | |
DateTimeZoneHandling = DateTimeZoneHandling.Utc | |
}; | |
public BaseController(AdventureWorksDbContext adventureWorksDbContext) | |
{ | |
_adventureWorksDbContext = adventureWorksDbContext; | |
} | |
} | |
[Route("api/[controller]")] | |
public class VendorsController : BaseController | |
{ | |
public VendorsController(AdventureWorksDbContext adventureWorksDbContext) : base(adventureWorksDbContext) | |
{ | |
} | |
[HttpGet] | |
public IActionResult Get(DateTime sinceModifiedDate) | |
{ | |
IQueryable<VendorViewModel> vendors = _adventureWorksDbContext.Vendors.AsNoTracking() | |
.Where(q => q.ModifiedDate >= sinceModifiedDate) | |
.Select( | |
vendor => | |
new VendorViewModel | |
{ | |
Id = vendor.VendorID, | |
IsActive = vendor.IsActive, | |
AccountNumber = vendor.AccountNumber, | |
Name = vendor.Name, | |
PreferredVendorStatus = vendor.PreferredVendorStatus | |
}); | |
return Json(vendors, DefaultJsonSerializerSettings); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment