コード例 #1
0
 public List <Note> GetAllNotesForQuestion(string userEmail, int questionId, PagingAttributes pagingAttributes)
 {
     using var db = new SovaDbContext();
     return(db.Notes.Where(n => n.QuestionId == questionId && n.UserEmail == userEmail)
            .Skip(pagingAttributes.Page * pagingAttributes.PageSize)
            .Take(pagingAttributes.PageSize)
            .ToList());
 }
コード例 #2
0
 public List <Note> GetNotesByUserEmail(string userEmail, PagingAttributes pagingAttributes)
 {
     using var db = new SovaDbContext();
     return(db.Notes.Where(n => n.UserEmail == userEmail)
            .OrderBy(n => n.QuestionId)
            .Skip(pagingAttributes.Page * pagingAttributes.PageSize)
            .Take(pagingAttributes.PageSize)
            .ToList());
 }
コード例 #3
0
 public bool UpdateNote(Note note)
 {
     using var db = new SovaDbContext();
     if (NoteExcist(note.Id))
     {
         db.Notes.Update(note);
         return(db.SaveChanges() > 0);
     }
     return(false);
 }
コード例 #4
0
 public bool UpdateUser(AppUser user)
 {
     using var db = new SovaDbContext();
     if (UserExcist(user.Email))
     {
         db.AppUsers.Update(user);
         return(db.SaveChanges() > 0);
     }
     return(false);
 }
コード例 #5
0
        public bool DeleteNoteById(int noteId)
        {
            using var db = new SovaDbContext();
            var note = db.Notes.Find(noteId);

            if (note == null)
            {
                return(false);
            }
            db.Notes.Remove(note);
            return(db.SaveChanges() > 0);
        }
コード例 #6
0
        public bool DeleteUserByEmail(string useremail)
        {
            using var db = new SovaDbContext();
            var email = db.AppUsers.Find(useremail);

            if (email == null)
            {
                return(false);
            }
            db.AppUsers.Remove(email);
            return(db.SaveChanges() > 0);
        }
コード例 #7
0
        public bool DeleteSearchHistoryById(int historyId)
        {
            using var db = new SovaDbContext();
            var history = db.SearchHistories.Find(historyId);

            if (history == null)
            {
                return(false);
            }
            db.SearchHistories.Remove(history);
            return(db.SaveChanges() > 0);
        }
コード例 #8
0
        public Note CreateNote(Note note)
        {
            using var db = new SovaDbContext();
            db.Notes.Add(note);
            int changes = db.SaveChanges();

            if (changes > 0)
            {
                return(note);
            }
            else
            {
                return(null);
            }
        }
コード例 #9
0
        public bool DeleteSearchHistoryByUserEmail(string userEmail)
        {
            using var db = new SovaDbContext();
            var history = db.SearchHistories.Where(u => u.Email == userEmail);

            if (history == null)
            {
                return(false);
            }
            foreach (var item in history)
            {
                db.SearchHistories.Remove(item);
            }
            return(db.SaveChanges() > 0);
        }
コード例 #10
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);
            }
        }
コード例 #11
0
 public List <SearchResult> SearchByScore(string fromScore, string toScore)
 {
     using var db = new SovaDbContext();
     return(db.SearchResults.FromSqlRaw("select * from search_by_score(" + fromScore + "," + toScore + ")").Select(x => new SearchResult
     {
         QuestionId = x.QuestionId,
         AnswerId = x.AnswerId,
         Type = x.Type,
         Body = x.Body,
         Title = x.Title,
         Score = x.Score,
         Tags = x.Tags,
         CreationDate = x.CreationDate
     }).ToList());
 }
コード例 #12
0
        public List <SearchResult> SearchByTag(params string[] tags)
        {
            using var db = new SovaDbContext();
            var s = BuildStringFromParams(tags);

            return(db.SearchResults.FromSqlRaw("select * from search_by_tags(" + s + ")").Select(x => new SearchResult
            {
                QuestionId = x.QuestionId,
                AnswerId = x.AnswerId,
                Type = x.Type,
                Body = x.Body,
                Title = x.Title,
                Score = x.Score,
                Tags = x.Tags,
                CreationDate = x.CreationDate
            }).ToList());
        }
コード例 #13
0
        public List <SearchResult> SearchByAcceptedAnswer(bool accepted, params string[] keywords)
        {
            using var db = new  SovaDbContext();
            var s   = BuildStringFromParams(keywords);
            var acc = accepted ? "'yes'" : "'no'";

            return(db.SearchResults.FromSqlRaw("select * from search_by_acceptedanswer(" + acc + "," + s + ")").Select(x => new SearchResult
            {
                QuestionId = x.QuestionId,
                AnswerId = x.AnswerId,
                Type = x.Type,
                Body = x.Body,
                Title = x.Title,
                Score = x.Score,
                Tags = x.Tags,
                CreationDate = x.CreationDate
            }).ToList());
        }
コード例 #14
0
        public AppUser CreateUser(string name, string email, string password, string salt)
        {
            using var db = new SovaDbContext();
            var user = new AppUser()
            {
                Name     = name,
                Email    = email,
                Password = password,
                Salt     = salt
            };

            db.AppUsers.Add(user);
            int changes = db.SaveChanges();

            if (changes > 0)
            {
                return(user);
            }
            else
            {
                return(null);
            }
        }
コード例 #15
0
 public int NumberOfNotesPerQuestion(int questionId)
 {
     using var db = new SovaDbContext();
     return(db.Notes.Where(n => n.QuestionId == questionId).Count());
 }
コード例 #16
0
 public int NumberOfNotesPerUser(string userEmail)
 {
     using var db = new SovaDbContext();
     return(db.Notes.Where(n => n.UserEmail == userEmail).Count());
 }
コード例 #17
0
 public Note GetNoteById(int noteId)
 {
     using var db = new SovaDbContext();
     return(db.Notes.Find(noteId));
 }
コード例 #18
0
 public List <SearchHistory> GetSearchHistoryByUserEmail(string userEmail)
 {
     using var db = new SovaDbContext();
     return(db.SearchHistories.Where(n => n.Email == userEmail).ToList());
 }
コード例 #19
0
 public AppUser GetUserByEmail(string email)
 {
     using var db = new SovaDbContext();
     return(db.AppUsers.Find(email));
 }