コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("IsArchived,Id,Title,Description,IdUser,Date")] Question question)
        {
            if (id != question.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(question);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!QuestionExists(question.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(question));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("QuestionID,Id,Description,Date")] Answer answer)
        {
            SetActiveUser();
            if (id != answer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(answer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AnswerExists(answer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["QuestionID"] = new SelectList(_context.Question, "Id", "Description", answer.QuestionID);
            return(View(answer));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,UserID,QuestionID")] View view)
        {
            if (id != view.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(view);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ViewExists(view.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["QuestionID"] = new SelectList(_context.Question, "Id", "Description", view.QuestionID);
            ViewData["UserID"]     = new SelectList(_context.User, "ID", "ID", view.UserID);
            return(View(view));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,UserID,AnswerID")] PositiveVote positiveVote)
        {
            if (id != positiveVote.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(positiveVote);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PositiveVoteExists(positiveVote.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["AnswerID"] = new SelectList(_context.Answer, "Id", "Description", positiveVote.AnswerID);
            ViewData["UserID"]   = new SelectList(_context.User, "ID", "ID", positiveVote.UserID);


            return(View(positiveVote));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("AnswerId,Id,Description,Date")] Comment comment)
        {
            if (id != comment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(comment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommentExists(comment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AnswerId"] = new SelectList(_context.Answer, "Id", "Description", comment.AnswerId);
            return(View(comment));
        }
コード例 #6
0
 public async Task <IActionResult> Edit([Bind("ID,GOOGLE_KEY,LEVEL,USERNAME,PASSWORD,EMAIL,PHOTO,QUESTIONS_ANSWERED,POSITIVE_VOTES_RECEIVED,QUESTIONS_ASKED,INTERESTING_VOTES_RECEIVED,DESCRIPTION,INTERESTS_OR_KNOWLEDGE,COUNTRY,CITY,StudioId")] User user)
 {
     if (string.IsNullOrEmpty(HttpContext.Session.GetString(ACTIVE_USERNAME)))
     {
         return(RedirectToAction("Index", "Users", new { message = "Error, Inicie sesión" }));
     }
     if (ModelState.IsValid && CheckUsername(user.USERNAME))
     {
         try
         {
             _context.Update(user);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!UserExists(user.ID))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         //return RedirectToAction("Index", "Users", new { message = user.PASSWORD });
         return(RedirectToAction(nameof(Profile)));
     }
     return(View(user));
 }
コード例 #7
0
 public async Task <IActionResult> Edit([Bind("ID,GOOGLE_KEY,LEVEL,USERNAME,PASSWORD,EMAIL,PHOTO,QUESTIONS_ANSWERED,POSITIVE_VOTES_RECEIVED,QUESTIONS_ASKED,INTERESTING_VOTES_RECEIVED,DESCRIPTION,INTERESTS_OR_KNOWLEDGE,COUNTRY,CITY,StudioId")] User user)
 {
     setActiveUser();
     if (ModelState.IsValid && _context.User.Count(p => p.USERNAME.Equals(user.USERNAME)) == 1)
     {
         try
         {
             _context.Update(user);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!UserExists(user.ID))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         //return RedirectToAction("Index", "Users", new { message = user.PASSWORD });
         return(RedirectToAction(nameof(Profile)));
     }
     return(View(user));
 }
コード例 #8
0
        // GET: Questions/Details/5
        public async Task <IActionResult> AsignRole(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var user = await _context.User.FirstOrDefaultAsync(m => m.ID == id);

            if (user == null)
            {
                return(NotFound());
            }

            user.LEVEL = 2;
            _context.Update(user);
            await _context.SaveChangesAsync();

            return(View(user));
        }
コード例 #9
0
        // GET: Questions/Details/5
        public async Task <IActionResult> AsignRole(int?id)
        {
            if (string.IsNullOrEmpty(SetActiveUser()))
            {
                return(RedirectToAction("Index", "Users", new { message = "Inicie sesión" }));
            }
            if (id == null)
            {
                return(NotFound());
            }

            var user = await _context.User.FirstOrDefaultAsync(m => m.ID == id);

            if (user == null)
            {
                return(NotFound());
            }

            user.LEVEL = 2;
            _context.Update(user);
            await _context.SaveChangesAsync();

            return(View(user));
        }
コード例 #10
0
        // GET: Questions/Details/5
        public async Task <IActionResult> Details(int?id, int NotificationID = -1)
        {
            SetActiveUser();
            if (NotificationID != -1)
            {
                Notification notif = _context.Notification.FirstOrDefault(a => a.Id == NotificationID);
                notif.Read = true;
                _context.Update(notif);
                _context.SaveChanges();
            }
            if (id == null)
            {
                return(NotFound());
            }
            //Example of how to get the actual user that logged into the application
            User actualUser = null;

            if (!string.IsNullOrEmpty(HttpContext.Session.GetString(UsersController.ACTIVE_USERNAME)))
            {
                actualUser = model.GetUser(HttpContext.Session.GetString(UsersController.ACTIVE_USERNAME));


                ViewData["actualUserID"] = actualUser.ID;//Si aqui es null, lanza un error al inetntar ver la descripción de una pregunta,se debe controlar este error
                ViewBag.User             = actualUser;
            }
            else
            {
                return(RedirectToAction(nameof(Index), "Users", new { message = "Inice sesión" }));
            }


            if (actualUser != null)
            {
                ViewData["Admin"] = actualUser.LEVEL;
            }
            else
            {
                ViewData["Admin"] = 4;
            }


            var question = await _context.Question
                           .Include(q => q.Answers)
                           .ThenInclude(x => x.PositiveVotes)
                           .Include(q => q.InterestingVotes)
                           .Include(q => q.Views)
                           .Include(q => q.QuestionLabels)
                           .ThenInclude(ql => ql.Label)
                           .Include(q => q.QuestionStudios)
                           .ThenInclude(qs => qs.Studio)
                           .Include(q => q.User)
                           .FirstOrDefaultAsync(m => m.Id == id);


            if (question == null)
            {
                return(NotFound());
            }

            if (question.Views.All(x => x.UserID != actualUser.ID))
            {
                var view = new View {
                    UserID = actualUser.ID, QuestionID = question.Id
                };
                _context.View.Add(view);
                _context.SaveChanges();
            }

            //Empieza busqueda de preguntas relacionadas
            initSearcher();

            var relatedQuestions           = new List <Question>();
            List <ISearchable> searchables = _searcher.Search(question.Title);

            foreach (ISearchable s in searchables)
            {
                Question q = (Question)s;
                if (q.Id != question.Id)
                {
                    relatedQuestions.Add(q);
                }
                if (relatedQuestions.Count == MAX_RELATED_QUESTIONS)
                {
                    break;
                }
            }

            ViewBag.Related = relatedQuestions;
            //Termina busqueda de preguntas relacionadas


            var filePath = Path.Combine(_hostingEnvironment.WebRootPath, "uploads", question.Id + "");

            List <string> files = new List <string>();

            if (Directory.Exists(filePath))
            {
                string[] rawFiles = Directory.GetFiles(filePath);
                foreach (string rf in rawFiles)
                {
                    files.Add(Path.GetFileName(rf));
                }
            }

            ViewBag.FileNames = files;


            return(View(question));
        }