Exemplo n.º 1
0
        public bool Restore(int id)
        {
            Question question = this.Database.Questions.Find(id);
            SubCategoryInfoServiceModel subCategoryInfo = this.GetSubCategoryInfo(question.SubCategoryId);

            if (question == null ||
                !question.IsDeleted ||
                subCategoryInfo == null ||
                subCategoryInfo.IsDeleted)
            {
                return(false);
            }

            question.IsDeleted = false;

            foreach (var answer in question.Answers)
            {
                foreach (var comment in answer.Comments)
                {
                    comment.IsDeleted = false;
                }

                answer.IsDeleted = false;
            }

            this.Database.Save();

            return(true);
        }
Exemplo n.º 2
0
        public bool Edit(int id, string title, string content, string tags, int subCategoryId)
        {
            Question question = this.Database.Questions.Find(id);

            if (question == null ||
                question.IsDeleted ||
                question.IsLocked ||
                question.SubCategory.IsDeleted ||
                (question.Title != title &&
                 this.TitleExists(title)))
            {
                return(false);
            }

            List <string> tagTokens = this.GetTags(tags);

            if (!tagTokens.Any())
            {
                return(false);
            }

            SubCategoryInfoServiceModel subCategoryInfo = this.GetSubCategoryInfo(subCategoryId);

            if (subCategoryInfo == null ||
                subCategoryInfo.IsDeleted)
            {
                return(false);
            }

            question.Title         = title;
            question.Content       = content;
            question.SubCategoryId = subCategoryId;
            question.Tags.Clear();

            AddTagsToQuestion(tagTokens, question);

            this.Database.Save();

            return(true);
        }
Exemplo n.º 3
0
        public int Create(int authorId, string title, string content, string tags, int subCategoryId)
        {
            if (this.TitleExists(title))
            {
                return(-1);
            }

            List <string> tagTokens = this.GetTags(tags);

            if (!tagTokens.Any())
            {
                return(-1);
            }

            SubCategoryInfoServiceModel subCategoryInfo = this.GetSubCategoryInfo(subCategoryId);

            if (subCategoryInfo == null ||
                subCategoryInfo.IsDeleted)
            {
                return(-1);
            }

            Question question = new Question
            {
                Title         = title,
                Content       = content,
                DateAdded     = DateTime.UtcNow,
                AuthorId      = authorId,
                SubCategoryId = subCategoryId
            };

            AddTagsToQuestion(tagTokens, question);

            this.Database.Questions.Add(question);
            this.Database.Save();

            return(question.Id);
        }