Пример #1
0
        public ActionResult Index(Guid questionId, string userId)
        {
            List<AnswereViewModel> AnswereViewModelList = new List<AnswereViewModel>();
            IEnumerable<AnswereViewModel> en;
            var answers = _dbContext.Answers.Where(a => a.QuestionId == questionId).ToList();

            Question question = _dbContext.Questions.Find(questionId);
            ApplicationUser user = _dbContext.Users.Find(userId);
            var tagList = _dbContext.Tags.ToList();
            // IEnumerable<AnswereViewModel> answereViewModel = Mapper.Map<IEnumerable<AnswereViewModel>>(answers);
            foreach (var answer in answers)
            {
                var tags = answer.Tags;
                AnswereViewModel answereViewModel = new AnswereViewModel();
                answereViewModel.Id = answer.Id;
                answereViewModel.CreatedDate = answer.CreatedDate;
                answereViewModel.Title = answer.Title;
                answereViewModel.Content = answer.Content;
                answereViewModel.UserQuestion = question.UserQuestion;
                answereViewModel.UserName = answer.User.Email;
                answereViewModel.QuestionId = questionId;
                answereViewModel.UserId = userId;
                answereViewModel.TagsList = tags;
                AnswereViewModelList.Add(answereViewModel);
            }

            en = AnswereViewModelList;
            return View(en);
        }
Пример #2
0
        public ActionResult Create(AnswereViewModel viewModel, params string[] rolesSelectedOnView)
        {
            if (ModelState.IsValid)
            {
                //  string html2 = Regex.Matches(viewModel.Content, @"(<img\/?[^>]+>)", @"", RegexOptions.IgnoreCase);
                //HtmlDocument doc = new HtmlDocument();
                //doc.LoadHtml(viewModel.Content);
                //HtmlNodeCollection linkNodes = doc.DocumentNode.SelectNodes("//img/@src");                               
                //if (linkNodes != null)
                //{
                //    foreach (HtmlNode linkNode in linkNodes)
                //    {
                //        HtmlAttribute attrib = linkNode.Attributes["src"];

                //        Base64Decode(attrib.Value);
                //    }
                //}

                //  SaveByteArrayAsImage(path, viewModel.Content);

                Answere answere = new Answere();
                answere.Id = Guid.NewGuid();
                answere.Title = viewModel.Title;
                answere.Slug = viewModel.Slug;
                answere.Content = viewModel.Content;
                answere.QuestionId = viewModel.QuestionId;
                answere.UserId = viewModel.UserId;
                _dbContext.Answers.Add(answere);

                var tags = _dbContext.Tags;
                // CreateNSaveTag(data);
                if(rolesSelectedOnView != null)
                {
                    foreach (var tag in rolesSelectedOnView)
                    {
                        Tag retriveTag = tags.Where(t => t.Name == tag).FirstOrDefault();
                        answere.Tags.Add(retriveTag);
                    }
                }
                //var deserialiseList = JsonConvert.DeserializeObject<List<Tag>>(data);             

                _dbContext.SaveChanges();
                return RedirectToAction("Index", "Questions");
            }

            return View();
        }
Пример #3
0
        public ActionResult Create(Guid questionId, string userId)
        {
            Question question = _dbContext.Questions.Find(questionId);
            ApplicationUser user = _dbContext.Users.Find(userId);
            AnswereViewModel answereViewModel = new AnswereViewModel();
            answereViewModel.UserQuestion = question.UserQuestion;
            answereViewModel.UserName = user.Email;
            answereViewModel.QuestionId = questionId;
            answereViewModel.UserId = userId;

            answereViewModel.Tags = _dbContext.Tags.Select(tag => new TagsCheckBox
            {
                Id = tag.Id,
                Name = tag.Name,
                IsChecked = false
            }).ToList();

            return View(answereViewModel);
        }
Пример #4
0
        public ActionResult ReadAnswere(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Answere answere = _dbContext.Answers.Find(id);
            var tagList = _dbContext.Tags.ToList();
            if (answere == null)
            {
                return HttpNotFound();
            }

            AnswereViewModel answereViewModel = new AnswereViewModel();
            answereViewModel.Id = answere.Id;
            answereViewModel.UserId = answere.UserId;
            answereViewModel.UserName = answere.User.UserName;
            answereViewModel.Title = answere.Title;
            answereViewModel.Content = answere.Content;
            answereViewModel.Slug = answere.Slug;
            answereViewModel.QuestionId = answere.QuestionId;
            answereViewModel.Tags = tagList.Select(tag => new TagsCheckBox
            {
                Id = tag.Id,
                Name = tag.Name,
                IsChecked = answere.Tags.Contains(tag)
            }).ToList();


            return View(answereViewModel);
        }