Ejemplo n.º 1
0
        public async Task <object> Save([FromBody] JObject o, [FromQuery] string type)
        {
            var assembly     = _context.GetType().Assembly;
            var assemblyName = assembly.GetName().Name;
            var objectType   = assembly.GetType($"{assemblyName}.Models.{type}");
            var entity       = o.ToObject(objectType);
            var id           = objectType.GetProperty("Id")?.GetValue(entity);
            var result       = id == null || (uint)id == 0 ? await _context.AddAsync(entity) : _context.Update(entity);

            await _context.SaveChangesAsync();

            return(result?.Entity);
        }