public IActionResult UpdateFourWord(FourWord fourWord)
 {
     if (ModelState.IsValid)
     {
         int request;
         fourWord.ModifiedDate = DateTime.Now;
         _unitOfWorkFour.RepositoryFour.Update(fourWord);
         request = HttpContext.Response.StatusCode;
         if (request == 200)
         {
             TempData["Message"] = "Kelime güncelleme işleminiz başarılı!";
             TempData["JS"]      = "showSuccess();";
             _unitOfWorkFour.Complete();
         }
         else
         {
             TempData["Message"] = "Kelime güncelleme işleminiz başarısız!";
             TempData["JS"]      = "showError();";
         }
         return(RedirectToAction("FourWordIndex"));
     }
     else
     {
         TempData["Message"] = "Güncellemek istediğiniz veri hatalı!";
         TempData["JS"]      = "showError();";
         return(RedirectToAction("FourWordIndex"));
     }
 }
Exemple #2
0
        public IActionResult KontrolEt(string answerUser, FourWord fourWord
                                       , FifthWord fifthWord, SixthWord sixthWord,
                                       SevenWord sevenWord, EightWord eightWord,
                                       NineWord nineWord, TenWord tenWord, ScoreTable scoreTable, int questionCount, string lastScore)
        {
            var gamevariant = _unitOfWorkGameVariant.RepositoryGameVariant.GetAll();

            foreach (var gameVariant in gamevariant)
            {
                if (gameVariant.GameIsCompleted == false)
                {
                    if (gameVariant.GameIsOver == false)
                    {
                        if (fourWord.FourWordAnswer == answerUser)
                        {
                            gameVariant.GameScoreCount    = gameVariant.GameScoreCount + fourWord.FourWordScore;
                            gameVariant.GameQuestionCount = gameVariant.GameQuestionCount + 1;
                            gameVariant.GameIsCompleted   = false;
                            gameVariant.GameIsOver        = false;
                            gameVariant.GameVariantID     = 1;
                            _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                            _unitOfWorkGameVariant.Complete();
                            TempData["Message"] = "Cevabınız Doğru !!";
                            TempData["JS"]      = "showSuccess();";
                        }
                        else if (fifthWord.FifthWordAnswer == answerUser)
                        {
                            gameVariant.GameScoreCount    = gameVariant.GameScoreCount + fifthWord.FifthWordScore;
                            gameVariant.GameQuestionCount = gameVariant.GameQuestionCount + 1;
                            gameVariant.GameIsCompleted   = false;
                            gameVariant.GameIsOver        = false;
                            gameVariant.GameVariantID     = 1;
                            _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                            _unitOfWorkGameVariant.Complete();
                            TempData["Message"] = "Cevabınız Doğru !!";
                            TempData["JS"]      = "showSuccess();";
                        }
                        else if (sixthWord.SixthWordAnswer == answerUser)
                        {
                            gameVariant.GameScoreCount    = gameVariant.GameScoreCount + sixthWord.SixthWordScore;
                            gameVariant.GameQuestionCount = gameVariant.GameQuestionCount + 1;
                            gameVariant.GameIsCompleted   = false;
                            gameVariant.GameIsOver        = false;
                            gameVariant.GameVariantID     = 1;
                            _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                            _unitOfWorkGameVariant.Complete();
                            TempData["Message"] = "Cevabınız Doğru !!";
                            TempData["JS"]      = "showSuccess();";
                        }
                        else if (sevenWord.SevenWordAnswer == answerUser)
                        {
                            gameVariant.GameScoreCount    = gameVariant.GameScoreCount + sevenWord.SevenWordScore;
                            gameVariant.GameQuestionCount = gameVariant.GameQuestionCount + 1;
                            gameVariant.GameIsCompleted   = false;
                            gameVariant.GameIsOver        = false;
                            gameVariant.GameVariantID     = 1;
                            _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                            _unitOfWorkGameVariant.Complete();
                            TempData["Message"] = "Cevabınız Doğru !!";
                            TempData["JS"]      = "showSuccess();";
                        }
                        else if (eightWord.EightWordAnswer == answerUser)
                        {
                            gameVariant.GameScoreCount    = gameVariant.GameScoreCount + eightWord.EightWordScore;
                            gameVariant.GameQuestionCount = gameVariant.GameQuestionCount + 1;
                            gameVariant.GameIsCompleted   = false;
                            gameVariant.GameIsOver        = false;
                            gameVariant.GameVariantID     = 1;
                            _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                            _unitOfWorkGameVariant.Complete();
                            TempData["Message"] = "Cevabınız Doğru !!";
                            TempData["JS"]      = "showSuccess();";
                        }
                        else if (nineWord.NineWordAnswer == answerUser)
                        {
                            gameVariant.GameScoreCount    = gameVariant.GameScoreCount + nineWord.NineWordScore;
                            gameVariant.GameQuestionCount = gameVariant.GameQuestionCount + 1;
                            gameVariant.GameIsCompleted   = false;
                            gameVariant.GameIsOver        = false;
                            gameVariant.GameVariantID     = 1;
                            _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                            _unitOfWorkGameVariant.Complete();
                            TempData["Message"] = "Cevabınız Doğru !!";
                            TempData["JS"]      = "showSuccess();";
                        }
                        else if (tenWord.TenWordAnswer == answerUser)
                        {
                            gameVariant.GameScoreCount    = gameVariant.GameScoreCount + tenWord.TenWordScore;
                            gameVariant.GameQuestionCount = gameVariant.GameQuestionCount + 1;
                            gameVariant.GameIsCompleted   = true;
                            gameVariant.GameIsOver        = false;
                            gameVariant.GameVariantID     = 1;
                            _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                            _unitOfWorkGameVariant.Complete();
                            if (gameVariant.GameQuestionCount == 14)
                            {
                                scoreTable.UserID    = 1;
                                scoreTable.ScoreData = gameVariant.GameScoreCount;
                                _unitOfWorkScoreTable.RepositoryScoreTable.Create(scoreTable);
                                _unitOfWorkScoreTable.Complete();
                                TempData["Message"] = "Tebrikler !! Oyunu " + scoreTable.ScoreData + " puan ile bitirdiniz!!";
                                TempData["JS"]      = "showSuccess();";
                                var currentUser = _unitOfWorkUser.RepositoryUser.GetByIDForUpdate(getCurrentUser());
                                foreach (var userUpdate in currentUser)
                                {
                                    userUpdate.UserLastScore = (gameVariant.GameScoreCount).ToString();
                                    userUpdate.CreatedDate   = DateTime.Now;
                                    userUpdate.ModifiedDate  = DateTime.Now;
                                    _unitOfWorkUser.RepositoryUser.Update(userUpdate);
                                    int request = HttpContext.Response.StatusCode;
                                    if (request == 200)
                                    {
                                        _unitOfWorkUser.Complete();
                                    }
                                }
                                gameVariant.GameIsCompleted   = false;
                                gameVariant.GameIsOver        = true;
                                gameVariant.GameQuestionCount = 0;
                                gameVariant.GameScoreCount    = 0;
                                gameVariant.GameVariantID     = 1;
                                _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                                int secondRequest = HttpContext.Response.StatusCode;
                                if (secondRequest == 200)
                                {
                                    _unitOfWorkGameVariant.Complete();
                                }
                            }
                            else
                            {
                                TempData["Message"] = "Cevabınız Doğru !!";
                                TempData["JS"]      = "showSuccess();";
                                return(RedirectToAction("GameArena"));
                            }
                        }
                        else
                        {
                            gameVariant.GameScoreCount    = gameVariant.GameScoreCount - questionCount;
                            gameVariant.GameQuestionCount = gameVariant.GameQuestionCount + 0;
                            gameVariant.GameIsCompleted   = false;
                            gameVariant.GameIsOver        = false;
                            gameVariant.GameVariantID     = 1;
                            _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                            _unitOfWorkGameVariant.Complete();
                            TempData["Message"] = "Cevabınız Yanlış !!";
                            TempData["JS"]      = "showError();";
                            return(RedirectToAction("GameArena"));
                        }
                    }
                    else
                    {
                        var currentUser = _unitOfWorkUser.RepositoryUser.GetByIDForUpdate(getCurrentUser());
                        gameVariant.GameIsCompleted   = true;
                        gameVariant.GameIsOver        = true;
                        gameVariant.GameQuestionCount = 0;
                        gameVariant.GameScoreCount    = 0;
                        gameVariant.GameVariantID     = 1;
                        _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                        int secondRequest = HttpContext.Response.StatusCode;
                        if (secondRequest == 200)
                        {
                            _unitOfWorkGameVariant.Complete();
                        }
                        foreach (var x in currentUser)
                        {
                            TempData["Message"] = "Tebrikler !! Oyunu " + x.UserLastScore + " puan ile bitirdiniz!!";
                            TempData["JS"]      = "showSuccess();";
                            return(RedirectToAction("GameArena"));
                        }
                    }
                }
                else
                {
                    gameVariant.GameScoreCount    = 0;
                    gameVariant.GameQuestionCount = 0;
                    gameVariant.GameIsCompleted   = false;
                    gameVariant.GameIsOver        = false;
                    gameVariant.GameVariantID     = 1;
                    _unitOfWorkGameVariant.RepositoryGameVariant.Update(gameVariant);
                    int request = HttpContext.Response.StatusCode;
                    if (request == 200)
                    {
                        TempData["Message"] = "Önceki oyunu başarıyla tamamladınız. Skorunuz:" + lastScore + " Yeni oyuna başlayabilirsiniz.";
                        TempData["JS"]      = "showSuccess();";
                        _unitOfWorkGameVariant.Complete();
                        return(RedirectToAction("GameArena"));
                    }
                    else
                    {
                        TempData["Message"] = "Bir sorun oluştu,tekrar deneyiniz";
                        TempData["JS"]      = "showError();";
                        return(RedirectToAction("GameArena"));
                    }
                }
            }
            return(RedirectToAction("GameArena"));
        }