public Feeder_WatchKeywordsBatch CreateFeeder_WatchKeywords(Feeder_WatchKeywordsBatch watchkeywords) { string Separator = watchkeywords.KeywordsSeparator; List <string> Keywords; Keywords = watchkeywords.Keywords.Split(Separator, StringSplitOptions.RemoveEmptyEntries).ToList(); /* * if (Separator == ":") * { * //var StringWithNewLine = watchkeywords.Keywords.Replace("\\n", "\\\\n"); * //Keywords = watchkeywords.Keywords.Split(new[] { '\r', '\n', '\t', ' '}, StringSplitOptions.RemoveEmptyEntries).ToList(); * * Keywords = watchkeywords.Keywords.Split(new[] { Environment.NewLine, Environment. }, StringSplitOptions.RemoveEmptyEntries).ToList(); * * * } * else * { * Keywords = watchkeywords.Keywords.Split(Separator).ToList(); * } */ watchkeywords.Keywords = ""; foreach (var Keyword in Keywords) { if (_context.Feeder_WatchKeywords.FirstOrDefault(x => x.Keyword == Keyword) != null) // keyword exists { continue; } if (Keyword.Trim() == "") { continue; } var NewWatchKeyword = new Feeder_WatchKeywords(); var RecordID = _context.Feeder_WatchKeywords.Max(id => id.pkKeywordID); NewWatchKeyword.pkKeywordID = RecordID + 1; NewWatchKeyword.Keyword = Keyword.Trim(); NewWatchKeyword.fkWatchID = watchkeywords.fkWatchID; NewWatchKeyword.DateAdded = DateTime.UtcNow; _context.Feeder_WatchKeywords.Add(NewWatchKeyword); watchkeywords.Keywords += Keyword + Separator; _context.SaveChanges(); } return(watchkeywords); }
public IActionResult CreateFromString([FromBody] Feeder_WatchKeywordsBatch watchkeywords) { var result = _repository.CreateFeeder_WatchKeywords(watchkeywords); return(Helper.CheckResult(result)); }