public ActionResult Index(GoalViewModel model, string saveButton, string status, string goalName, string goalQuestion) { var userId = User.Identity.GetUserId(); var user = _context.Users.FirstOrDefault(x => x.Id == userId); string newGoal = ""; if (saveButton == "newGoal") { if (_context.FirstGoals.Where(x => x.UserProfileId == userId).ToList().Count() == 0) { newGoal = "firstGoal"; } if (_context.FirstGoals.Where(x => x.UserProfileId == userId).ToList().Count() != 0 && _context.SecondGoals.Where(x => x.UserProfileId == userId).ToList().Count() == 0) { newGoal = "secondGoal"; } if (_context.SecondGoals.Where(x => x.UserProfileId == userId).ToList().Count() != 0 && _context.ThirdGoals.Where(x => x.UserProfileId == userId).ToList().Count() == 0) { newGoal = "thirdGoal"; } if (_context.ThirdGoals.Where(x => x.UserProfileId == userId).ToList().Count() != 0 && _context.FourthGoals.Where(x => x.UserProfileId == userId).ToList().Count() == 0) { newGoal = "fourthGoal"; } if (_context.FourthGoals.Where(x => x.UserProfileId == userId).ToList().Count() != 0 && _context.FifthGoals.Where(x => x.UserProfileId == userId).ToList().Count() == 0) { newGoal = "fifthGoal"; } if (_context.FifthGoals.Where(x => x.UserProfileId == userId).ToList().Count() != 0 && _context.SixthGoals.Where(x => x.UserProfileId == userId).ToList().Count() == 0) { newGoal = "sixthGoal"; } if (_context.SixthGoals.Where(x => x.UserProfileId == userId).ToList().Count() != 0 && _context.SeventhGoals.Where(x => x.UserProfileId == userId).ToList().Count() == 0) { newGoal = "seventhGoal"; } if (_context.SeventhGoals.Where(x => x.UserProfileId == userId).ToList().Count() != 0 && _context.EighthGoals.Where(x => x.UserProfileId == userId).ToList().Count() == 0) { newGoal = "eightGoal"; } if (newGoal == "firstGoal") { for (int i = 1; i < 8; i++) { var firstGoal = new FirstGoal { GoalId = i, GoalName = goalName, GoalQuestion = goalQuestion, UserProfileId = userId }; _context.FirstGoals.Add(firstGoal); _context.SaveChanges(); } } if (newGoal == "secondGoal") { for (int i = 1; i < 8; i++) { var secondGoal = new SecondGoal { GoalId = i, GoalName = goalName, GoalQuestion = goalQuestion, UserProfileId = userId }; _context.SecondGoals.Add(secondGoal); _context.SaveChanges(); } } if (newGoal == "thirdGoal") { for (int i = 1; i < 8; i++) { var thirdGoal = new ThirdGoal { GoalId = i, GoalName = goalName, GoalQuestion = goalQuestion, UserProfileId = userId }; _context.ThirdGoals.Add(thirdGoal); _context.SaveChanges(); } } if (newGoal == "fourthGoal") { for (int i = 1; i < 8; i++) { var fourthGoal = new FourthGoal { GoalId = i, GoalName = goalName, GoalQuestion = goalQuestion, UserProfileId = userId }; _context.FourthGoals.Add(fourthGoal); _context.SaveChanges(); } } if (newGoal == "fifthGoal") { for (int i = 1; i < 8; i++) { var fifthGoal = new FifthGoal { GoalId = i, GoalName = goalName, GoalQuestion = goalQuestion, UserProfileId = userId }; _context.FifthGoals.Add(fifthGoal); _context.SaveChanges(); } } if (newGoal == "sixthGoal") { for (int i = 1; i < 8; i++) { var sixthGoal = new SixthGoal { GoalId = i, GoalName = goalName, GoalQuestion = goalQuestion, UserProfileId = userId }; _context.SixthGoals.Add(sixthGoal); _context.SaveChanges(); } } if (newGoal == "seventhGoal") { for (int i = 1; i < 8; i++) { var seventhGoal = new SeventhGoal { GoalId = i, GoalName = goalName, GoalQuestion = goalQuestion, UserProfileId = userId }; _context.SeventhGoals.Add(seventhGoal); _context.SaveChanges(); } } if (newGoal == "eightGoal") { for (int i = 1; i < 8; i++) { var eightGoal = new EightGoal { GoalId = i, GoalName = goalName, GoalQuestion = goalQuestion, UserProfileId = userId }; _context.EighthGoals.Add(eightGoal); _context.SaveChanges(); } } model.FirstGoals = _context.FirstGoals.Where(x => x.UserProfileId == userId).ToList(); model.SecondGoals = _context.SecondGoals.Where(x => x.UserProfileId == userId).ToList(); model.ThirdGoals = _context.ThirdGoals.Where(x => x.UserProfileId == userId).ToList(); model.FourthGoals = _context.FourthGoals.Where(x => x.UserProfileId == userId).ToList(); model.FifthGoals = _context.FifthGoals.Where(x => x.UserProfileId == userId).ToList(); model.SixthGoals = _context.SixthGoals.Where(x => x.UserProfileId == userId).ToList(); model.SeventhGoals = _context.SeventhGoals.Where(x => x.UserProfileId == userId).ToList(); model.EightGoals = _context.EighthGoals.Where(x => x.UserProfileId == userId).ToList(); return(View(model)); } else { dynamic goals = _context.FirstGoals.Where(x => x.UserProfileId == userId).ToArray(); string renderPartial = ""; if (user == null) { return(View()); } switch (saveButton) { case "firstGoal": goals = _context.FirstGoals.Where(x => x.UserProfileId == userId).ToArray(); renderPartial = "_FirstGoalTable"; break; case "secondGoal": goals = _context.SecondGoals.Where(x => x.UserProfileId == userId).ToArray(); renderPartial = "_SecondGoalTable"; break; case "thirdGoal": goals = _context.ThirdGoals.Where(x => x.UserProfileId == userId).ToArray(); renderPartial = "_ThirdGoalTable"; break; case "fourthGoal": goals = _context.FourthGoals.Where(x => x.UserProfileId == userId).ToArray(); renderPartial = "_FourthGoalTable"; break; case "fifthGoal": goals = _context.FifthGoals.Where(x => x.UserProfileId == userId).ToArray(); renderPartial = "_FifthGoalTable"; break; case "sixthGoal": goals = _context.SixthGoals.Where(x => x.UserProfileId == userId).ToArray(); renderPartial = "_SixthGoalTable"; break; case "seventhGoal": goals = _context.SeventhGoals.Where(x => x.UserProfileId == userId).ToArray(); renderPartial = "_SeventhGoalTable"; break; case "eightGoal": goals = _context.EighthGoals.Where(x => x.UserProfileId == userId).ToArray(); renderPartial = "_EightGoalTable"; break; } //Dla tych samych dat if (goals[0].GoalDate == null) { goals[0].GoalDate = DateTime.Today; goals[0].GoalStatus = status; } if (goals[0].GoalDate != null && goals[0].GoalDate == DateTime.Today) { goals[0].GoalDate = DateTime.Today; goals[0].GoalStatus = status; } if (goals[1].GoalDate != null && goals[1].GoalDate == DateTime.Today) { goals[1].GoalDate = DateTime.Today; goals[1].GoalStatus = status; } if (goals[2].GoalDate != null && goals[2].GoalDate == DateTime.Today) { goals[2].GoalDate = DateTime.Today; goals[2].GoalStatus = status; } if (goals[3].GoalDate != null && goals[3].GoalDate == DateTime.Today) { goals[3].GoalDate = DateTime.Today; goals[3].GoalStatus = status; } if (goals[4].GoalDate != null && goals[4].GoalDate == DateTime.Today) { goals[4].GoalDate = DateTime.Today; goals[4].GoalStatus = status; } if (goals[5].GoalDate != null && goals[5].GoalDate == DateTime.Today) { goals[5].GoalDate = DateTime.Today; goals[5].GoalStatus = status; } if (goals[6].GoalDate != null && goals[6].GoalDate == DateTime.Today) { goals[6].GoalDate = DateTime.Today; goals[6].GoalStatus = status; } //Dla wolnych miejsc if (goals[0].GoalDate != null && goals[1].GoalDate == null && goals[0].GoalDate != DateTime.Today) { goals[1].GoalDate = DateTime.Today; goals[1].GoalStatus = status; } else if (goals[0].GoalDate != null && goals[1].GoalDate != null && goals[2].GoalDate == null && goals[1].GoalDate != DateTime.Today) { goals[2].GoalDate = DateTime.Today; goals[2].GoalStatus = status; } else if (goals[0].GoalDate != null && goals[1].GoalDate != null && goals[2].GoalDate != null && goals[3].GoalDate == null && goals[2].GoalDate != DateTime.Today) { goals[3].GoalDate = DateTime.Today; goals[3].GoalStatus = status; } else if (goals[0].GoalDate != null && goals[1].GoalDate != null && goals[2].GoalDate != null && goals[3].GoalDate != null && goals[4].GoalDate == null && goals[3].GoalDate != DateTime.Today) { goals[4].GoalDate = DateTime.Today; goals[4].GoalStatus = status; } if (goals[0].GoalDate != null && goals[1].GoalDate != null && goals[2].GoalDate != null && goals[3].GoalDate != null && goals[4].GoalDate != null && goals[5].GoalDate == null && goals[4].GoalDate != DateTime.Today) { goals[5].GoalDate = DateTime.Today; goals[5].GoalStatus = status; } if (goals[0].GoalDate != null && goals[1].GoalDate != null && goals[2].GoalDate != null && goals[3].GoalDate != null && goals[4].GoalDate != null && goals[5].GoalDate != null && goals[6].GoalDate == null && goals[5].GoalDate != DateTime.Today) { goals[6].GoalDate = DateTime.Today; goals[6].GoalStatus = status; } //Dla zajętych if (goals[6].GoalDate != null && goals[6].GoalDate != DateTime.Today) { goals[0].GoalStatus = goals[1].GoalStatus; goals[0].GoalDate = goals[1].GoalDate; goals[1].GoalStatus = goals[2].GoalStatus; goals[1].GoalDate = goals[2].GoalDate; goals[2].GoalStatus = goals[3].GoalStatus; goals[2].GoalDate = goals[3].GoalDate; goals[3].GoalStatus = goals[4].GoalStatus; goals[3].GoalDate = goals[4].GoalDate; goals[4].GoalStatus = goals[5].GoalStatus; goals[4].GoalDate = goals[5].GoalDate; goals[5].GoalStatus = goals[6].GoalStatus; goals[5].GoalDate = goals[6].GoalDate; goals[6].GoalStatus = status; goals[6].GoalDate = DateTime.Today; } model = new GoalViewModel(goals); _context.SaveChanges(); return(PartialView(renderPartial, model)); } }
// Update is called once per frame void Update() { pointsAmount.text = points.ToString(); spawnWait = Random.Range(spawnLeastWait, spawnMostWait); colorNum = Random.Range(1, 8); if (points > highScore) { highScore = points; } highScoreAmount.text = "HS: " + highScore.ToString(); PlayerPrefs.SetInt("highScore", highScore); PlayerPrefs.Save(); timer += Time.deltaTime; timerValue.text = timer.ToString("f1"); TimeChange(); if (timer >= 50) { changeNum = Random.Range(1, 8); PointsChange(); } if (points == 0) { FirstGoal.SetActive(true); } if (timer >= 5f) { FirstGoal.SetActive(false); } if (timer >= 51) { SecondGoal.SetActive(true); } if (timer >= 55) { SecondGoal.SetActive(false); } if (timer >= 151) { ThirdGoal.SetActive(true); } if (timer >= 155) { ThirdGoal.SetActive(false); } if (timer >= 501) { FourthGoal.SetActive(true); spawnLeastWait = 0f; spawnMostWait = 2f; } if (timer >= 505) { FourthGoal.SetActive(false); } if (timer >= 1001 & points >= 3500) { FifthGoal.SetActive(true); Time.timeScale = 0f; GameIsPaused = true; BlockInput.SetActive(true); } if (points == -15 & timer >= 0f) { Oops.SetActive(true); } if (points == -15 & timer >= 4f) { Oops.SetActive(false); } }