Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
0
        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);
            }
        }