Ejemplo n.º 1
0
        private static async Task <bool> ImportCategoryAsync
        (
            PluginsDatabaseContext db,
            IdeaPluginCategory category
        )
        {
            var dbCategory = await db.Categories.FirstOrDefaultAsync(c => c.Name == category.Name);

            if (dbCategory is null)
            {
                dbCategory = category.ToEntity();
                db.Categories.Add(dbCategory);
            }
            else
            {
                var newValues = category.ToEntity();
                newValues.ID = dbCategory.ID;

                var existingEntry = db.Entry(dbCategory);
                existingEntry.CurrentValues.SetValues(newValues);

                if (existingEntry.State == EntityState.Unchanged)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Maps the given <see cref="IdeaPluginCategory"/> to a <see cref="Models.PluginCategory"/>.
 /// </summary>
 /// <param name="this">The category.</param>
 /// <returns>The mapped category.</returns>
 public static Models.PluginCategory ToEntity(this IdeaPluginCategory @this)
 {
     return(new Models.PluginCategory(@this.Name));
 }