Пример #1
0
        public SearchHistory CreateSearchHistory(string text, string username, DateTime date)
        {
            using var db = new StackoverflowContext();

            int nextId;

            try
            {
                nextId = db.SearchHistories.Max(x => x.Id) + 1;
            }
            catch (Exception e)
            {
                nextId = 1;
            }

            var searchHistory = new SearchHistory()
            {
                Id       = nextId,
                Text     = text,
                Date     = date,
                UserName = username,
            };

            db.SearchHistories.Add(searchHistory);

            db.SaveChanges();

            return(searchHistory);
        }
Пример #2
0
        public SearchHistory CreateSearchHistory(SearchHistory history)
        {
            using var db = new SovaDbContext();
            db.SearchHistories.Add(history);
            int changes = db.SaveChanges();

            if (changes > 0)
            {
                return(history);
            }
            else
            {
                return(null);
            }
        }