/// <summary> /// Upserts the single category. /// </summary> /// <param name="category">The category.</param> /// <param name="categoryToId">The category to identifier.</param> /// <returns>upserted category's id</returns> private int UpsertSingleCategory(AmazonProductCategory category, IDictionary <AmazonProductCategory, int> categoryToId) { using (var connection = GetOpenedSqlConnection2()) { int parentId = -1; if (category.Parent != null) { parentId = UpsertSingleCategory(category.Parent, categoryToId); } AmazonCategory cat = new AmazonCategory { MarketplaceTypeId = AmazonMarketplaceTypeId, ServiceCategoryId = category.CategoryId, Name = category.CategoryName, ParentId = parentId > 0 ? parentId : (int?)null }; var upsertCommand = GetUpsertGenerator(cat) .WithConnection(connection.SqlConnection()) .WithSkipColumns(o => o.Id) .WithOutputColumns(o => o.Id) .WithTableName("MP_EbayAmazonCategory") .WithMatchColumns(o => o.Name) .Verify() .GenerateCommand(); using (var sqlCommand = upsertCommand) { int id = (int)ExecuteScalarAndLog <int>(sqlCommand); categoryToId.Add(category, id); return(id); } } }
public async Task <IActionResult> Edit(int id, [Bind("AmazonCategoryID,Category")] AmazonCategory amazonCategory) { if (id != amazonCategory.AmazonCategoryID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(amazonCategory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AmazonCategoryExists(amazonCategory.AmazonCategoryID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(amazonCategory)); }
public async Task <IActionResult> Create([Bind("AmazonCategoryID,Category")] AmazonCategory amazonCategory) { if (ModelState.IsValid) { _context.Add(amazonCategory); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(amazonCategory)); }
private void UpdateDesignCategories(String amazonCategory, AmazonDesign amazonDesign) { var keywordsFromDb = _context.AmazonCategories .ToDictionary(c => c.Category, c => c.AmazonCategoryID); if (amazonCategory != null) { if (keywordsFromDb.Keys.Contains(amazonCategory)) { amazonDesign.AmazonCategoryID = keywordsFromDb[amazonCategory]; } else { AmazonCategory newKeyword = new AmazonCategory { Category = amazonCategory }; _context.AmazonCategories.Add(newKeyword); _context.SaveChanges(); amazonDesign.AmazonCategoryID = newKeyword.AmazonCategoryID; } } }