//add a like public int Add(string headWord) { try { Guid userId = (Guid)Membership.GetUser().ProviderUserKey; //check have liked if (context.Favorites.Find(headWord, userId) != null) { return(LikeModel.EXISTED); } else { Favorite favorite = new Favorite(); favorite.HeadWord = headWord; favorite.UserId = userId; favorite.DateAdd = DateTime.Now; context.Favorites.Add(favorite); context.SaveChanges(); return(LikeModel.SUCCESS); } } catch { return(LikeModel.FAIL); } }
//add searching history public int AddSearchHistory(string keyword, bool isExist) { try { SearchHistory searchHistory = context.SearchHistories.Find(keyword); if (searchHistory == null) { searchHistory = new SearchHistory(); searchHistory.Keyword = keyword; searchHistory.IsExist = isExist; searchHistory.Counter = 1; searchHistory.DateModify = DateTime.Now; //add new context.SearchHistories.Add(searchHistory); } else { searchHistory.IsExist = isExist; searchHistory.Counter++; searchHistory.DateModify = DateTime.Now; //increment count context.Entry(searchHistory).State = EntityState.Modified; } //change context return(context.SaveChanges()); } catch { return(0); } }
// Add new question public int NewQuestion(Question question) { context.Questions.Add(question); return(context.SaveChanges()); }