예제 #1
0
        public ActionResult <string> Get(string context, string id)
        {
            DbContext dbContext;

            if (_detContext.GetType().Name.StartsWith(context, StringComparison.CurrentCultureIgnoreCase))
            {
                dbContext = _detContext;
            }
            else if (_infContext.GetType().Name.StartsWith(context, StringComparison.CurrentCultureIgnoreCase))
            {
                dbContext = _infContext;
            }
            else if (_obsContext.GetType().Name.StartsWith(context, StringComparison.CurrentCultureIgnoreCase))
            {
                dbContext = _obsContext;
            }
            else if (_mapContext.GetType().Name.StartsWith(context, StringComparison.CurrentCultureIgnoreCase))
            {
                dbContext = _mapContext;
            }
            else
            {
                throw new Exception();
            }
            var table  = dbContext.GetType().GetProperty(id);
            var entity = table?.GetValue(dbContext, null);

            return(Content(JsonConvert.SerializeObject(entity, new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            }), "application/json"));
        }