Пример #1
0
        public IActionResult SearchPage(string query, int id)
        {
            _userinfo = _userManager.FindByNameAsync(User.Identity.Name).Result;

            ViewBag.Notifications = _db.Notifications.OrderBy(x => x.Date)
                                    .Where(x => x.Seen == false && x.Question.UserId == _userinfo.Id).Count() > 0 ? "notification-color" : "";

            IQueryable <Question> searchResult = _db.Questions.Where(x =>
                                                                     x.QuestionTitle.Contains(query) || x.QuestionDescription.Contains(query)
                                                                     );

            PaginationViewModel paginationView = new PaginationViewModel
            {
                AmmountOfPages = Convert.ToDouble(Convert.ToDouble(searchResult.Count()) / 5.0) > (searchResult.Count() / 5) ? (searchResult.Count() / 5) + 1 : searchResult.Count() / 5,
                Questions      = searchResult.OrderByDescending(x => x.QuestionId).Skip(id * 5).Take(5)
            };

            if (id == 0)
            {
                paginationView.Questions = searchResult.OrderByDescending(x => x.QuestionId).Take(5);
            }

            ViewBag.Query = query;
            ViewBag.Id    = id;

            return(View(paginationView));
        }
Пример #2
0
        public IActionResult AddQuestion()
        {
            _userinfo = _userManager.FindByNameAsync(User.Identity.Name).Result;

            ViewBag.Notifications = _db.Notifications.OrderBy(x => x.Date)
                                    .Where(x => x.Seen == false && x.Question.UserId == _userinfo.Id).Count() > 0 ? "notification-color" : "";

            return(View());
        }
Пример #3
0
        public IActionResult Notifications()
        {
            _userinfo = _userManager.FindByNameAsync(User.Identity.Name).Result;

            var currentNotifications = _db.Notifications.OrderBy(x => x.Date)
                                       .Where(x => x.Seen == false && x.Question.UserId == _userinfo.Id);

            ViewBag.DbExecute = _db;

            return(View(currentNotifications));
        }
Пример #4
0
        public IActionResult Index()
        {
            _userinfo = _userManager.FindByNameAsync(User.Identity.Name).Result;

            ViewBag.Notifications = _db.Notifications.OrderBy(x => x.Date)
                                    .Where(x => x.Seen == false && x.Question.UserId == _userinfo.Id).Count() > 0 ? "notification-color" : "";

            PaginationViewModel paginationView = new PaginationViewModel
            {
                AmmountOfPages = Convert.ToDouble(_db.Questions.Count()) / Convert.ToDouble(5) > (_db.Questions.Count() / 5) ? (_db.Questions.Count() / 5) + 1 : _db.Questions.Count() / 5,
                Questions      = _db.Questions.Take(5).OrderByDescending(x => x.QuestionId)
            };

            return(View(paginationView));
        }
Пример #5
0
        public IActionResult ReportQuestion(int id)
        {
            _userinfo = _userManager.FindByNameAsync(User.Identity.Name).Result;

            ViewBag.Notifications = _db.Notifications.OrderBy(x => x.Date)
                                    .Where(x => x.Seen == false && x.Question.UserId == _userinfo.Id).Count() > 0 ? "notification-color" : "";

            _db.QuestionReports.Add(new QuestionReport {
                QuestionId = id
            });

            _db.SaveChanges();

            return(RedirectToAction("question", id));
        }
Пример #6
0
        public async Task SeedNewUser(string userName, string email, string password)
        {
            var _user = new CustomUserFields
            {
                UserName    = userName,
                Email       = email,
                FullName    = "Brian Jerez",
                Description = "Ain't got no cash Ain't got no style. Ladies vomit when I smile",
                ImageUrl    = "/img/static/avatar.png"
            };

            var result = await _userManager.CreateAsync(_user, password);

            if (result.Succeeded)
            {
                IdentityResult x = await _userManager.AddToRoleAsync(_user, "Administrador");
            }
        }
Пример #7
0
        public IActionResult Question(int id)
        {
            _userinfo = _userManager.FindByNameAsync(User.Identity.Name).Result;

            ViewBag.Notifications = _db.Notifications.OrderBy(x => x.Date)
                                    .Where(x => x.Seen == false && x.Question.UserId == _userinfo.Id).Count() > 0 ? "notification-color" : "";

            ViewBag.Id = id;
            var QuestionVM = new QuestionViewModel
            {
                GetQuestion    = _db.Questions.FirstOrDefault(x => x.QuestionId == id),
                Answers        = _db.Answers.Where(x => x.QuestionId == id).OrderByDescending(X => X.AnswerId),
                UserFieldsInfo = _userinfo
            };

            ViewBag.Contenido = Markdown.ToHtml(QuestionVM.GetQuestion.QuestionDescription).ToString();

            return(View(QuestionVM));
        }
Пример #8
0
        public async Task <IActionResult> RegistroBD(UserLoginAndRegister newUser)
        {
            CustomUserFields _newUser = new CustomUserFields
            {
                UserName = newUser.UserName,
                Email    = newUser.Email,
                ImageUrl = "/img/static/avatar.png"
            };

            IdentityResult result = await _userManager.CreateAsync(_newUser, newUser.Password);

            if (!result.Succeeded)
            {
                return(RedirectToAction("Registro", "LandingPages"));
            }

            await _userManager.AddToRoleAsync(_newUser, "Usuario");

            return(RedirectToAction("Index", "LandingPages"));
        }
Пример #9
0
        public IActionResult Page(int id)
        {
            _userinfo = _userManager.FindByNameAsync(User.Identity.Name).Result;

            ViewBag.Notifications = _db.Notifications.OrderBy(x => x.Date)
                                    .Where(x => x.Seen == false && x.Question.UserId == _userinfo.Id).Count() > 0 ? "notification-color" : "";

            if (id == 0 || id == 1)
            {
                return(RedirectToAction("Index", "AppPages"));
            }

            ViewBag.Id = id;

            PaginationViewModel paginationView = new PaginationViewModel
            {
                AmmountOfPages = _db.Questions.Count() / 5,
                Questions      = _db.Questions.OrderByDescending(x => x.QuestionId).Skip((id - 1) * 5).Take(5)
            };

            return(View(paginationView));
        }