private string InsertTag(string newTag, string currentTag) { currentTag = currentTag?.Trim() ?? ""; bool newTagAdded = false; int nextID = -1; bool nextIDUsed = true; if (!string.IsNullOrEmpty(newTag?.Trim()) && newTag.Trim() != "|") { string[] nt = newTag.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in nt) { if (!string.IsNullOrEmpty(text?.Trim())) { TagEntity tag = CacheHelper.GetTagList().FirstOrDefault(te => te.RowKey.Trim().ToLower() == text.Trim().ToLower()); if (tag == null) { if (nextIDUsed) { nextID = int.Parse(SequenceHelper.GetNextSequence("ID", Constants.TABLE_TAG, null)); } tag = new POCO.TagEntity("Tag", text.Trim()) { ID = nextID }; try { TableStorageHelper.InsertAsync(Constants.TABLE_TAG, tag).Wait(); nextIDUsed = true; newTagAdded = true; } catch (Exception ex) { nextIDUsed = false; CacheHelper.ClearTagListCache(); tag = CacheHelper.GetTagList().FirstOrDefault(te => te.RowKey.Trim().ToLower() == text.Trim().ToLower()); } } if (tag != null) { currentTag = currentTag + (currentTag.Trim().Length == 0 ? "|" : "") + tag.ID + "|"; } } } if (newTagAdded) { CacheHelper.ClearTagListCache(); } } return(currentTag); }
public IActionResult Add(UserEntity user) { int errorCode = 0; try { TableStorageHelper.InsertAsync(Constants.TABLE_USER, user).Wait(); CacheHelper.ClearUsersCache(); } catch (Exception ex) { if (!TableStorageHelper.IsStorageException(ex, out errorCode)) { errorCode = Constants.ERROR_CODE_COMMON; } } return(RedirectToAction("Index", new { errorCode = errorCode })); }