public async Task <Guid> Create(Models.Archetype arch)
        {
            try
            {
                var context = CreateContext();
                var created = new Data.Archetype
                {
                    Id           = arch.Id,
                    NomArchetype = arch.NomArchetype,
                    Description  = arch.Description,
                    UniversId    = arch.UniversId,
                };
                var enr = await context
                          ._Archetype
                          .AddAsync(created);

                await context.SaveChangesAsync();

                return(enr.Entity.Id);
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
                return(arch.Id);
            }
        }
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var defaultValue = new Models.Archetype();

            if (source == null)
                return defaultValue;

            var sourceString = source.ToString();

            if (sourceString.DetectIsJson())
            {
                try
                {
                    // Deserialize value to archetype model
                    var archetype = JsonConvert.DeserializeObject<Models.Archetype>(sourceString, _jsonSettings);

                    try
                    {
                        // Get list of configured properties and their types
                        // and map them to the deserialized archetype model
                        var dataTypeCache = new Dictionary<Guid, IDataTypeDefinition>();
                        var preValue = GetArchetypePreValueFromDataTypeId(propertyType.DataTypeId, dataTypeCache);
                        foreach (var fieldset in preValue.Fieldsets)
                        {
                            var fieldsetAlias = fieldset.Alias;
                            foreach (var fieldsetInst in archetype.Fieldsets.Where(x => x.Alias == fieldsetAlias))
                            {
                                foreach (var property in fieldset.Properties)
                                {
                                    var propertyAlias = property.Alias;
                                    foreach (var propertyInst in fieldsetInst.Properties.Where(x => x.Alias == propertyAlias))
                                    {
                                        propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id;
                                        propertyInst.PropertyEditorAlias = property.PropertyEditorAlias;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }

                    return archetype;
                }
                catch (Exception ex)
                {
                    return defaultValue;
                }
            }

            return defaultValue;
        }
        public async Task <IActionResult> Post([FromBody] Models.Archetype a)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            context.Archetypes.Add(a);
            await context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = a.ID }, a));
        }
        public async Task Delete(Models.Archetype arch)
        {
            try
            {
                var context  = CreateContext();
                var toDelete = await context._Archetype.FindAsync(arch.Id);

                if (toDelete != null)
                {
                    context._Archetype.Remove(toDelete);
                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public async Task Update(Models.Archetype arch)
        {
            try
            {
                var context  = CreateContext();
                var toUpdate = await context._Archetype.FindAsync(arch.Id);

                if (toUpdate != null)
                {
                    toUpdate.Id           = arch.Id;
                    toUpdate.NomArchetype = arch.NomArchetype;
                    toUpdate.Description  = arch.Description;
                    toUpdate.UniversId    = arch.UniversId;

                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }