... just some arbitrary notes on webapi guidelines. #wip
- Is CORS enabled and/or properly configured?
[Serializable] | |
public static class CacheProvider | |
{ | |
public const string CacheFilename = "APPNAME.cache"; | |
public static string DataStoragePath() | |
{ | |
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data"); | |
} |
<template> | |
<ak-chart k-title.bind="{text: 'Gross Domestic product growth \n /GDP annual %/'}" | |
k-legend.bind="{position: 'bottom'}" | |
k-series-defaults.bind="seriesDefaults" | |
k-series.bind="series" | |
k-value-axis.bind="valueAxis" | |
k-category-axis.bind="categoryAxis" | |
k-tooltip.bind="tooltip"> | |
</ak-chart> | |
</template> |
namespace Hanssens.Integrations.RavenDb | |
{ | |
/** | |
* Built by : hanssens.com | |
* License : MIT | |
* See also : https://gist.github.com/hanssens/63db5bce5674cc950f3e | |
*/ | |
/// <summary> |
// consider the following model | |
var person = new { | |
Name = "Harry Potter", | |
DateOfBirth = DateTime.Now, | |
DateOfBirthSpecified = true | |
}; | |
// now if the 'DateOfBirth' is specified, use it's value | |
// otherwise, simply use null | |
DateTime? x = (person.DateOfBirthSpecified) ? person.DateOfBirth : null; |
public JsonResult Products(IDataTablesRequest request) | |
{ | |
// Nothing important here. Just creates some mock data. | |
var data = ProductFactory.Create(); | |
// Global filtering. | |
// Filter is being manually applied due to in-memmory (IEnumerable) data. | |
// If you want something rather easier, check IEnumerableExtensions Sample. | |
var filteredData = data.Where(_item => _item.Name.Contains(request.Search.Value)); |
public class DataController : Controller | |
{ | |
public JsonResult Products(int pageSize = 25, int skip = 0) | |
{ | |
var products = ProductFactory.Create(); | |
var total = products.Count(); | |
var data = products.Skip(skip).Take(pageSize).ToList(); | |
return Json(new { total = total, data = data }, JsonRequestBehavior.AllowGet); | |
} |
/// <summary> | |
/// Authenticates a token provided as a a header in a webapi request. | |
/// </summary> | |
public class RequireSessionKeyAttribute : ActionFilterAttribute | |
{ | |
public string TokenFieldName { get; set; } | |
public RequireSessionKey() : this("token") { } | |
public RequireSessionKey(string tokenFieldName) |
/// <summary> | |
/// Attribute that validates the provided credentials in the XHR header of an AJAX request. | |
/// </summary> | |
/// <example> | |
/// Example call: | |
/// http://stackoverflow.com/a/11960692/1039247 | |
/// </example> | |
public class BasicAuthAttribute : ActionFilterAttribute | |
{ |
public static bool IsAnyNullOrEmpty(this object obj) | |
{ | |
// could be less verbose, in on linq query, | |
// but it would come at the cost of readability | |
foreach (var pi in obj.GetType().GetProperties()) | |
{ | |
var value = (string)pi.GetValue(obj); | |
if (string.IsNullOrEmpty(value)) return false; | |
} | |