Beispiel #1
0
        public async Task <IActionResult> Result(int id, int?search)
        {
            Result        result  = null;
            var           vote    = false;
            List <Result> results = new List <Result>();

            if (search != null)
            {
                var sch = search ?? default;
                result = _resultRepository.GetAllResults().Where(p => p.PhotoId == id && p.SearchId == sch).FirstOrDefault();
                if (result == null)
                {
                    var phrase = _searchRepository.GetSearch(sch).Phrase;
                    sch    = _searchRepository.GetAllSearches().Where(p => p.Phrase == phrase).FirstOrDefault().ID;
                    result = _resultRepository.GetAllResults().Where(p => p.PhotoId == id && p.SearchId == sch).FirstOrDefault();
                }
                var hist   = _historyRepository.GetHistory(sch);
                var scores = _scoreRepository.GetAllScores().Where(p => p.UserId == hist.UserId && p.ResultId == result.ID);
                if (scores.Any())
                {
                    vote = true;
                }
            }
            else
            {
                result = _resultRepository.GetAllResults().Where(p => p.PhotoId == id).FirstOrDefault();
            }
            Photo                  photo         = _photoRepository.GetPhoto(id);
            List <Comment>         coms          = _commentRepository.GetAllComments(id).ToList();
            List <CommentWithName> comsWithNames = new List <CommentWithName>();

            foreach (var comm in coms)
            {
                var user = await userManager.FindByIdAsync(comm.UserId);

                comsWithNames.Add(new CommentWithName(comm, user.UserName));
            }


            PhotoCommentsViewModel photoCommentViewMode = new PhotoCommentsViewModel
            {
                ID          = photo.ID,
                Url         = photo.Url,
                ResX        = photo.ResX,
                ResY        = photo.ResY,
                PhotoFormat = photo.PhotoFormat,
                Date        = photo.Date,
                Comments    = comsWithNames,
                Voted       = vote
            };
            var tuple = new Tuple <PhotoCommentsViewModel, Result>(photoCommentViewMode, result);

            return(View(tuple));
        }
Beispiel #2
0
        public async Task <IActionResult> Result(PhotoCommentsViewModel model, string content)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.FindByNameAsync((User.Identity.Name));

                Comment comment = new Comment
                {
                    Content = content,
                    Date    = DateTime.Now,
                    UserId  = user.Id,
                    PhotoId = model.ID
                };

                _commentRepository.Add(comment);
            }
            return(RedirectToAction("Result", new { id = model.ID }));
        }