public async Task <object> Post(string table, [FromBody] object detail) { int?id = AccessWrapper.Add(this.Settings, GetTable(table), detail); StatusCode(id.HasValue ? HttpStatusCode.Created : HttpStatusCode.BadRequest); return(await Get(table, id.ToString())); }
/// <summary> /// </summary> /// <param name="type"></param> private void AddTable(Type type) { String name = AccessWrapper.GetTableName(type); if (name != null) { this.tables.Add(name.ToUpper().Replace(" ", ""), type); } }
public async Task <object> Get(string table, string id) { int realId; object result = null; if (int.TryParse(id, out realId)) { result = AccessWrapper.Get(this.Settings, GetTable(table), realId).FirstOrDefault(); } if (string.Compare("Template", id, true) == 0) { result = Activator.CreateInstance(GetTable(table)); } if (result == null) { throw new ArgumentException("Invalid argument."); } return(await Task.Run(() => result)); }
/// <summary> /// Create the status object. /// </summary> /// <param name="settings">The access settings.</param> public SystemStatus(AccessSettings settings) { this.Requested = DateTime.UtcNow; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); this.DatabaseTime = AccessWrapper.QueryDatabase <DateTime>(settings, "SELECT Now() AS [Date]", (reader) => { DateTime result = DateTime.MinValue; if (reader.HasRows) { reader.Read(); int ordinal = reader.GetOrdinal("Date"); result = reader.GetDateTime(ordinal); } return(result); }); stopWatch.Stop(); this.QueryTimeInMilliseconds = stopWatch.ElapsedMilliseconds; this.QueryTimeInTicks = stopWatch.ElapsedTicks; }
public async Task <object> Get(string table) { return(await Task.Run(() => AccessWrapper.Get(this.Settings, GetTable(table), null).ToArray())); }
public async Task Delete(string table, int id) { StatusCode(HttpStatusCode.Accepted); await Task.Run(() => AccessWrapper.Delete(this.Settings, GetTable(table), id)); }
public async Task <object> Put(string table, int id, [FromBody] object detail) { AccessWrapper.Modify(this.Settings, GetTable(table), id, detail); StatusCode(HttpStatusCode.Accepted); return(await Get(table, id.ToString())); }