예제 #1
0
        public Response InsertQuestion(Guid id, QuestionModel question)
        {
            var userId   = Guid.NewGuid();
            var response = new Response();

            using (var db = new KalingaHubDBModel())
            {
                try
                {
                    db.Questions.Add(new Question
                    {
                        Id          = id,
                        CreatedBy   = userId,
                        CreatedDate = DateTime.Now,
                        Title       = question.Title,
                        Description = question.Description,
                        CategoryId  = question.CategoryId
                    });
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    response.IsSuccess = false;
                    response.Message   = e.ToString();
                    return(response);
                }

                response.IsSuccess = true;
                response.Message   = "Question Successfully Posted";
                return(response);
            }
        }
예제 #2
0
        public Response AddQuestionTags(List <Guid> tagIds, Guid questionId)
        {
            Response response = new Response();

            try
            {
                using (var db = new KalingaHubDBModel())
                {
                    foreach (var tagId in tagIds)
                    {
                        QuestionTag questionTag = new QuestionTag {
                            QuestionId = questionId, TagId = tagId
                        };
                        db.QuestionTags.Add(questionTag);
                    }
                    db.SaveChanges();
                    response.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                response.IsSuccess = false;
                response.Message   = e.Message;
                return(response);
            }
            return(response);
        }
        public List <Guid> AddTags(List <string> tags)
        {
            try
            {
                var tagIds = new List <Guid>();

                using (var db = new KalingaHubDBModel())
                {
                    var qry = from t in db.Tags
                              select t.Name;
                    foreach (var obj in tags)
                    {
                        if (!qry.Contains(obj))
                        {
                            Tag tag = new Tag {
                                Id = Guid.NewGuid(), Name = obj
                            };
                            tagIds.Add(tag.Id);
                            db.Tags.Add(tag);
                        }
                    }

                    db.SaveChanges();
                    return(tagIds);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
예제 #4
0
 public void EditQuestion(QuestionModel questionModel)
 {
     using (var db = new KalingaHubDBModel())
     {
         var question = db.Questions.Single(q => q.Id == questionModel.Id && q.IsActive);
         question.ModifiedDate = DateTime.Now;
         question.Title        = questionModel.Title;
         question.Description  = questionModel.Description;
         db.SaveChanges();
     }
 }
예제 #5
0
 public void RemoveQuestionTags(List <Guid> tagIds, Guid questionId)
 {
     using (var db = new KalingaHubDBModel())
     {
         var questionTags = (from qt in db.QuestionTags
                             where tagIds.Contains(qt.TagId) && qt.QuestionId == questionId
                             select qt)?.ToList();
         db.QuestionTags.RemoveRange(questionTags);
         db.SaveChanges();
     }
 }