public IActionResult Add(CategoryEntity entity) { int errorCode = 0; try { if (CacheHelper.GetCategoryList(entity.PartitionKey).Count(cat => cat.NameHash.Equals(entity.NameHash)) > 0) { errorCode = Constants.ERROR_CODE_ENTITY_ALREADY_EXISTS; } else { string nextSortNumber = SequenceHelper.GetNextSequence(Constants.SORT, Constants.TABLE_CATEGORY + "_" + entity.PartitionKey, Constants.PADDING_SORT); string nextID = SequenceHelper.GetNextSequence(Constants.ID, Constants.TABLE_CATEGORY, Constants.PADDING_CATEGORYID); entity.RowKey = nextSortNumber + "_" + nextID; TableStorageHelper.InsertOrMergeAsync(Constants.TABLE_CATEGORY, entity).Wait(); CacheHelper.ClearCategoryListCache(); } } catch (Exception ex) { if (!TableStorageHelper.IsStorageException(ex, out errorCode)) { errorCode = Constants.ERROR_CODE_COMMON; } } return(RedirectToAction("Index", new { category = entity.PartitionKey, errorCode = errorCode })); }