Exemple #1
0
        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()));
        }
Exemple #2
0
        /// <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);
            }
        }
Exemple #3
0
        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;
        }
Exemple #5
0
 public async Task <object> Get(string table)
 {
     return(await Task.Run(() => AccessWrapper.Get(this.Settings, GetTable(table), null).ToArray()));
 }
Exemple #6
0
 public async Task Delete(string table, int id)
 {
     StatusCode(HttpStatusCode.Accepted);
     await Task.Run(() => AccessWrapper.Delete(this.Settings, GetTable(table), id));
 }
Exemple #7
0
 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()));
 }