Example #1
0
        public async Task <IActionResult> Create(Question question)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            question.User = currentUser;
            _db.Questions.Add(question);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create(Response response)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            response.User = currentUser;
            _db.Responses.Add(response);
            _db.SaveChanges();
            return(RedirectToAction("Details", "Question", new { QuestionId = response.QuestionId }));
        }
        public void UpdateVote(int aid, int uid, int value)
        {
            int updatevalue;

            if (value > 0)
            {
                updatevalue = 1;
            }
            else if (value < 0)
            {
                updatevalue = -1;
            }
            else
            {
                updatevalue = 0;
            }
            Vote vote = db.Votes.Where(temp => temp.AnswerID == aid && temp.UserID == uid).FirstOrDefault();

            if (vote != null)
            {
                vote.VoteValue = updatevalue;
            }
            else
            {
                Vote newVote = new Vote()
                {
                    AnswerID = aid, UserID = uid, VoteValue = updatevalue
                };
                db.Votes.Add(newVote);
            }
            db.SaveChanges();
        }
 public void Insert(SearchUser searchUser)
 {
     using (var db = new StackOverflowDbContext())
     {
         searchUser.Id = db.SearchUsers.Max(a => a.Id) + 1;
         db.SearchUsers.Add(searchUser);
         db.SaveChanges();
     }
 }
 public void Insert(Annotation annotation)
 {
     using (var db = new StackOverflowDbContext())
     {
         annotation.Id = db.Annotations.Max(a => a.Id) + 1;
         db.Annotations.Add(annotation);
         db.SaveChanges();
     }
 }
        public bool DeleteSearchUser(int id)
        {
            using (var db = new StackOverflowDbContext())
            {
                var searchUser = db.SearchUsers.FirstOrDefault(a => a.Id == id);
                if (searchUser == null)
                {
                    return(false);
                }

                db.SearchUsers.Remove(searchUser);
                db.SaveChanges();

                return(true);
            }
        }
        public bool Update(SearchUser searchUser)
        {
            using (var db = new StackOverflowDbContext())
            {
                var dbSearchUser = db.SearchUsers.FirstOrDefault(a => a.Id == searchUser.Id);
                if (dbSearchUser == null)
                {
                    return(false);
                }

                dbSearchUser.MacAdresse = searchUser.MacAdresse;

                db.SaveChanges();
                return(true);
            }
        }
        public bool DeleteAnnotation(int id)
        {
            using (var db = new StackOverflowDbContext())
            {
                var annotation = db.Annotations.FirstOrDefault(a => a.Id == id);
                if (annotation == null)
                {
                    return(false);
                }

                db.Annotations.Remove(annotation);
                db.SaveChanges();

                return(true);
            }
        }
        public bool Update(int id, Annotation annotation)
        {
            using (var db = new StackOverflowDbContext())
            {
                var dbAnnotation = db.Annotations.FirstOrDefault(a => a.Id == id);
                if (dbAnnotation == null)
                {
                    return(false);
                }

                dbAnnotation.Body         = annotation.Body;
                dbAnnotation.MarkingStart = annotation.MarkingStart;
                dbAnnotation.MarkingEnd   = annotation.MarkingEnd;
                dbAnnotation.PostId       = annotation.PostId;
                dbAnnotation.CommentId    = annotation.CommentId;
                dbAnnotation.SearchUserId = annotation.SearchUserId;

                db.SaveChanges();
                return(true);
            }
        }
 public void Save()
 {
     _dbContext.SaveChanges();
 }
 public void InsertAnswer(Answer a)
 {
     db.Answers.Add(a);
     db.SaveChanges();
     qr.UpdateQuestionAnswersCount(a.QuestionID, 1);
 }
Example #12
0
 public void InsertQuestion(Question q)
 {
     db.Questions.Add(q);
     db.SaveChanges();
 }
Example #13
0
 public void InsertUser(User u)
 {
     db.Users.Add(u);
     db.SaveChanges();
 }
 public void InsertCategory(Category c)
 {
     db.Categories.Add(c);
     db.SaveChanges();
 }