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); }
public Boolean UpdateUser(string username, string password, string email, string salt) { using var db = new StackoverflowContext(); var user = db.Users.Find(username); if (user != null) { if (password != null) { user.Password = password; } if (email != null) { user.Email = email; } if (salt != null) { user.Salt = salt; } db.SaveChanges(); return(true); } else { return(false); } }
public Marking CreateMarking(string annotation, string username, int?postid, int?commentid, DateTime date) { using var db = new StackoverflowContext(); int nextId; try { nextId = db.Markings.Max(x => x.Id) + 1; } catch (Exception e) { nextId = 1; } var marking = new Marking() { Id = nextId, Annotation = annotation, Date = date, Username = username, PostId = postid, CommentId = commentid }; db.Markings.Add(marking); db.SaveChanges(); return(marking); }
public Boolean DeleteUser(string username) { using var db = new StackoverflowContext(); var user = db.Users.Find(username); if (user != null) { db.Users.Remove(user); db.SaveChanges(); return(true); } else { return(false); } }
public User CreateUser(string username, string password, string email, string salt, DateTime date) { using var db = new StackoverflowContext(); var user = new User() { UserName = username, Password = password, Email = email, Salt = salt, CreationDate = date }; db.Users.Add(user); db.SaveChanges(); return(user); }
public Boolean DeleteSearchHistory(int searchhistoryid) { using var db = new StackoverflowContext(); var searchhistory = db.SearchHistories.Find(searchhistoryid); if (searchhistory != null) { db.SearchHistories.Remove(searchhistory); db.SaveChanges(); return(true); } else { return(false); } }
public Boolean DeleteMarking(int markid) { using var db = new StackoverflowContext(); var marking = db.Markings.Find(markid); if (marking != null) { db.Markings.Remove(marking); db.SaveChanges(); return(true); } else { return(false); } }
public Boolean UpdateMarking(int markid, string annotation) { using var db = new StackoverflowContext(); var marking = db.Markings.Find(markid); if (marking != null) { if (annotation != null) { marking.Annotation = annotation; } db.SaveChanges(); return(true); } else { return(false); } }