private async Task SetCategory(Image img, ImageFormVM imgForm) { if (string.IsNullOrWhiteSpace(imgForm.Category)) { img.Category = null; } else { var category = PendingCategories.Find(c => c.Name.ToLower() == imgForm.Category.ToLower()); if (category != null) { img.Category = category; return; } category = await _db.Categories.FirstOrDefaultAsync(c => c.Name.ToLower() == imgForm.Category.ToLower()); if (category == null) { category = new Category { Name = imgForm.Category }; PendingCategories.Add(category); _db.Categories.Add(category); } img.Category = category; } }
protected override bool ProcessRow(Row row) { var slug = GetCell(row, "A").Trim(); slug = Hotcakes.Web.Text.Slugify(slug, true); if (!PendingCategories.Any(c => c.Slug == slug)) { var ci = new CategoryInfo(); ci.Slug = slug; ci.ParentSlug = Hotcakes.Web.Text.Slugify(GetCell(row, "B"), true); ci.CategoryName = GetCell(row, "C"); PendingCategories.Add(ci); } return(true); }